DRAWWIN.ASM
上传用户:ys_happy
上传日期:2007-01-09
资源大小:20k
文件大小:7k
源码类别:

汇编语言

开发平台:

Asm

  1. .386
  2. .model flat,STDCALL
  3. extrn Dispatch : PROC, hwndFrame : DWORD, hwndClient : DWORD
  4. extrn handlesb : PROC ,scrollkeys : PROC
  5. extrn DisplayWindowBars: PROC, SetBarRanges : PROC
  6. extrn ShiftState : BYTE
  7. extrn OpenFileDialog : PROC, SaveFileDialog : PROC
  8. include win32.asi           ; some 32-bit constants and structures
  9. include win32.ase
  10. include commdlg.asi
  11. include fdid.asi
  12. include fdui.asi
  13. .data
  14. Public numberofdrawwindows
  15. numberofdrawwindows dd ?
  16. childxpos dd ?
  17. childypos dd ?
  18. szMyName db 'Unknown',0
  19. szDrawClassName      db 'LADsoftGPLDraw',0
  20. .code
  21. public RegisterDrawWindow
  22. RegisterDrawWindow PROC hInst : DWORD
  23. LOCAL  wc : WNDCLASS, 
  24. bluebrush : LOGBRUSH, hBrush : dword
  25. ; make us a blue brush
  26. ;
  27. mov [bluebrush.lbStyle],BS_SOLID
  28. mov [bluebrush.lbColor],0FF0000h
  29. mov [bluebrush.lbHatch],0
  30. lea eax,[bluebrush]
  31. call CreateBrushIndirect,eax
  32. mov [hBrush],eax
  33. ;
  34. ; initialize the DrawClass structure
  35. ;
  36.         mov     [wc.clsStyle], CS_HREDRAW + CS_VREDRAW + CS_GLOBALCLASS
  37.         mov     [wc.clsLpfnWndProc], offset DrawProc
  38.         mov     [wc.clsCbClsExtra], 0
  39.         mov     [wc.clsCbWndExtra], 4 ; pointer for window instance data
  40.         mov     eax, [hInst]
  41.         mov     [wc.clsHInstance], eax
  42.         call    LoadIcon,0,IDI_APPLICATION
  43.         mov     [wc.clsHIcon], eax
  44.         call    LoadCursor,0,IDC_ARROW
  45.         mov     [wc.clsHCursor], eax
  46. mov eax,[hBrush]
  47.         mov     [wc.clsHbrBackground], eax
  48.         mov     [dword ptr wc.clsLpszMenuName], 0
  49.         mov     [dword ptr wc.clsLpszClassName], offset szDrawClassName
  50. lea eax,[wc]
  51.         call    RegisterClass,eax
  52. ;
  53. ; delete the blue brush
  54. ;
  55. call DeleteObject,[hBrush]
  56. ret
  57. RegisterDrawWindow ENDP
  58. public CreateDrawWindow
  59. CreateDrawWindow PROC  hInst : dword
  60. LOCAL mc : MDICREATESTRUCT
  61. ; first create the window
  62. inc [numberofdrawwindows]
  63. mov [mc.szClass],offset szDrawClassName
  64. mov [mc.szTitle], offset szMyName
  65. mov eax,[hInst]
  66. mov [mc.hOwner], eax
  67. mov eax,[childxpos]
  68. mov [mc.x],eax
  69. mov eax,[childypos]
  70. mov [mc.y],eax
  71. mov [mc.cxc],0
  72. mov [mc.cyc],0
  73. mov [mc.style],0
  74. mov [mc.lParam],0
  75. lea eax,[mc]
  76. call SendMessage,[hwndClient],WM_MDICREATE,0,eax
  77. ;
  78. ; update next window pos
  79. ;
  80. add [childxpos],20
  81. add [childypos],20
  82. cmp [childxpos],120
  83. jc nopos0
  84. mov [childxpos],0
  85. mov [childypos],0
  86. nopos0:
  87. ret
  88. CreateDrawWindow ENDP
  89. public DrawProc
  90. DrawProc PROC uses ebx edi esi, hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
  91. mov eax,[wmsg]
  92. call Dispatch
  93. dd 10
  94. dd WM_SYSCOMMAND,wmsyscommand
  95. dd WM_COMMAND,wmcommand
  96. dd WM_HSCROLL,wmhscroll
  97. dd WM_VSCROLL,wmvscroll
  98. dd WM_KEYDOWN,wmkeydown
  99. dd WM_KEYUP,wmkeyup
  100. dd WM_CREATE,wmcreate
  101. dd WM_CLOSE, wmclose
  102. dd WM_DESTROY,wmdestroy
  103. dd WM_QUERYENDSESSION,wmqueryend
  104. jnc dp_nodef
  105. call dpdef
  106. dp_nodef:
  107. ret
  108. dpdef  PROC
  109. call DefMDIChildProc,hwnd,wmsg,wparam,lparam
  110. ret
  111. dpdef ENDP
  112. wmcreate PROC
  113. ;
  114. ; Get the name of the file
  115. ; we have to do this first so we don't allocate stuff if
  116. ; we aren't going to have a window
  117. ;
  118. call OpenFileDialog,0,[hwnd]
  119. or eax,eax
  120. jnz opened
  121. mov eax,-1
  122. ret
  123. opened:
  124. push esi
  125. push edi
  126. push ebx
  127. push eax
  128. ;
  129. ; now install the window data
  130. ;
  131. call GetProcessHeap
  132. call HeapAlloc,eax,HEAP_ZERO_MEMORY,size dwinfo
  133. push eax
  134. call SetWindowLong,[hwnd],0,eax
  135. pop ebx
  136. ;
  137. ; init the window data.  The heap alloc we did is nonmoveable, so
  138. ;
  139. mov [ebx + dwinfo.phsb.sbheight],200
  140. mov [ebx + dwinfo.phsb.sbstyle],SB_HORZ
  141. mov [ebx + dwinfo.phsb.sbpaging],10
  142. mov [ebx + dwinfo.pvsb.sbheight],200
  143. mov [ebx + dwinfo.pvsb.sbstyle],SB_VERT
  144. mov [ebx + dwinfo.pvsb.sbpaging],10
  145. ;
  146. ; set the window title and file name strings
  147. ;
  148. pop ecx
  149. push ecx
  150. mov esi,[ecx].oflpstrFileTitle
  151. lea edi,[ebx].dwTitle
  152. cplp:
  153. lodsb
  154. stosb
  155. or al,al
  156. jnz cplp
  157. lea eax,[ebx].dwTitle
  158. call SetWindowText,[hwnd],eax
  159. pop ecx
  160. mov esi,[ecx].oflpstrFile
  161. lea edi,[ebx].dwFileName
  162. cplp2:
  163. lodsb
  164. stosb
  165. or al,al
  166. jnz cplp2
  167. ;
  168. ; now put the scrollbars up and show them
  169. ;
  170. lea eax,[ebx + dwinfo.pvsb]
  171. call SetBarRanges,[hwnd],ebx,eax
  172. call    ShowScrollBar,[hwnd],SB_BOTH,1
  173. pop ebx
  174. pop edi
  175. pop esi
  176. sub eax,eax
  177. ret
  178. wmcreate ENDP
  179. wmdestroy PROC
  180. ;
  181. ; now get rid of any window memory.
  182. ;
  183. dec [numberofdrawwindows]
  184. call GetWindowLong,[hwnd],0
  185. push eax
  186. call GetProcessHeap
  187. pop ebx
  188. call HeapFree,eax,0,ebx
  189. sub eax,eax
  190. ret
  191. wmdestroy ENDP
  192. wmkeydown PROC
  193. call GetWindowLong,[hwnd],0
  194. lea eax,[eax + dwinfo.phsb]
  195. call scrollkeys,[hwnd],[wparam],eax
  196. cmp [wparam],VK_SHIFT
  197. jnz wmkdx
  198. mov [ShiftState],1
  199. sub eax,eax
  200. ret
  201. wmkdx:
  202. call dpdef
  203. sub eax,eax
  204. ret
  205. wmkeydown ENDP
  206. wmkeyup PROC
  207. cmp [wparam],VK_SHIFT
  208. jnz wmkux
  209. mov [ShiftState],0
  210. call dpdef
  211. sub eax,eax
  212. ret
  213. wmkux:
  214. sub eax,eax
  215. ret
  216. wmkeyup ENDP
  217. wmhscroll PROC
  218. ; update scroll pos
  219. call GetWindowLong,[hwnd],0
  220. mov ebx,[wparam]
  221. mov ecx,ebx
  222. movzx ebx,bx
  223. shr ecx,16
  224. lea eax,[eax + dwinfo.phsb]
  225. call handlesb,[hwnd],eax,ebx,ecx
  226. sub eax,eax
  227. ret
  228. wmhscroll ENDP
  229. wmvscroll PROC
  230. ; update scroll pos
  231. call GetWindowLong,[hwnd],0
  232. mov ebx,[wparam]
  233. mov ecx,ebx
  234. movzx ebx,bx
  235. shr ecx,16
  236. lea eax,[eax + dwinfo.pvsb]
  237. call handlesb,[hwnd],eax,ebx,ecx
  238. sub eax,eax
  239. ret
  240. wmvscroll ENDP
  241. wmclose PROC
  242. call SendMessage,[hwnd],WM_QUERYENDSESSION,0,0
  243. or eax,eax
  244. jz wmcclosex
  245. call SendMessage,[hwnd],WM_COMMAND,IDM_SAVE,0
  246. call dpdef
  247. sub eax,eax
  248. ret
  249. wmcclosex:
  250. mov eax,-1
  251. ret
  252. wmclose ENDP
  253. wmsyscommand PROC
  254. mov eax,[wparam]
  255. movzx eax,ax ; get rid of accel flag
  256. call Dispatch
  257. dd 1
  258. dd SC_CLOSE,dpcclose
  259. call DefMDIChildProc,hwnd,wmsg,wparam,lparam
  260. sub eax,eax
  261. ret
  262. wmsyscommand ENDP
  263. wmcommand PROC
  264. mov eax,[wparam]
  265. call Dispatch
  266. dd 3
  267. dd IDM_SAVE,wmcsave
  268. dd IDM_SAVEAS,wmcsaveas
  269. dd IDM_CLOSE,wmcclose
  270. ret
  271. wmcclose PROC
  272. call SendMessage,[hwnd],WM_CLOSE,0,0
  273. ret
  274. wmcclose ENDP
  275. wmcsaveas PROC
  276. call GetWindowLong,[hwnd],0
  277. mov ebx,eax
  278. lea eax,[eax].dwTitle
  279. call SaveFileDialog,eax,[hwnd]
  280. or eax,eax
  281. jnz accepted
  282. sub eax,eax
  283. ret
  284. accepted:
  285. mov ecx,eax
  286. ;
  287. ; set the window title and file name strings
  288. ;
  289. push ecx
  290. mov esi,[ecx].oflpstrFileTitle
  291. lea edi,[ebx].dwTitle
  292. cplp3:
  293. lodsb
  294. stosb
  295. or al,al
  296. jnz cplp3
  297. lea eax,[ebx].dwTitle
  298. call SetWindowText,[hwnd],eax
  299. pop ecx
  300. mov esi,[ecx].oflpstrFile
  301. lea edi,[ebx].dwFileName
  302. cplp4:
  303. lodsb
  304. stosb
  305. or al,al
  306. jnz cplp4
  307. wmcsaveas ENDP
  308. ;
  309. ; fall through
  310. ;
  311. wmcsave PROC
  312. sub eax,eax
  313. ret
  314. wmcsave ENDP
  315. wmcommand ENDP
  316. wmqueryend PROC
  317. mov eax,1
  318. ret
  319. wmqueryend ENDP
  320. ;
  321. ; we do this to keep up with changes elsewhere
  322. ;
  323. dpcclose PROC
  324. call SendMessage,[hwndFrame],WM_COMMAND,IDM_CLOSE,0
  325. sub eax,eax
  326. ret
  327. dpcclose ENDP
  328. DrawProc ENDP
  329. end