Rafpast

Timer

Jul 12th, 2023
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 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 timer.inc ; local includes for this file
  8.  
  9. .code
  10.  
  11. start:
  12.  
  13. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  14.  
  15. ; ------------------
  16. ; set global values
  17. ; ------------------
  18. mov hInstance, FUNC(GetModuleHandle, NULL)
  19. mov CommandLine, FUNC(GetCommandLine)
  20. mov hIcon, FUNC(LoadIcon,NULL,IDI_ASTERISK)
  21. mov hCursor, FUNC(LoadCursor,NULL,IDC_ARROW)
  22. mov sWid, FUNC(GetSystemMetrics,SM_CXSCREEN)
  23. mov sHgt, FUNC(GetSystemMetrics,SM_CYSCREEN)
  24.  
  25. call Main
  26.  
  27. invoke ExitProcess,eax
  28.  
  29. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  30.  
  31. Main proc
  32.  
  33. LOCAL Wwd:DWORD,Wht:DWORD,Wtx:DWORD,Wty:DWORD
  34.  
  35. STRING szClassName,"Timer_Demo_Class"
  36.  
  37. ; --------------------------------------------
  38. ; register class name for CreateWindowEx call
  39. ; --------------------------------------------
  40. invoke RegisterWinClass,ADDR WndProc,ADDR szClassName,
  41. hIcon,hCursor,COLOR_BTNFACE+1
  42.  
  43. mov Wwd, 300
  44. mov Wht, 250
  45. invoke TopXY,Wwd,sWid
  46. mov Wtx, eax
  47. invoke TopXY,Wht,sHgt
  48. mov Wty, eax
  49.  
  50. invoke CreateWindowEx,WS_EX_LEFT or WS_EX_ACCEPTFILES,
  51. ADDR szClassName,
  52. chr$("Display Local Time"),
  53. WS_OVERLAPPEDWINDOW,
  54. Wtx,Wty,Wwd,Wht,
  55. NULL,NULL,
  56. hInstance,NULL
  57. mov hWnd,eax
  58.  
  59. ; ---------------------------
  60. ; macros for unchanging code
  61. ; ---------------------------
  62. DisplayWindow hWnd,SW_SHOWNORMAL
  63.  
  64. call MsgLoop
  65. ret
  66.  
  67. Main endp
  68.  
  69. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  70.  
  71. RegisterWinClass proc lpWndProc:DWORD, lpClassName:DWORD,
  72. Icon:DWORD, Cursor:DWORD, bColor:DWORD
  73.  
  74. LOCAL wc:WNDCLASSEX
  75.  
  76. mov wc.cbSize, sizeof WNDCLASSEX
  77. mov wc.style, CS_BYTEALIGNCLIENT or \
  78. CS_BYTEALIGNWINDOW
  79. m2m wc.lpfnWndProc, lpWndProc
  80. mov wc.cbClsExtra, NULL
  81. mov wc.cbWndExtra, NULL
  82. m2m wc.hInstance, hInstance
  83. m2m wc.hbrBackground, bColor
  84. mov wc.lpszMenuName, NULL
  85. m2m wc.lpszClassName, lpClassName
  86. m2m wc.hIcon, Icon
  87. m2m wc.hCursor, Cursor
  88. m2m wc.hIconSm, Icon
  89.  
  90. invoke RegisterClassEx, ADDR wc
  91.  
  92. ret
  93.  
  94. RegisterWinClass endp
  95.  
  96. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  97.  
  98. MsgLoop proc
  99.  
  100. LOCAL msg:MSG
  101.  
  102. jmp InLoop ; not needed but for "purists"
  103.  
  104. StartLoop:
  105. invoke TranslateMessage, ADDR msg
  106. invoke DispatchMessage, ADDR msg
  107. InLoop:
  108. invoke GetMessage,ADDR msg,NULL,0,0
  109. test eax, eax
  110. jnz StartLoop
  111.  
  112. mov eax, msg.wParam
  113. ret
  114.  
  115. MsgLoop endp
  116.  
  117. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  118.  
  119. WndProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
  120.  
  121. LOCAL buffer1[260]:BYTE
  122.  
  123. Switch uMsg
  124. Case WM_CREATE
  125. ; ---------------------------------------------------
  126. ; set the timer with a 1000 MS (1 second) update rate
  127. ; ---------------------------------------------------
  128. invoke SetTimer,hWin,222,1000,NULL
  129.  
  130. Case WM_TIMER
  131. ; -------------------------------
  132. ; receive the timer message every
  133. ; second, retrieve the local time
  134. ; and display it on the title bar
  135. ; -------------------------------
  136. invoke GetTimeFormat,LOCALE_USER_DEFAULT,NULL,NULL,NULL,ADDR buffer1,260
  137. fn SetWindowText,hWnd,ADDR buffer1
  138. return 0
  139.  
  140. Case WM_CLOSE
  141. ; -------------------------
  142. ; destroy the timer on exit
  143. ; -------------------------
  144. invoke KillTimer,hWin,222
  145.  
  146. Case WM_DESTROY
  147. invoke PostQuitMessage,NULL
  148. return 0
  149.  
  150. Endsw
  151.  
  152. invoke DefWindowProc,hWin,uMsg,wParam,lParam
  153.  
  154. ret
  155.  
  156. WndProc endp
  157.  
  158. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  159.  
  160. TopXY proc wDim:DWORD, sDim:DWORD
  161.  
  162. shr sDim, 1 ; divide screen dimension by 2
  163. shr wDim, 1 ; divide window dimension by 2
  164. mov eax, wDim ; copy window dimension into eax
  165. sub sDim, eax ; sub half win dimension from half screen dimension
  166.  
  167. return sDim
  168.  
  169. TopXY endp
  170.  
  171. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  172.  
  173. end start
  174.  
Advertisement
Add Comment
Please, Sign In to add comment