www.pudn.com > fd.zip > FD.ASM


	.386 
	.model flat,STDCALL 
 
	extrn Dispatch : PROC, handlesb : proc, scrollkeys : proc 
	extrn CreateDrawWindow : PROC, RegisterDrawWindow : PROC 
	extrn numberofdrawwindows : dword 
	extrn WaitingProc : proc, YesNoProc : proc 
	extrn SaveFileDialog : PROC 
 
	public hwndFrame, hwndClient 
 
include win32.asi           ; some 32-bit constants and structures 
include win32.ase 
include commdlg.asi 
include fdid.asi 
include fdui.asi 
 
	.DATA 
copyright        db 'Fractal Designer 1.0 Copyright (c) LADsoft, 1998',0 
 
hInst            dd 0 
hMenuMain	dd	? 
hwndClient	dd	? 
hwndFrame	dd	? 
hAccel		dd	? 
childxpos	dd	? 
childypos	dd	? 
 
szTitleName      db 'Fractal Designer 1.0',0 
szFrameClassName      db 'LADsoftFDFrame',0 
szDrawClassName      db 'LADsoftFDDraw',0 
szClientClassName db	'MDICLIENT',0 
szMainAccel	db	'MAINACCELERATORS',0 
szMainMenu	db	'MAINMENU',0 
szAboutDialog	db	'ABOUTDLG',0 
szAbortDialog	db	'ABORTDLG',0 
szAboutCapt	db	'About Fractal Designer',0 
szFDIcon	db	'FDICON',0 
psShow		db 	'SHOW',0 
 
	extrn	DrawProc : PROC, IntFromProfile : PROC, IntToProfile : PROC 
 
	.CODE 
;----------------------------------------------------------------------------- 
; 
; This is where control is received from the loader. 
; 
start	PROC 
	LOCAL	hAceel : dword, \ 
		msg : MSGSTRUCT, wc : WNDCLASS 
 
        call    GetModuleHandle,0         ; get hmod (in eax) 
        mov     [hInst], eax            ; hInst is same as HMODULE 
                                        ; in the Win32 world 
 
        call    FindWindow,offset szFrameClassName,0 
        or      eax,eax 
        jnz      no_reg_class 
; 
; 
; initialize the WndClass structure 
; 
        mov     [wc.clsStyle], CS_HREDRAW + CS_VREDRAW + CS_GLOBALCLASS 
        mov     [wc.clsLpfnWndProc], offset WndProc 
        mov     [wc.clsCbClsExtra], 0 
        mov     [wc.clsCbWndExtra], 0 
 
        mov     eax, [hInst] 
        mov     [wc.clsHInstance], eax 
 
        call    LoadIcon,[hInst],offset szFDIcon 
        mov     [wc.clsHIcon], eax 
 
        call    LoadCursor,0,IDC_ARROW 
        mov     [wc.clsHCursor], eax 
 
        mov     [wc.clsHbrBackground], COLOR_APPWORKSPACE + 1 
        mov     [dword ptr wc.clsLpszMenuName], 0 
        mov     [dword ptr wc.clsLpszClassName], offset szFrameClassName 
 
	lea	eax,[wc] 
        call    RegisterClass,eax 
 
	call	RegisterDrawWindow, [hInst] 
 
no_reg_class: 
 
; load resources and open frame 
; 
	call	LoadMenu,[hInst],offset szMainMenu 
	mov	[hMenuMain],eax 
 
	call	LoadAccelerators, [hInst],offset szMainAccel 
	mov	[hAccel],eax 
 
        call    CreateWindowEx, 0, offset szFrameClassName, offset szTitleName, \ 
			WS_OVERLAPPEDWINDOW OR WS_CLIPCHILDREN, \ 
			CW_USEDEFAULT, \ 
			CW_USEDEFAULT, \ 
			CW_USEDEFAULT, \ 
			CW_USEDEFAULT, \ 
			0,[hMenuMain],[hInst],0 
 
        mov     [hwndFrame], eax 
 
	lea	esi,[psShow] 
	mov	eax,SW_SHOWNORMAL 
	call	IntFromProfile 
 
        call    ShowWindow, [hwndFrame],eax 
 
        call    UpdateWindow, [hwndFrame] 
; 
; handle messages 
; 
msg_loop: 
	lea	eax,[msg] 
        call    GetMessage,eax,0,0,0 
        cmp     ax, 0 
        je      end_loop 
 
	lea	eax,[msg] 
	call	TranslateMDISysAccel,[hwndClient],eax 
	or	eax,eax 
	jnz	msg_loop 
 
	lea	eax,[msg] 
	call	TranslateAccelerator,[hwndFrame],[hAccel],eax 
	or	eax,eax 
	jnz	msg_loop 
 
	lea	eax,[msg] 
        call    TranslateMessage, eax 
	lea	eax,[msg] 
        call    DispatchMessage, eax 
 
        jmp     msg_loop 
 
end_loop: 
        call    ExitProcess, [msg.msWPARAM] 
 
        ; we never get to here 
start	endp 
 
;----------------------------------------------------------------------------- 
public WndProc 
WndProc PROC uses ebx edi esi, hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD 
; 
; WARNING: Win32 requires that EBX, EDI, and ESI be preserved!  We comply 
; with this by listing those regs after the 'uses' statement in the 'proc' 
; line.  This allows the Assembler to save them for us. 
; 
        LOCAL   csx : CLIENTCREATESTRUCT, \ 
			mf_state : DWORD 
 
	mov	eax,[wmsg] 
	call	Dispatch 
	dd	6 
	dd	WM_COMMAND,wmcommand 
	dd	WM_DESTROY,wmdestroy 
	dd	WM_CREATE,wmcreate 
	dd	WM_QUERYENDSESSION,wmqueryend 
	dd	WM_INITMENUPOPUP,wminitmenupopup 
	dd	WM_SIZE,wmsize 
	jnc	finish 
	call	wmdefault 
finish: 
	ret 
wmdefault	PROC 
        call    DefFrameProc,[hwnd],[hwndClient],[wmsg],[wparam],[lparam] 
	ret 
wmdefault	ENDP 
 
wmcreate PROC 
	mov	eax,[hMenuMain] 
	mov	[csx.hWindowMenu],eax 
	mov	[csx.idFirstChild],IDM_FIRSTCHILD 
	lea	eax,[csx] 
        call    CreateWindowEx, 0, offset szClientClassName, 0, \ 
			WS_CHILD OR WS_CLIPCHILDREN OR WS_VISIBLE, \ 
			CW_USEDEFAULT, \ 
			CW_USEDEFAULT, \ 
			CW_USEDEFAULT, \ 
			CW_USEDEFAULT, \ 
			[hwnd],1,[hInst],eax 
	mov	[hwndClient],eax 
 
; 
; set up the window for the project list 
; 
	call	GetSubMenu,[hMenuMain],ProjectsMenuItem 
	call	SendMessage,[hwndClient],WM_MDISETMENU,hMenuMain,eax 
; 
	sub	eax,eax 
	ret 
wmcreate ENDP 
 
wmdestroy PROC 
        call    PostQuitMessage,0 
	sub	eax,eax 
	ret 
wmdestroy ENDP 
 
wmqueryend	PROC 
       call	DialogBoxParam,[hInst],offset szAbortDialog,[hwnd],offset YesNoProc,0 
	ret 
wmqueryend	ENDP 
 
wminitmenupopup PROC 
	mov	[mf_state],MF_GRAYED 
	test	[numberofdrawwindows],-1 
	jz	wmimpz 
	mov	[mf_state],MF_ENABLED 
wmimpz: 
	call	EnableMenuItem,[hMenuMain],IDM_CLOSE,[mf_state] 
	call	EnableMenuItem,[hMenuMain],IDM_SAVEAS,[mf_state] 
	call	EnableMenuItem,[hMenuMain],IDM_SAVE,[mf_state] 
	call	EnableMenuItem,[hMenuMain],IDM_CASCADE,[mf_state] 
	call	EnableMenuItem,[hMenuMain],IDM_TILE,[mf_state] 
	call	EnableMenuItem,[hMenuMain],IDM_ARRANGE,[mf_state] 
	sub	eax,eax 
	ret 
wminitmenupopup	ENDP 
 
wmsize	PROC 
	cmp	[wparam],SIZEFULLSCREEN 
	jnz	wmsnma 
	mov	eax,SW_SHOWMAXIMIZED 
	jmp	wmsx 
wmsnma: 
	cmp	[wparam],SIZEICONIC 
	jnz	wmsnmi 
	mov	eax,SW_SHOWMINIMIZED 
	jmp	wmsx 
wmsnmi: 
	cmp	[wparam],SIZENORMAL 
	jnz	wmsnmx2 
	mov	eax,SW_SHOWNORMAL 
wmsx: 
	push	esi 
	push	edi 
	lea	esi,[psShow] 
	call	IntToProfile 
	pop	edi 
	pop	esi 
wmsnmx2: 
	call	wmdefault 
	sub	eax,eax 
	ret 
wmsize	ENDP 
wmcommand PROC 
	mov	eax,[wparam] 
	movzx	eax,ax	; get rid of accel flag 
	call	Dispatch 
	dd	6 
	dd	IDM_ABOUT,wmcabout 
	dd	IDM_NEWDRAW,wmcnewdraw 
	dd	IDM_EXIT,wmcexit 
	dd	IDM_CASCADE,wmccascade 
	dd	IDM_TILE,wmctile 
	dd	IDM_ARRANGE,wmcarrange 
	jnc	wmcx 
 
; 
; we didn't interp, send to active window 
;	 
	call	SendMessage,[hwndClient],WM_MDIGETACTIVE,0,0 
	push	eax 
	call	IsWindow,eax 
	or	eax,eax 
	pop	eax 
	jz	wmcnx 
	call	SendMessage,eax,WM_COMMAND,[wparam],[lparam] 
wmcnx: 
; 
; and to DefFrameProc 
; 
	call	wmdefault 
	sub	eax,eax 
wmcx: 
	ret 
wmcommand ENDP 
 
wmcabout PROC 
       call	DialogBoxParam,[hInst],offset szAboutDialog,[hwnd],offset WaitingProc,0 
	sub	eax,eax 
	ret 
wmcabout ENDP 
 
wmcnewdraw PROC 
	call	CreateDrawWindow, [hInst] 
	sub	eax,eax 
	ret 
wmcnewdraw ENDP 
 
wmcexit PROC 
	call	SendMessage,[hwnd],WM_QUERYENDSESSION,0,0 
	jz	wmcnex 
      	call	SendMessage,[hwnd],WM_CLOSE,0,0 
wmcnex: 
	sub	eax,eax 
	ret 
wmcexit ENDP 
 
wmccascade PROC 
	call	SendMessage,[hwndClient],WM_MDICASCADE,0,0 
	sub	eax,eax 
	ret 
wmccascade ENDP 
 
wmctile PROC 
	call	SendMessage,[hwndClient],WM_MDITILE,0,0 
	sub	eax,eax 
	ret 
wmctile ENDP 
 
wmcarrange PROC 
	call	SendMessage,[hwndClient],WM_MDIICONARRANGE,0,0 
	sub	eax,eax 
	ret 
wmcarrange ENDP 
WndProc	ENDP 
end start