Hi


What do I miss here to get this program work right :confused:

I just want it to startup without the client area to be
updated, and then when you click the button, the
background/client area is updated.
Posted on 2004-04-04 04:56:01 by The SharK
Shark,

I had a quick look but I can't figure out you really intend to do.

I point out a couple errors and wait for more info.



to get BN_CLICKED from WM_COMMAND do the following:

.ELSEIF uMsg==WM_COMMAND
mov eax, wParam
shr eax, 16
.IF ax==BN_CLICKED
; do stuff
.ENDIF


Please also note that in your Thread procedure you have the following errors:

[*] You declare rect as Local.. And you decide to use the rect without ever filling the structure. Consider making a call to GetClientRect first.
[*] In the thread procedure you also declare hwnd as local and you use it like erm.. an hwnd .. This can not work as this just declared hwnd is 0.
Posted on 2004-04-04 07:30:13 by JimmyClif
Ok JimmyClif


I think I have corrected the errors, but what is wrong with
the ThreadProc now, since it won't assemble :confused:
Posted on 2004-04-06 08:55:33 by The SharK
Remove that comma and I think it will work. oh yes dec sets zero flag, thus no need to have the cmp there.
Posted on 2004-04-06 09:21:11 by roticv
Hi roticv


I don't quite follow what you mean...
What comma ?

If I move a number into ecx, and I use dec, then that number
is just decremented by one, so my Idea was to make a delay,
I could have used sleep
:)
Posted on 2004-04-06 09:56:47 by The SharK
Hi TS

Try this ..........




;RECT STRUCT
; left DD ?
; top DD ?
; right DD ?
; bottom DD ?
;RECT ENDS

MyRect RECT <?,?,?,?>

.
.
ThreadProc PROC uses ecx ;sParam:DWORD
mov ecx,600000000
Loop1: dec ecx
jz Get_out
invoke GetClientRect, hwnd, ADDR MyRect
invoke ValidateRect,hwnd, ADDR MyRect
invoke UpdateWindow, hwnd
jmp Loop1
Get_out:
invoke SendMessage,hwnd,WM_FINISH,NULL,NULL
ret
ThreadProc ENDP



Peace
Posted on 2004-04-06 09:57:33 by mistronr1
Your code:


ThreadProc PROC uses ecx, Param:DWORD


Should be


ThreadProc PROC uses ecx Param:DWORD


mistronr1,

The kernel calls the Threadproc with 1 parameter and you need to clear the stack.
Posted on 2004-04-06 10:27:31 by roticv
Ok thanks


Now it assembles right, but I have to make some changes to the program.
My idea was to make the client area un-updated, so if you drag some other
window into the client area, the window would "hang" in the client area,
without any update to remove the window. Then if you pushed the button,
the client area would be updated, and the window you dragged into it,
would disappear.

Not that it's a totally unique program, just for studying purposes only ;-)

Btw.
I took the ThreadProc, from Iczelion's tut15 - where did the "Param" parameter
came from, I mean was the idea of it, just to clear the stack :confused:
Posted on 2004-04-06 10:55:08 by The SharK
You can pass the dword or pointer that the threadproc functions needs via the lparam of CreateThread. A good example would be the following by QvasiModo



.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data
MsgTitle db "Hello",0
Msg1 db "Message 1",0
Msg2 db "Message 2",0
Msg3 db "Message 3",0
.data?
ThreadID dd ?

hThread1 dd ?
hThread2 dd ?
hThread3 dd ?

.code

MessageProc PROTO :DWORD

start:

invoke CreateThread, NULL, 0, addr MessageProc, addr Msg1, 0, addr ThreadID
mov hThread1,eax
push eax
invoke CreateThread, NULL, 0, addr MessageProc, addr Msg2, 0, addr ThreadID
mov hThread2,eax
push eax
invoke CreateThread, NULL, 0, addr MessageProc, addr Msg3, 0, addr ThreadID
mov hThread3,eax
push eax

invoke WaitForMultipleObjects,3,offset hThread1,TRUE,INFINITE

call CloseHandle
call CloseHandle
call CloseHandle
invoke ExitProcess, 0

MessageProc PROC msg:DWORD
invoke MessageBox, NULL, msg, addr MsgTitle, MB_OK
ret
MessageProc ENDP
end start


I do not know why I added this post. Abit out of topic. hmm
Posted on 2004-04-06 10:59:46 by roticv
Hi roticv !

Nice program anyway, guess I learned a little about threads ;-)

Where do I place InvalidateRect, to make the whole client area invalid :confused:

and then when I push the button the client area is updated - any hint :confused:




.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD

.data
ClassName db "SimpleWinClass",0
ButtonClass db "Button",0
AppName db "Our First Window",0
ButtonText_1 db "Refresh Client Area",0



.data?
hInstance dd ?
CommandLine dd ?
hwndButton_1 dd ?
ThreadID DWORD ?
hwnd HANDLE ?
MyRect RECT <?,?,?,?>



.const
ButtonID_1 equ 7
WM_FINISH equ WM_USER+100h

.code
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT
invoke ExitProcess, eax




WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+2
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, OFFSET ClassName
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax
invoke RegisterClassEx, addr wc

; CreateWindowEx:
; ######################
; HWND CreateWindowEx(
; DWORD dwExStyle,
; LPCTSTR lpClassName,
; LPCTSTR lpWindowName,
; DWORD dwStyle,
; int x,
; int y,
; int nWidth,
; int nHeight,
; HWND hWndParent,
; HMENU hMenu,
; HINSTANCE hInstance,
; LPVOID lpParam
; );
; ######################
invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,\
NULL,NULL,hInst,NULL
mov hwnd, eax
invoke ShowWindow, hwnd, SW_SHOWNORMAL

invoke CreateWindowEx,NULL,addr ButtonClass,addr ButtonText_1,\
WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,\
300,42,132,22,hwnd,ButtonID_1,hInstance,NULL
mov hwndButton_1,eax
invoke UpdateWindow, hwnd
.WHILE TRUE
invoke GetMessage, ADDR msg, NULL, 0, 0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret
WinMain endp




WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

.if uMsg == WM_DESTROY
invoke PostQuitMessage, NULL

.ELSEIF uMsg==WM_COMMAND

; ######################################
; BN_CLICKED:
; wParam:
; The low-order word contains the button's control identifier.
; The high-order word specifies the notification message.
; ######################################
mov eax, wParam
shr eax, 16
.IF ax==BN_CLICKED
mov eax,OFFSET ThreadProc
invoke CreateThread,NULL,NULL,eax,\
NULL,NORMAL_PRIORITY_CLASS,\
ADDR ThreadID
invoke CloseHandle,eax
.ENDIF

.else
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
ret
.endif
xor eax,eax
ret
WndProc endp




ThreadProc PROC uses ecx Param:DWORD
mov ecx,10000000
Loop1: dec ecx
cmp ecx,0
jz Get_out
push ecx
invoke GetClientRect, hwnd, ADDR MyRect
invoke ValidateRect,hwnd, ADDR MyRect
invoke UpdateWindow, hwnd
pop ecx
jmp Loop1
Get_out:
invoke SendMessage,hwnd,WM_FINISH,NULL,NULL
ret
ThreadProc ENDP

end start
Posted on 2004-04-07 02:40:16 by The SharK