NicoDean
Joined: 22 May 2007
Posts: 1
|
Hello,
I want to code a program, which creates a window. From time to time the main program should write a text to the window.
I've done the window and window proc, which reads the WM_PAINT Messages, and uses DrawText to write it to the Window.
Unfortanutally, this just work for the first time, all other times the text will not be drawn to the window. I've searched for many hours, read (non-FASM) examples, where it should work.
Could anybody tell me where the mistake is? Thanks alot!!!
kind regards,
NicoDean
include '..\fasm\INCLUDE\win32ax.inc'
.data
WNDC WNDCLASS
wRECT RECT
wPAINTSTRUCT PAINTSTRUCT
wmsg MSG
whDC dd 0x0
hinst dd 0x0
classname db "ClassName",0x0
windowname db "Master's Window",0x0
windowtext db "mytext",0x0
mainhwnd dd 0x0
.code
start:
invoke GetModuleHandle,0
mov [hinst],eax
invoke LoadIcon,0,IDI_APPLICATION
mov [WNDC.hIcon],eax
invoke LoadCursor,0,IDC_ARROW
mov [WNDC.hCursor],eax
mov [WNDC.style],0
mov [WNDC.lpfnWndProc],WindowProc
mov [WNDC.cbClsExtra],0
mov [WNDC.cbWndExtra],0
mov eax,[hinst]
mov [WNDC.hInstance],eax
mov [WNDC.hbrBackground],COLOR_BTNFACE+1
mov [WNDC.lpszMenuName],0
mov [WNDC.lpszClassName], classname
invoke RegisterClass,WNDC
invoke CreateWindowEx,0,classname,windowname,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,192,192,NULL,NULL,[hinst],NULL
mov [mainhwnd],eax
invoke ShowWindow, [mainhwnd], SW_SHOW
; invoke UpdateWindow, [mainhwnd]
invoke SendMessage, [mainhwnd], WM_PAINT, 0x0, windowname
msgloop:
invoke GetMessage, wmsg, 0x0, 0x0, 0x0
cmp eax, 0x0
je end_msgloop
invoke TranslateMessage, wmsg
invoke DispatchMessage, wmsg
invoke SendMessage, [mainhwnd], WM_PAINT, 0x0, windowtext
jmp msgloop
end_msgloop:
; invoke Sleep, 2000
; invoke SendMessage, [mainhwnd], WM_SETTEXT, 0x0, windowname
; invoke Sleep, 2000
; invoke SendMessage, [mainhwnd], WM_DESTROY, 0x0, 0x0
; invoke SendMessage, [mainhwnd], WM_SETTEXT, 0x0, windowtext
; invoke MessageBox, 0x0, "a", "h", 0x0
; invoke Sleep, 3000
invoke ExitProcess, 0x0
proc WindowProc, hwnd, wmsg, wparam, lparam
pusha
cmp [wmsg],WM_DESTROY
je window_wmdestroy
cmp [wmsg],WM_PAINT
je window_printtext
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp window_finish
window_printtext:
invoke BeginPaint, [hwnd], wPAINTSTRUCT
mov [whDC], eax
invoke GetClientRect, [hwnd], wRECT
invoke DrawText, [whDC], [lparam], -1, wRECT, DT_LEFT
invoke EndPaint, [hwnd], wPAINTSTRUCT
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp window_finish
window_wmdestroy:
invoke PostQuitMessage,0
xor eax, eax
window_finish:
popa
return
endp
.end start
|