--------------------------------------------------------------------------------

WM_CREATE Notification

The WM_CREATE message is sent when an application requests that a window be created by calling the CreateWindowEx or CreateWindow function. (The message is sent before the function returns.) The window procedure of the new window receives this message after the window is created, but before the window becomes visible.




Return Value

If an application processes this message, it should return zero to continue creation of the window. If the application returns ?1, the window is destroyed and the CreateWindowEx or CreateWindow function returns a NULL handle.





------------------------------------------------------------------------------
hi,all
above is information about WM_CREATE i find in msdn.
please notice the Return Value i made red color.

my question is how to return a value to CreateWindowEx or CreateWindow
when it send a WM_CREATE message.

thank u
Posted on 2004-11-20 22:11:53 by geegle
The easy way is to declare whatever global variables you may require and fill them with whatever data you need to return from the WM_CREATE code.

For example, the window handle is immediately available to the WM_CREATE code. If that handle is required for some other procedure called by the WM_CREATE code, you can copy it to a global variable for other procedures to use before the CreateWindowEx function returns with the handle in EAX.

Raymond
Posted on 2004-11-21 11:13:05 by Raymond
i m sorry, Raymond. i can not understand what you said.
Posted on 2004-11-21 22:13:01 by geegle
IIRC, this value is placed in EAX:


__WM_CREATE:
invoke HeapAlloc, WinMain_hHeap, NULL, SIZEOF _WINDOW

pushad
mov ebx, eax
ASSUME ebx:PTR _WINDOW

invoke SetWindowLong, WndProc_hWnd[8][32], GWL_USERDATA, ebx

ASSUME ebx:NOTHING
popad
xor eax, eax ; <--- OKAY to create window!
retn 16
...here I return zero in EAX, resulting in the continued creation of window. If something bad happened I could return the value 1 in EAX to stop window creation:
__WM_CREATE:

invoke HeapAlloc, WinMain_hHeap, NULL, SIZEOF _WINDOW
test eax, eax
jne okay
mov eax, 1 ; do NOT create window
retn 16
The above code is within the window PROC.
Posted on 2004-11-22 01:04:02 by bitRAKE
hi, bitRAKE. when we receive the WM_CREATE in window PROC,
the window have already created by windows. the only way i know to process the WM_CREATE is in window PROC. but, what i want to know is how we can process WM_CREATE outside the window PROC when the CreateWindow API is runing and how we return a value to it stop or continue the Creating window.
Posted on 2004-11-22 01:57:03 by geegle
You don't need to process any message "outside the window proc".

When you receive WM_CREATE in your window proc, return 1 in EAX to cancel (will destroy the window) or 0 to continue as normal.

Hope this helps :)
Posted on 2004-11-22 07:08:54 by QvasiModo
You don't need to process any message "outside the window proc".

When you receive WM_CREATE in your window proc, return 1 in EAX to cancel (will destroy the window) or 0 to continue as normal.

Hope this helps :)


hi, QvasiModo.
i put below code in window proc, but the window create as well as normal.
not be destroyed.


.if uMsg==WM_CREATE
mov eax,1
ret
Posted on 2004-11-22 07:21:49 by geegle
as i know, during the CreateWindow/CreateWindowEx function is being executed, Window PROC is called to process the WM_CREATE message. and then the return value will be checked.

all message related to the window u create should be and must be send to ur Window PROC, so if u want to process WM_CREATE message outside, maybe u need to put the message out again.
Posted on 2004-11-22 07:26:09 by gentlelover
the code below also run well as normal.


WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.if uMsg==WM_CREATE
mov eax,1
ret
.elseif uMsg==WM_DESTROY
invoke PostQuitMessage, NULL
.else
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
ret
.endif
xor eax,eax
ret
WndProc endp
Posted on 2004-11-22 07:42:55 by geegle
to say the truth, i cannot get ur meaning clearly. :(

sorry.
Posted on 2004-11-22 07:48:22 by gentlelover
hi, all, below is my opinion:
when we create a window, the windows send WM_CREATE before the window was created. and we receive WM_CREATE in window PROC after
the window was create. when we want to destroy window, return 1 to windows responsible to WM_CREATE in window PROC is too late,because the window had been create already. so we can not destroy window in window PROC but some where----what is my want to know.
Posted on 2004-11-22 07:58:31 by geegle
Not working for me either :(

Strange that MS docs got it so wrong... maybe we're making a mistake somewhere? :?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowmessages/wm_create.asp
Posted on 2004-11-22 08:45:52 by QvasiModo
You should return -1, not 1.
Posted on 2004-11-22 08:54:06 by death
LOL :P a bug on MSDN site. they should verify their texts more carefully :/

on the contrary - my "offline" platform sdk says:

If an application processes this message, it should return zero to continue creation of the window. If the application returns ?1, the window is destroyed and the CreateWindowEx or CreateWindow function returns a NULL handle.


so it looks like the bug is only on msdn library.
Posted on 2004-11-22 09:15:39 by ti_mo_n
geegle,

The basics of a WM_CREATE message is that it is sent to the address of the WndProc style procedure that is set in the WNDCLASSEX structure used to create the class for the CreateWindowEx() function call. As the documentation says, it is sent after the window has been created but before the CreateWindowex() function returns so you must use the Window handle from the stack parameter passed to the WndProc for the WM_CREATE.

Now if you want to test for some condition in the WM_CREATE processing with the option of closing the application, perform your test then use the documented method as is described in the old win32.hlp.

Return Values

If an application processes this message, it should return 0 to continue creation of the window. If the application returns -1, the window is destroyed and the CreateWindowEx or CreateWindow function returns a NULL handle.

You can also use
invoke SendMessage,hWin,WM_SYSCOMAND,SC_CLOSE,0

but using the return value from the WM_CREATE is a cleaner method.
Posted on 2004-11-22 09:54:11 by hutch--
:-D
Posted on 2004-11-22 10:36:01 by QvasiModo
well, when return -1, it runs well. i hope microsoft to correct this mistake.
Posted on 2004-11-22 17:40:09 by geegle