Archived

This topic is now archived and is closed to further replies.

cleves

window handle

Recommended Posts

cleves    148
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.

Share this post


Link to post
Share on other sites
JY    289
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

Share this post


Link to post
Share on other sites
Wildfire    154
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) ???

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites