📄 winclock.asm
字号:
INVOKE SelectObject, hDC, ax
INVOKE CreatePen, PS_SOLID OR PS_INSIDEFRAME, 2, 0
INVOKE SelectObject, hDC, ax
push ax
INVOKE Rectangle, hDC, TextRect.left, TextRect.top,
TextRect.right, TextRect.bottom
INVOKE GetStockObject, HOLLOW_BRUSH
INVOKE SelectObject, hDC, ax
INVOKE DeleteObject, ax
pop ax
INVOKE SelectObject, hDC, ax
INVOKE DeleteObject, ax
.ENDIF
;---- Check for Alarm
xor dx, dx
mov ax, hour
mov cx, 60t
imul cx
add ax, minutes ; ax now holds the time in minutes
.IF (TestAlarm)
.IF (EnableAlarm && (ax == AlarmTime))
mov TestAlarm, FALSE
INVOKE SetFocus, hWnd
INVOKE InvertRect, hDC, ADDR TextRect
INVOKE MessageBeep, MB_ICONASTERISK
INVOKE InvertRect, hDC, ADDR TextRect
INVOKE MessageBox, hWnd, ADDR szAlarmMsg,
ADDR szAppName,MB_ICONEXCLAMATION OR MB_OK
.ENDIF
.ELSE ; of TestAlarm ; if TestAlarm=0, means
.IF (ax != AlarmTime) ; we sounded the alarm.
mov TestAlarm, TRUE ; but, if time
.ENDIF ; changed, we should to
.ENDIF ; check again (allows
; alarm every 24 hours)
ret
PaintTime ENDP
;----------------------------------------------------------------------------;
; WndProc ;
;----------------------------------------------------------------------------;
; ;
; The routine called on by Windows through WinMain's dispatch message loop. ;
; Different actions according to messages ;
; Create: Set the timer with AlarmSetup ;
; Timer: Repaint the window (Invalidate it) ;
; Paint: BeginPaint, call on the correct paint routine ;
; SetFocus: Redraw the Window Frame ;
; Resize: Resize the fonts and scroll bar, redraw the window ;
; Destroy: Close window and exit program ;
; LeftDouble or RightClick: If setting alarm, set it; otherwise pop up ;
; menu. Mouse position is in the high & low words of lParam, in ;
; client coords. Change them to Screen coords and show menu. ;
; LeftClick: Move window by tricking Windows into thinking that we've ;
; hit the Caption Bar of the window. It doesn't matter that ;
; there isn't a caption bar. ;
; Commands: Date: Toggle the switch, check the menu, resize and paint ;
; EnableAlarm: Sound the alarm or not ;
; Set: Start setting the alarm ;
; About: Display a Message Box. A dialog box is up to you ;
; AlwaysOnTop: Sets the Window Position to be Topmost or not ;
; Minimize: make Windows think we hit the 'Minimize' command ;
; from the system menu. ;
; Exit: Exit program. ;
; ScrollBar: Page Moves indicate hours, lines minutes. If thumb, the ;
; lParam low word holds the position. Check that we don't ;
; go out of range, set the scroll position, and repaint. ;
; Otherwise, call the default window procedure. ;
; ;
; Notice that most of the repaints do not erase the backgrnd, only ;
; RedrawWindow of Resize and SetFocus. This speeds up exec, ;
; and drawtext will erase over everything automatically. ;
; ;
;----------------------------------------------------------------------------;
WndProc PROC FAR PASCAL, hWnd:HWND, iMessage:WORD, wParam:SWORD,
lParam:SDWORD
; Windows gives us: the handle of the Window, the Message ID,
; and two parameters for the message
LOCAL hDC:HDC, ps:PAINTSTRUCT, point:POINT
; locals: a handle to a device context, a paint structure,
; a point structure
.IF (iMessage == WM_CREATE)
INVOKE SetupTimer, hWnd, TIMER_SECS
INVOKE Resize, hWnd
INVOKE InvalidateRect, hWnd, NULL, FALSE
.ELSEIF (iMessage == WM_TIMER)
INVOKE InvalidateRect, hWnd, NULL, FALSE
.ELSEIF (iMessage == WM_PAINT)
INVOKE BeginPaint, hWnd, ADDR ps
mov hDC, ax
.IF SetAlarm
INVOKE PaintAlarm, hWnd, hDC
.ELSE
INVOKE PaintTime, hWnd, hDC
.ENDIF
INVOKE EndPaint, hWnd, ADDR ps
.ELSEIF (iMessage == WM_SETFOCUS)
INVOKE RedrawWindow, hWnd, NULL, NULL,
RDW_FRAME OR RDW_UPDATENOW
.ELSEIF (iMessage == WM_SIZE)
.IF ((wParam != SIZE_MINIMIZED) && Iconized)
mov Iconized, FALSE
INVOKE KillTimer, hWnd, 1
INVOKE SetupTimer, hWnd, TIMER_SECS
.ENDIF
INVOKE Resize, hWnd
INVOKE RedrawWindow, hWnd, NULL, NULL,
RDW_ERASE OR RDW_INVALIDATE
.ELSEIF (iMessage == WM_DESTROY)
INVOKE KillTimer, hWnd, 1
INVOKE PostQuitMessage, 0
.ELSEIF (iMessage==WM_LBUTTONDBLCLK)||(iMessage==WM_RBUTTONUP)
.IF SetAlarm
xor SetAlarm, TRUE
INVOKE AlarmSetup, hWnd
.ELSE
mov di, word ptr lParam
mov point.x, di
mov di, word ptr (lParam+2)
mov point.y, di
INVOKE ClientToScreen, hWnd, ADDR point
INVOKE TrackPopupMenu, hMenu, TPM_LEFTALIGN,
point.x, point.y, 0, hWnd, NULL
INVOKE InvalidateRect, hWnd, NULL, TRUE
.ENDIF
.ELSEIF (iMessage == WM_LBUTTONDOWN)
INVOKE DefWindowProc, hWnd, WM_NCLBUTTONDOWN,
HTCAPTION, lParam
.ELSEIF (iMessage == WM_COMMAND)
.IF (wParam == IDM_DATE)
xor EnableDate, MF_CHECKED
INVOKE CheckMenuItem,hMenu,wParam,EnableDate
INVOKE Resize, hWnd
INVOKE InvalidateRect, hWnd, NULL, FALSE
.ELSEIF (wParam == IDM_ALARM)
xor EnableAlarm, MF_CHECKED
mov TestAlarm, TRUE
INVOKE CheckMenuItem,hMenu,wParam,EnableAlarm
.ELSEIF (wParam == IDM_SET)
mov SetAlarm, TRUE
INVOKE AlarmSetup, hWnd
.ELSEIF (wParam == IDM_ABOUT)
INVOKE MessageBox, hWnd, ADDR szAboutText,
ADDR szAppName, MB_ICONASTERISK OR MB_OK
.ELSEIF (wParam == IDM_ONTOP)
xor AlwaysOnTop, MF_CHECKED
INVOKE CheckMenuItem,hMenu,wParam,AlwaysOnTop
.IF AlwaysOnTop
mov ax, HWND_TOPMOST
.ELSE
mov ax, HWND_NOTOPMOST
.ENDIF
INVOKE SetWindowPos, hWnd, ax,
0, 0, 0, 0, SWP_NOMOVE OR SWP_NOSIZE
.ELSEIF (wParam == IDM_EXIT)
INVOKE KillTimer, hWnd, 1
INVOKE PostQuitMessage, 0
.ELSEIF (wParam == IDM_MINIMIZE)
mov Iconized, TRUE
INVOKE KillTimer, hWnd, 1
INVOKE SetupTimer, hWnd, TIMER_MINS
INVOKE DefWindowProc, hWnd, WM_SYSCOMMAND,
SC_ICON, NULL
.ENDIF
.ELSEIF (iMessage == WM_HSCROLL)
.IF (wParam == SB_PAGEDOWN)
add AlarmTime, 10t
.ELSEIF (wParam == SB_LINEDOWN)
inc AlarmTime
.ELSEIF (wParam == SB_PAGEUP)
sub AlarmTime, 10t
.ELSEIF (wParam == SB_LINEUP)
dec AlarmTime
.ELSEIF (wParam == SB_TOP)
mov AlarmTime, MAXTIME
.ELSEIF (wParam == SB_BOTTOM)
mov AlarmTime, 0t
.ELSEIF (wParam == SB_THUMBPOSITION)
mov ax, word ptr lParam
mov AlarmTime, ax
.ELSEIF (wParam == SB_THUMBTRACK)
mov ax, word ptr lParam
mov AlarmTime, ax
.ELSEIF (wParam == SB_LINEDOWN)
mov ax, word ptr lParam
mov AlarmTime, ax
.ENDIF
.IF (AlarmTime < 0)
mov AlarmTime, 0t
.ELSEIF (AlarmTime > MAXTIME)
mov AlarmTime, MAXTIME
.ENDIF
INVOKE SetScrollPos, hWndScrol, SB_CTL,
AlarmTime, TRUE
INVOKE InvalidateRect, hWnd,
ADDR TextRect, FALSE
.ELSE
INVOKE DefWindowProc, hWnd, iMessage,
wParam,lParam
jmp doRet
.ENDIF
mov ax, 0
cwd
doRet:
ret
WndProc ENDP
END __astart ; so that the code of the application will
; start with the Windows start-up code
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -