This repository has been archived by the owner on Oct 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.asm
236 lines (151 loc) · 6.18 KB
/
Main.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
;format PE GUI 4.0
include 'win32ax.inc'
; headers
include 'Common.h'
include 'HelloWindow.h'
include 'ChooseWindow.h'
include 'PlayWindow.h'
;------------------------------------------------------------------------------
; data section
.data
include 'Common.d'
include 'HelloWindow.d'
include 'ChooseWindow.d'
include 'PlayWindow.d'
include 'Main.d'
;Globalwc WNDCLASS <10 dup (0)>
Globalwc WNDCLASS 0,0,0,0,0,0,0,0,0,0
msg MSG ?
;end of data section
;------------------------------------------------------------------------------
;code section
.code
startPoint:
;calculating scale
invoke GetSystemMetrics, SM_CXSCREEN
mov [_CurrentScreenSize.width], eax
invoke GetSystemMetrics, SM_CYSCREEN
mov [_CurrentScreenSize.height], eax
stdcall CalculateScale, _ScreenScale, _DefScreenSize, _CurrentScreenSize
;loading cursors
invoke LoadCursor, <invoke GetModuleHandle, NULL>, "IDC_PEN"
mov [PenCursorHandle], eax
invoke LoadCursor, <invoke GetModuleHandle, NULL>, "IDC_HAND"
mov [HandCursorHandle], eax
invoke GetModuleHandle, NULL
mov [Globalwc.hInstance], eax
invoke LoadIcon, 0, IDI_APPLICATION
mov [Globalwc.hIcon], eax
mov eax, [PenCursorHandle]
mov [Globalwc.hCursor], eax
mov [Globalwc.style], CS_GLOBALCLASS
mov [Globalwc.lpfnWndProc], MainWindow.WindowProc
mov [Globalwc.hbrBackground], COLOR_BACKGROUND + 1
mov [Globalwc.lpszClassName], MainWindow.ClassName
;random init
stdcall Random.Init
; registrating all the window classes ---------
invoke RegisterClass, Globalwc
cmp eax, 0
je error
stdcall HelloWindow.Register
cmp eax, 0
je error
stdcall ChooseWindow.Register
cmp eax, 0
je error
stdcall PlayWindow.Register
cmp eax, 0
je error
; end of registration -------------------------
; creating main window ------------------------
invoke CreateWindowEx, 0, MainWindow.ClassName, MainWindow.WindowName,\
WS_VISIBLE xor WS_MINIMIZEBOX xor WS_POPUP,\
[_CurrentScreenSize.left], [_CurrentScreenSize.top], [_CurrentScreenSize.width], [_CurrentScreenSize.height],\
0, 0, <invoke GetModuleHandle, NULL>, 0
cmp eax, 0
je error
mov [MainWindow.Handle], eax
; end of creation -----------------------------
; invoke SetWindowLong, hwnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW
; invoke ShowWindow, hwnd, SW_SHOW
;------ msg loop --------
msg_loop:
invoke GetMessage, msg, 0, 0, 0
cmp eax, 0
je end_loop
invoke TranslateMessage, msg
invoke DispatchMessage, msg
jmp msg_loop
error:
invoke MessageBox, 0, "Error acured!", "Error", MB_ICONERROR + MB_OK
end_loop:
invoke ExitProcess, [msg.wParam]
; end of code section
;------------------------------------------------------------------------------
; Procedures definitions
;------------------------------------------------------------------------------
; main window procedure
proc MainWindow.WindowProc\
uses ebx esi edi,\
hwnd, umsg, wparam, lparam
locals
hbmTemp dd ?
endl
; message case --------------------------
.if [umsg] = WM_COMMAND
mov eax, 0
.elseif [umsg] = _wmSwitchWindows
;wparam - handle of the window to be shown
;lparam - handle of the window to be hidden
; hiding window
.if [lparam] <> 0
invoke AnimateWindow, [lparam], AW_SPEED, AW_CURRENTANIMATION or AW_HIDE
.endif
; showing window
.if [wparam] <> 0
invoke AnimateWindow, [wparam], AW_SPEED, AW_CURRENTANIMATION or AW_ACTIVATE
;invoke RedrawWindow, [wparam], NULL, NULL, RDW_INVALIDATE
.endif
.elseif [umsg] = WM_CREATE
stdcall HelloWindow.Create, [hwnd]
stdcall ChooseWindow.Create, [hwnd]
stdcall PlayWindow.Create, [hwnd]
invoke PostMessage, [hwnd], _wmSwitchWindows, [HelloWindow.Handle], 0
; invoke PostMessage, [hwnd], _wmSwitchWindows, [PlayWindow.Handle], 0
stdcall InitializeWindow, MainWindow
.elseif ([umsg] = WM_PAINT) | ([umsg] = WM_PRINT)
;Preparing for real painting
.if ([umsg] = WM_PAINT)
invoke BeginPaint, [hwnd], MainWindow.PS
mov esi, eax
.else
mov esi, [wparam]
.endif
; Updating info about window size
invoke GetClientRect, [hwnd], MainWindow.RealRect
;Copying everything from BG DC to RealDC
invoke StretchBlt, esi, 0, 0, [MainWindow.RealRect.width], [MainWindow.RealRect.height],\
[MainWindow.BG.hdc], 0, 0, [MainWindow.BG.bm.bmWidth], [MainWindow.BG.bm.bmHeight], SRCCOPY
;ending real painting
.if ([umsg] = WM_PAINT)
invoke EndPaint, [hwnd], MainWindow.PS
.endif
mov eax, 0
.elseif [umsg] = WM_DESTROY
invoke SendMessage, [hwnd], _wmSwitchWindows, 0, [hwnd]
invoke PostQuitMessage, 0
mov eax, 0
.else
invoke DefWindowProc, [hwnd], [umsg], [wparam], [lparam]
.endif
; endcase ------------------------------
ret
endp
;------------------------------------------------------------------------------
include 'Common.c'
include 'HelloWindow.c'
include 'ChooseWindow.c'
include 'PlayWindow.c'
section '.rsrc' data resource from 'data.res' readable
.end startPoint