DRAWWIN.ASM
上传用户:ys_happy
上传日期:2007-01-09
资源大小:20k
文件大小:7k
- .386
- .model flat,STDCALL
- extrn Dispatch : PROC, hwndFrame : DWORD, hwndClient : DWORD
- extrn handlesb : PROC ,scrollkeys : PROC
- extrn DisplayWindowBars: PROC, SetBarRanges : PROC
- extrn ShiftState : BYTE
- extrn OpenFileDialog : PROC, SaveFileDialog : PROC
- include win32.asi ; some 32-bit constants and structures
- include win32.ase
- include commdlg.asi
- include fdid.asi
- include fdui.asi
- .data
- Public numberofdrawwindows
- numberofdrawwindows dd ?
- childxpos dd ?
- childypos dd ?
- szMyName db 'Unknown',0
- szDrawClassName db 'LADsoftGPLDraw',0
- .code
- public RegisterDrawWindow
- RegisterDrawWindow PROC hInst : DWORD
- LOCAL wc : WNDCLASS,
- bluebrush : LOGBRUSH, hBrush : dword
- ; make us a blue brush
- ;
- mov [bluebrush.lbStyle],BS_SOLID
- mov [bluebrush.lbColor],0FF0000h
- mov [bluebrush.lbHatch],0
- lea eax,[bluebrush]
- call CreateBrushIndirect,eax
- mov [hBrush],eax
- ;
- ; initialize the DrawClass structure
- ;
- mov [wc.clsStyle], CS_HREDRAW + CS_VREDRAW + CS_GLOBALCLASS
- mov [wc.clsLpfnWndProc], offset DrawProc
- mov [wc.clsCbClsExtra], 0
- mov [wc.clsCbWndExtra], 4 ; pointer for window instance data
- mov eax, [hInst]
- mov [wc.clsHInstance], eax
- call LoadIcon,0,IDI_APPLICATION
- mov [wc.clsHIcon], eax
- call LoadCursor,0,IDC_ARROW
- mov [wc.clsHCursor], eax
- mov eax,[hBrush]
- mov [wc.clsHbrBackground], eax
- mov [dword ptr wc.clsLpszMenuName], 0
- mov [dword ptr wc.clsLpszClassName], offset szDrawClassName
- lea eax,[wc]
- call RegisterClass,eax
- ;
- ; delete the blue brush
- ;
- call DeleteObject,[hBrush]
- ret
- RegisterDrawWindow ENDP
- public CreateDrawWindow
- CreateDrawWindow PROC hInst : dword
- LOCAL mc : MDICREATESTRUCT
- ; first create the window
- inc [numberofdrawwindows]
- mov [mc.szClass],offset szDrawClassName
- mov [mc.szTitle], offset szMyName
- mov eax,[hInst]
- mov [mc.hOwner], eax
- mov eax,[childxpos]
- mov [mc.x],eax
- mov eax,[childypos]
- mov [mc.y],eax
- mov [mc.cxc],0
- mov [mc.cyc],0
- mov [mc.style],0
- mov [mc.lParam],0
- lea eax,[mc]
- call SendMessage,[hwndClient],WM_MDICREATE,0,eax
- ;
- ; update next window pos
- ;
- add [childxpos],20
- add [childypos],20
- cmp [childxpos],120
- jc nopos0
- mov [childxpos],0
- mov [childypos],0
- nopos0:
- ret
- CreateDrawWindow ENDP
- public DrawProc
- DrawProc PROC uses ebx edi esi, hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
-
- mov eax,[wmsg]
- call Dispatch
- dd 10
- dd WM_SYSCOMMAND,wmsyscommand
- dd WM_COMMAND,wmcommand
- dd WM_HSCROLL,wmhscroll
- dd WM_VSCROLL,wmvscroll
- dd WM_KEYDOWN,wmkeydown
- dd WM_KEYUP,wmkeyup
- dd WM_CREATE,wmcreate
- dd WM_CLOSE, wmclose
- dd WM_DESTROY,wmdestroy
- dd WM_QUERYENDSESSION,wmqueryend
- jnc dp_nodef
- call dpdef
- dp_nodef:
- ret
- dpdef PROC
- call DefMDIChildProc,hwnd,wmsg,wparam,lparam
- ret
- dpdef ENDP
- wmcreate PROC
- ;
- ; Get the name of the file
- ; we have to do this first so we don't allocate stuff if
- ; we aren't going to have a window
- ;
- call OpenFileDialog,0,[hwnd]
- or eax,eax
- jnz opened
- mov eax,-1
- ret
- opened:
- push esi
- push edi
- push ebx
- push eax
- ;
- ; now install the window data
- ;
- call GetProcessHeap
- call HeapAlloc,eax,HEAP_ZERO_MEMORY,size dwinfo
- push eax
- call SetWindowLong,[hwnd],0,eax
- pop ebx
- ;
- ; init the window data. The heap alloc we did is nonmoveable, so
- ;
- mov [ebx + dwinfo.phsb.sbheight],200
- mov [ebx + dwinfo.phsb.sbstyle],SB_HORZ
- mov [ebx + dwinfo.phsb.sbpaging],10
- mov [ebx + dwinfo.pvsb.sbheight],200
- mov [ebx + dwinfo.pvsb.sbstyle],SB_VERT
- mov [ebx + dwinfo.pvsb.sbpaging],10
- ;
- ; set the window title and file name strings
- ;
- pop ecx
- push ecx
- mov esi,[ecx].oflpstrFileTitle
- lea edi,[ebx].dwTitle
- cplp:
- lodsb
- stosb
- or al,al
- jnz cplp
- lea eax,[ebx].dwTitle
- call SetWindowText,[hwnd],eax
- pop ecx
- mov esi,[ecx].oflpstrFile
- lea edi,[ebx].dwFileName
- cplp2:
- lodsb
- stosb
- or al,al
- jnz cplp2
- ;
- ; now put the scrollbars up and show them
- ;
- lea eax,[ebx + dwinfo.pvsb]
- call SetBarRanges,[hwnd],ebx,eax
- call ShowScrollBar,[hwnd],SB_BOTH,1
- pop ebx
- pop edi
- pop esi
- sub eax,eax
- ret
- wmcreate ENDP
- wmdestroy PROC
- ;
- ; now get rid of any window memory.
- ;
- dec [numberofdrawwindows]
- call GetWindowLong,[hwnd],0
- push eax
- call GetProcessHeap
- pop ebx
- call HeapFree,eax,0,ebx
- sub eax,eax
- ret
- wmdestroy ENDP
- wmkeydown PROC
- call GetWindowLong,[hwnd],0
- lea eax,[eax + dwinfo.phsb]
- call scrollkeys,[hwnd],[wparam],eax
- cmp [wparam],VK_SHIFT
- jnz wmkdx
- mov [ShiftState],1
- sub eax,eax
- ret
- wmkdx:
- call dpdef
- sub eax,eax
- ret
- wmkeydown ENDP
- wmkeyup PROC
- cmp [wparam],VK_SHIFT
- jnz wmkux
- mov [ShiftState],0
- call dpdef
- sub eax,eax
- ret
- wmkux:
- sub eax,eax
- ret
- wmkeyup ENDP
- wmhscroll PROC
- ; update scroll pos
- call GetWindowLong,[hwnd],0
- mov ebx,[wparam]
- mov ecx,ebx
- movzx ebx,bx
- shr ecx,16
- lea eax,[eax + dwinfo.phsb]
- call handlesb,[hwnd],eax,ebx,ecx
- sub eax,eax
- ret
- wmhscroll ENDP
- wmvscroll PROC
- ; update scroll pos
- call GetWindowLong,[hwnd],0
- mov ebx,[wparam]
- mov ecx,ebx
- movzx ebx,bx
- shr ecx,16
- lea eax,[eax + dwinfo.pvsb]
- call handlesb,[hwnd],eax,ebx,ecx
- sub eax,eax
- ret
- wmvscroll ENDP
- wmclose PROC
- call SendMessage,[hwnd],WM_QUERYENDSESSION,0,0
- or eax,eax
- jz wmcclosex
- call SendMessage,[hwnd],WM_COMMAND,IDM_SAVE,0
- call dpdef
- sub eax,eax
- ret
- wmcclosex:
- mov eax,-1
- ret
- wmclose ENDP
- wmsyscommand PROC
- mov eax,[wparam]
- movzx eax,ax ; get rid of accel flag
- call Dispatch
- dd 1
- dd SC_CLOSE,dpcclose
- call DefMDIChildProc,hwnd,wmsg,wparam,lparam
- sub eax,eax
- ret
- wmsyscommand ENDP
- wmcommand PROC
- mov eax,[wparam]
- call Dispatch
- dd 3
- dd IDM_SAVE,wmcsave
- dd IDM_SAVEAS,wmcsaveas
- dd IDM_CLOSE,wmcclose
- ret
- wmcclose PROC
- call SendMessage,[hwnd],WM_CLOSE,0,0
- ret
- wmcclose ENDP
- wmcsaveas PROC
- call GetWindowLong,[hwnd],0
- mov ebx,eax
- lea eax,[eax].dwTitle
- call SaveFileDialog,eax,[hwnd]
- or eax,eax
- jnz accepted
- sub eax,eax
- ret
- accepted:
- mov ecx,eax
- ;
- ; set the window title and file name strings
- ;
- push ecx
- mov esi,[ecx].oflpstrFileTitle
- lea edi,[ebx].dwTitle
- cplp3:
- lodsb
- stosb
- or al,al
- jnz cplp3
- lea eax,[ebx].dwTitle
- call SetWindowText,[hwnd],eax
- pop ecx
- mov esi,[ecx].oflpstrFile
- lea edi,[ebx].dwFileName
- cplp4:
- lodsb
- stosb
- or al,al
- jnz cplp4
-
- wmcsaveas ENDP
- ;
- ; fall through
- ;
- wmcsave PROC
- sub eax,eax
- ret
- wmcsave ENDP
- wmcommand ENDP
- wmqueryend PROC
- mov eax,1
- ret
- wmqueryend ENDP
- ;
- ; we do this to keep up with changes elsewhere
- ;
- dpcclose PROC
- call SendMessage,[hwndFrame],WM_COMMAND,IDM_CLOSE,0
- sub eax,eax
- ret
- dpcclose ENDP
- DrawProc ENDP
- end