Register class & Create Window

Tight_Coder_Ex 0 Tallied Votes 243 Views Share

Additional features will be added to this section of code such as fixing window size proportial to monitors resolution and subclassing the single edit control of this program. You'll notice I don't call ShowWindow here as WS_VISIBLE in windows style is defined.

STYLE		EQU	WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_VISIBLE
  EX_STYLE	EQU	WS_EX_STATICEDGE



  Wc		dd	48			; cbSize
		dd	CS_HREDRAW | CS_VREDRAW	
		dd	MainWndProc		; Main window procedure
		dd	0, 0			; cbClsExtra & cbWndExtra
  hInst		dd	0			; Instance Handle
		dd	0			; hIcon
		dd	0			; hCursor
		dd	COLOR_APPWORKSPACE + 1
		dd	0			; Hmenu
		dd	AppName			; Applications name
		dd	0			; Small Icon			

; ----------------------------------------------------------------------------------------------------------------------
  AppTitle	db	'Ordered List Lookup & Maintenance', 0
  AppName	db	'LOOK', 0

;-----------------------------------------------------------------------------------------------------------------------

  Cw		dd	EX_STYLE		; dwExStyle
		dd	AppName			; lpClassName
		dd	AppTitle		; lpWindowName
		dd	STYLE			; dwStyle
		dd	CW_USEDEFAULT		; x
		dd	CW_USEDEFAULT		; y
		dd	CW_USEDEFAULT		; nWidth
		dd	CW_USEDEFAULT		; nHeight
		dd	0			; hWndParent
		dd	0			; hMenu
		dd	0			; hInstance
		dd	0			; lpParam


; ============================================================================================
  				     *** SHOW MAIN WINDOW ***

  ; As the name implies the only responsiblity of this section of code is to register and 
  ; display main window.  

;	LEAVE: 	 CY = 1, If either registering class or creating window failed.  Additional
;			 code could be added to further define which caused the error.
; _____________________________________________________________________________________________

  ShowMainWnd	push	ebx
		mov	ebx, Wc			; Point to WNDCLASSEX structure in .data

		push	IDC_ARROW		; Establish main windows cursor
		push	byte 0
		call	_LoadCursorA@8
		mov	[ebx + 0x1c], eax	; hCursor

		push	byte 0
		call	_GetModuleHandleA@4
		mov	[hInst], eax
		push	eax

  	; Now that everything has been initialized the window class can be registered.

		push	ebx
		call	_RegisterClassExA@4
		and	eax, eax		; Set flags
		jz	.Exit			; EAX = 0 then registration failed.		

	; Create applications main window
		mov	ebx, Cw
		pop	eax		
		mov	[ebx + 40], eax
		call	Create_Wnd
		mov	[MainWnd], eax		; Save hWnd
		jnc	.Exit + 1

  .Exit		stc
		pop	ebx
		ret