Rafpast

myProgram

Jul 12th, 2023
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.51 KB | None | 0 0
  1. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  2.  
  3. .486 ; create 32 bit code
  4. .model flat, stdcall ; 32 bit memory model
  5. option casemap :none ; case sensitive
  6.  
  7. include \masm32\include\dialogs.inc
  8. include simple.inc
  9. include timer.inc
  10.  
  11. dlgproc PROTO :DWORD,:DWORD,:DWORD,:DWORD
  12.  
  13. .code
  14.  
  15. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  16.  
  17. start:
  18.  
  19. ; ------------------
  20. ; set global values
  21. ; ------------------
  22. mov hInstance, FUNC(GetModuleHandle, NULL)
  23. mov CommandLine, FUNC(GetCommandLine)
  24. mov hIcon, FUNC(LoadIcon,NULL,IDI_ASTERISK)
  25. mov hCursor, FUNC(LoadCursor,NULL,IDC_ARROW)
  26. mov sWid, FUNC(GetSystemMetrics,SM_CXSCREEN)
  27. mov sHgt, FUNC(GetSystemMetrics,SM_CYSCREEN)
  28.  
  29. call Main
  30.  
  31. invoke ExitProcess,eax
  32.  
  33. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  34.  
  35. Main proc
  36.  
  37. LOCAL Wwd:DWORD,Wht:DWORD,Wtx:DWORD,Wty:DWORD
  38.  
  39. STRING szClassName,"Timer_Demo_Class"
  40.  
  41. Dialog "Simple Dialog","MS Sans Serif",10, \ ; caption,font,pointsize
  42. WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \ ; style
  43. 2, \ ; control count
  44. 50,50,150,80, \ ; x y co-ordinates
  45. 1024 ; memory buffer size
  46.  
  47. DlgButton "&OK",WS_TABSTOP,48,40,50,15,IDCANCEL
  48. DlgStatic "Simple Dialog Written In MASM32",SS_CENTER,2,20,140,9,100
  49.  
  50. CallModalDialog hInstance,0,dlgproc,NULL
  51.  
  52.  
  53. ; --------------------------------------------
  54. ; register class name for CreateWindowEx call
  55. ; --------------------------------------------
  56. invoke RegisterWinClass,ADDR WndProc,ADDR szClassName,
  57. hIcon,hCursor,COLOR_BTNFACE+1
  58.  
  59. mov Wwd, 300
  60. mov Wht, 250
  61. invoke TopXY,Wwd,sWid
  62. mov Wtx, eax
  63. invoke TopXY,Wht,sHgt
  64. mov Wty, eax
  65.  
  66. invoke CreateWindowEx,WS_EX_LEFT or WS_EX_ACCEPTFILES,
  67. ADDR szClassName,
  68. chr$("Display Local Time"),
  69. WS_OVERLAPPEDWINDOW,
  70. Wtx,Wty,Wwd,Wht,
  71. NULL,NULL,
  72. hInstance,NULL
  73. mov hWnd,eax
  74.  
  75. ; ---------------------------
  76. ; macros for unchanging code
  77. ; ---------------------------
  78. DisplayWindow hWnd,SW_SHOWNORMAL
  79.  
  80. call MsgLoop
  81. ret
  82.  
  83.  
  84. Main endp
  85.  
  86. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  87.  
  88.  
  89. dlgproc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
  90.  
  91. .if uMsg == WM_INITDIALOG
  92. invoke SendMessage,hWin,WM_SETICON,1,FUNC(LoadIcon,NULL,IDI_ASTERISK)
  93.  
  94. .elseif uMsg == WM_COMMAND
  95. .if wParam == IDCANCEL
  96. jmp quit_dialog
  97. .endif
  98.  
  99. .elseif uMsg == WM_CLOSE
  100. quit_dialog:
  101. invoke EndDialog,hWin,0
  102.  
  103. .endif
  104.  
  105. xor eax, eax
  106. ret
  107.  
  108. dlgproc endp
  109.  
  110. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  111.  
  112.  
  113. RegisterWinClass proc lpWndProc:DWORD, lpClassName:DWORD,
  114. Icon:DWORD, Cursor:DWORD, bColor:DWORD
  115.  
  116. LOCAL wc:WNDCLASSEX
  117.  
  118. mov wc.cbSize, sizeof WNDCLASSEX
  119. mov wc.style, CS_BYTEALIGNCLIENT or \
  120. CS_BYTEALIGNWINDOW
  121. m2m wc.lpfnWndProc, lpWndProc
  122. mov wc.cbClsExtra, NULL
  123. mov wc.cbWndExtra, NULL
  124. m2m wc.hInstance, hInstance
  125. m2m wc.hbrBackground, bColor
  126. mov wc.lpszMenuName, NULL
  127. m2m wc.lpszClassName, lpClassName
  128. m2m wc.hIcon, Icon
  129. m2m wc.hCursor, Cursor
  130. m2m wc.hIconSm, Icon
  131.  
  132. invoke RegisterClassEx, ADDR wc
  133.  
  134. ret
  135.  
  136. RegisterWinClass endp
  137.  
  138. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  139.  
  140. MsgLoop proc
  141.  
  142. LOCAL msg:MSG
  143.  
  144. jmp InLoop ; not needed but for "purists"
  145.  
  146. StartLoop:
  147. invoke TranslateMessage, ADDR msg
  148. invoke DispatchMessage, ADDR msg
  149. InLoop:
  150. invoke GetMessage,ADDR msg,NULL,0,0
  151. test eax, eax
  152. jnz StartLoop
  153.  
  154. mov eax, msg.wParam
  155. ret
  156.  
  157. MsgLoop endp
  158.  
  159. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  160.  
  161.  
  162. WndProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
  163.  
  164. LOCAL buffer1[260]:BYTE
  165.  
  166. Switch uMsg
  167. Case WM_CREATE
  168. ; ---------------------------------------------------
  169. ; set the timer with a 1000 MS (1 second) update rate
  170. ; ---------------------------------------------------
  171. invoke SetTimer,hWin,222,1000,NULL
  172.  
  173. Case WM_TIMER
  174. ; -------------------------------
  175. ; receive the timer message every
  176. ; second, retrieve the local time
  177. ; and display it on the title bar
  178. ; -------------------------------
  179. invoke GetTimeFormat,LOCALE_USER_DEFAULT,NULL,NULL,NULL,ADDR buffer1,260
  180. fn SetWindowText,hWnd,ADDR buffer1
  181. return 0
  182.  
  183. Case WM_CLOSE
  184. ; -------------------------
  185. ; destroy the timer on exit
  186. ; -------------------------
  187. invoke KillTimer,hWin,222
  188.  
  189. Case WM_DESTROY
  190. invoke PostQuitMessage,NULL
  191. return 0
  192.  
  193. Endsw
  194.  
  195. invoke DefWindowProc,hWin,uMsg,wParam,lParam
  196.  
  197. ret
  198.  
  199. WndProc endp
  200.  
  201. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  202.  
  203. TopXY proc wDim:DWORD, sDim:DWORD
  204.  
  205. shr sDim, 1 ; divide screen dimension by 2
  206. shr wDim, 1 ; divide window dimension by 2
  207. mov eax, wDim ; copy window dimension into eax
  208. sub sDim, eax ; sub half win dimension from half screen dimension
  209.  
  210. return sDim
  211.  
  212. TopXY endp
  213.  
  214. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  215.  
  216. end start
Advertisement
Add Comment
Please, Sign In to add comment