window handle

Started by
2 comments, last by cleves 20 years, 8 months ago
Hey all, I have window A.i want to create a button in that window, so i use the function CreateWindowEx(NULL, // extended style "button", // class "Push Me", // text on button WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 10,10, // initial x,y 100,24, // initial width, height main_window_handle, // handle to parent (HMENU)(100), // id of button, notice cast to HMENU hinstance, // instance of this application NULL); // extra creation parms everything is ok except that i need the handle of window A,how can i get it? Thanks in advance.
Advertisement
If you have ''A'' then you don''t need ''A''?! In the create function where you have main_window_handle, this is the parent window which is where you would put ''A''.

Incidentally, window ''A'' will be returned from a previous CreateWindowEx call, or some other function for getting window handles (like FindWindow or something).


"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
Some pseude code to illustrate what JY said:

main_window_handle = CreateWindowEx(...''main window''...);

button_handle = CreateWindowEx(...''button''...);

You should always store the return values of the CreateWindowEx function... how else do you problerly free the resource via DestroyWindow(handle) ???
How do I set my laser printer on stun?
quote:Original post by Wildfire
how else do you problerly free the resource via DestroyWindow(handle) ???

that''s done via the window''s msg proc, which has an HWND passed to it. for normal Windows apps, i rarely have a need to store an HWND except for convenience. i always check the return value for validity though.

This topic is closed to new replies.

Advertisement