News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Window creation for OLIST.EXE

Started by Tight_Coder_Ex, November 25, 2007, 06:54:32 AM

Previous topic - Next topic

Tight_Coder_Ex

Nothing exciting here, but as it is part of the application I decided to post as only those parts that change in the future will be posted.

.686
.model flat, stdcall
option casemap:none

include windows.inc
include kernel32.inc
include user32.inc
include gdi32.inc

includelib kernel32.lib
includelib user32.lib
includelib gdi32.lib
includelib Horizons.lib

ParseCL PROTO :dword
MsgBox PROTO :dword, :dword, :dword, :dword
ScanMap PROTO

.const
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

  MainMap dd 0 ; Default windows procedure
dw (MainEnd - MainMap) / 6 - 1 ; Number of handlers

dw WM_DESTROY ; Main windows destroyed
dd QuitApp

  MainEnd equ $

  AppName db 'OLIST', 0
  AppTitle db 'Ordered List Maintenance', 0

.data
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

  CmdLines dd 0 ; Pointer to command line parameters

  Wc dd 48 ; cbSize
dd CS_HREDRAW + CS_VREDRAW + CS_BYTEALIGNCLIENT
dd MWndProc ; lpfnWndProc
dd 0 ; cbClsExtra
dd 0 ; cbWndExtra
  dd 0 ; hInst
dd 0 ; hIcon
dd 0 ; hCursor
dd COLOR_APPWORKSPACE + 1
dd 0 ; lpszMenuName
dd AppName ; lpszClassName
dd 0 ; hIconSm

.code
; --------------------------------------------------------------------------------------------

  Start: enter 0, 0 ; Empty procedure frame

push 0
call GetModuleHandle
mov Wc + 20, eax ; Wc.hInst

push 84 ; Maximum number of arguments
call ParseCL
push eax ; Save actual arguments passed
mov CmdLines, esp ; Save pointer to command line parameters

call MainWnd

leave ; Destroy procedure frame

push eax ; Returned from message pump
call ExitProcess ; Orderly cleanup

; ============================================================================================

  MainWnd proc

STYLE EQU WS_VISIBLE or WS_THICKFRAME or WS_MINIMIZEBOX or WS_SYSMENU

LOCAL Msg:MSG

mov dword ptr Msg.wParam, -1

push IDC_ARROW
push 0
call LoadCursor
mov Wc.WNDCLASSEX.hCursor, eax

push offset Wc
call RegisterClassEx
and eax, eax
jnz $ + 3

int 3 ; Error function MsgBox will go here

; Create window and display it

xor eax, eax
push eax ; lpParam
push dword ptr Wc + 20 ; hInstance
push eax ; hMenu
push eax ; hWndParent

bts eax, 31
push eax ; nHeight
push eax ; nWidth
push eax ; y
push eax ; x
push STYLE
push offset AppTitle
push offset AppName
push WS_EX_STATICEDGE
call CreateWindowEx
and eax, eax
jz Done

lea ebx, Msg

; Applications main message pump

@@: xor eax, eax
push eax ; wMsgFilterMax
push eax ; wMsgFilterMin
push eax ; hWnd, NULL = Desktop
push ebx
call GetMessage
and eax, eax
jz Done

push ebx ; lpMsg
call TranslateMessage
push ebx
call DispatchMessage
jmp @B

  Done: mov eax, Msg.wParam ; Get return value
ret

  MainWnd endp
; ============================================================================================

  MWndProc: mov esi, offset MainMap
jmp ScanMap

; ============================================================================================

  QuitApp: push 0 ; Return value
call PostQuitMessage
stc ; No default processing
ret

; ============================================================================================
end Start

lingo

"Nothing exciting here"

You can take a look of my Message Loop with MMX here:
http://www.masm32.com/board/index.php?topic=6628.15

and there:
http://www.masm32.com/board/index.php?topic=6729.0

I'm wondering about usage of and eax, eax in your code...
I prefer test eax, eax... :wink

Regard,
Lingo

Tight_Coder_Ex

Quote from: lingo on November 25, 2007, 02:21:19 PM
I'm wondering about usage of and eax, eax in your code...
I prefer test eax, eax...

You have a point, but generally and for no apparent reason I only use test where there is a need to be none destructive.  You refer to your message pump as being with MMX, could you please qualify what you mean by that.

I've never investigated timings, but there is no benefit space wise in using test over and, so I am curious as to your preference.