10-7-2012
Program still errors out after painting the 1st screen.
I feel that it is some register change that I can not see in GoAsm.
Have no debugger to help me.
In MASM32 I avoided the stack like the plague. Only used it for
push/pop, pushad\popad. Savregx was much easier to follow.
So I do not really understand what "and rsp,-16 and sub rsp, 4*8"
are doing. I know that GoAsm adds rcx,rdx,r8 and R9 to the stack
but that is as far as I get at the present time in my learning curve.
In L1 what is cmp eax,-1 doing?
I noticed that you put GlobalFree in WM_DESTROY but did not use
GlobalLock in WM_CREATE. Is that OK??
Don't know how to do the fancy scroll goodie that you did.
Thanks for your help qWord
#define LINKFILES
#define codejps
#define WIN64
#INCLUDE windows.h
DATA SECTION
colorbk dq 00ff0000h ; blue
dwNeeded dq 0
dwReturned dq 0
hBrush dq 0
hdcPrn dq 0
hInstance dq 0
pinfo4 dq 0
BufAdd dd 0
holdleft dd 0
holdright dd 0
holdbottom dd 0
holdtop dd 0
savemiddleofX dd 0
AppName db "blah1",0
datestring db "MM'-'dd'-'yyyy",0
szDisplayName db 'wc',0
CommandLine LPSTR ?
.code
start:
and rsp,-16
sub rsp,4*8
invoke GetModuleHandleA, NULL
mov [hInstance],eax
invoke GetCommandLine
invoke WinMain, [hInstance],NULL,[CommandLine],SW_SHOWDEFAULT
invoke ExitProcess,rax
WinMain:
FRAME hInst,hPrevInst,CmdLine,CmdShow
LOCAL wc:WNDCLASSEXA,msg:MSG,hdc,rc:RECT,hWnd
mov D[wc.cbSize], SIZEOF WNDCLASSEXA
mov D[wc.style], CS_BYTEALIGNWINDOW | CS_HREDRAW | CS_VREDRAW
mov rax,offset WndProc
mov Q[wc.lpfnWndProc],rax
mov D[wc.cbClsExtra], NULL
mov D[wc.cbWndExtra], NULL
push [hInst]
pop [wc.hInstance]
invoke LoadIcon, NULL,IDI_APPLICATION
mov Q[wc.hIcon], rax
invoke LoadCursor, NULL,IDC_ARROW
mov Q[wc.hCursor], rax
invoke CreateSolidBrush, [colorbk] ; background color
mov Q[hBrush], rax
mov Q[wc.hbrBackground], rax
mov Q[wc.lpszMenuName], NULL
mov Q[wc.lpszClassName], OFFSET szDisplayName
mov Q[wc.hIconSm], 0
invoke RegisterClassExA, addr wc
invoke SystemParametersInfoA, SPI_GETWORKAREA,0,addr rc,0
mov eax,[rc.left]
mov [holdleft], eax
mov eax,[rc.right]
mov [holdright],eax
shr eax,1
mov [savemiddleofX],eax
mov eax,[rc.bottom]
mov [holdbottom],eax
mov eax,[rc.top]
mov [holdtop],eax
; This code executed when turned on
; temp code begin
;tmsg1 db 'got to end of winmain_cr',0
; invoke MessageBox, [hWnd], addr tmsg1, addr tmsg1, MB_OK ;true
; temp code end
INVOKE CreateWindow, addr szDisplayName,addr AppName,\
WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_MAXIMIZEBOX|WS_MINIMIZEBOX,\
[rc.left],[rc.top],[rc.right],[rc.bottom],NULL,NULL,[hInstance],NULL
mov [hWnd],rax
invoke ShowWindow, [hWnd],SW_SHOWNORMAL
invoke UpdateWindow, [hWnd]
; The above instruction executed and the screen appeared
L1:
INVOKE GetMessageA,addr msg,0,0,0
test eax,eax ;see if it is WM_QUIT
jz >L2 ;yes
cmp eax,-1
je >L2
INVOKE TranslateMessage,addr msg
INVOKE DispatchMessageA,addr msg
jmp L1 ;after message dealt with, loop back for next one
L2: ;message was WM_QUIT
ret
ENDF
WndProc:
FRAME hWnd,uMsg,wParam,lParam
USES rbx,rdi,rsi
Local hMemory,ps:PAINTSTRUCT,hdc
.WM_CREATE
cmp D[uMsg],WM_CREATE
jne >>.WM_CHAR
mov Q[dwNeeded],0
invoke GetDC, [hWnd]
mov [hdc], rax
invoke EnumPrinters, PRINTER_ENUM_LOCAL,NULL,4,NULL,\
0,addr dwNeeded,addr dwReturned
invoke GlobalAlloc, GPTR,[dwNeeded]
test rax,rax
jz >>.err@GlobalAlloc
mov [hMemory], rax
invoke GlobalLock, rax
mov [pinfo4],rax
invoke EnumPrinters, PRINTER_ENUM_LOCAL,NULL,4,[pinfo4],\
[dwNeeded],addr dwNeeded,addr dwReturned
mov rbx,[pinfo4]
mov rdx, [rbx+PRINTER_INFO_4.pPrinterName]
invoke CreateDC, NULL,rdx,NULL,NULL
mov [hdcPrn],rax
invoke GlobalUnlock, [hMemory]
invoke Rectangle, [hdc],0,0,[holdright],[holdbottom]
; This code executed when turned on
; temp code begin
;tmsg2 db 'got to end of wm_create',0
; invoke MessageBox, [hWnd], addr tmsg2, addr tmsg2, MB_OK ;true
; temp code end
jmp >>.END
.err@GlobalAlloc
; allocation error
invoke ExitProcess,0
jmp >>.END
.WM_CHAR
cmp D[uMsg],WM_CHAR
jne >>.WM_PAINT
jmp >>.END
.WM_PAINT
cmp D[uMsg],WM_PAINT
jne >>.WM_DESTROY
; This code never executes
; temp code begin
;tmsg3 db 'got wm_paint',0
invoke MessageBox, [hWnd], addr tmsg3, addr tmsg3, MB_OK ;true
; temp code end
jmp >>.END
.WM_DESTROY
cmp D[uMsg],WM_DESTROY
jne >.default
invoke GlobalUnlock, [hMemory]
invoke GlobalFree, [hMemory]
invoke ReleaseDC,[hWnd],[hdc]
invoke PostQuitMessage,NULL
jmp >>.END
.default
invoke DefWindowProc,[hWnd],[uMsg],[wParam],[lParam]
ret
.END
xor rax, rax
ret
ENDF