# re-title window with win32 api

This topic is 4689 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey, I'm using the win32 API, and I need to re-title a window at runtime, after registering it. I tried doing this with RegisterClassEx - whoops! it did it too many times and crashed the computer. How do I do this safely? Thanks.

##### Share on other sites
SetWindowText [smile]

##### Share on other sites
how about this then: what if I wanted to send a CALLBACK function a reference to an HWND, like one stored in a class, rather than one sent, I guess, by Windows.

For example, say I had a "Window" class, part of which was an HWND for the window. Say its CALLBACK function was called WndProc. If it looked like this:

WindowClass myWindowClass; //Part of this is an HWND called "window"LRESULT CALLBACK WndProc( HWND hwnd, //etc){    //How would I get hwnd, above to be a reference to myWindowClass.window??}

well, what Im asking is probably clear by now. If not, then i = teh stupid and tell me, so I can clarify. Thanks!

##### Share on other sites
SetWindowLong I believe [wink] Oh, not sure if that will work in your example though, but give it a try.

##### Share on other sites
Nargle. I'm not sure if thats what I want. What I mean is if I did something like changing the title of myWindowClass within WndProc, it would change the title of hwnd. Thanks.

##### Share on other sites
Quote:
 Original post by silverphyre673What I mean is if I did something like changing the title of myWindowClass within WndProc, it would change the title of hwnd. Thanks.

I'm not sure what you are trying to do - if you have a HWND, you should be able to change the title with the SetWindowText function. Can you explain some more please.

##### Share on other sites
oh, sorry. Its not a question specifically about changing the title anymore (sorry, maybe it should have gone in a new thread). Its just that I'm making this framework for the win32 api, and one of the classes is a Window class (usage is the obvious one). Now, each Window has an HWND and WNDCLASSEX stored in it, and the WNDCLASSEX stores the CALLBACK that is called when the HWND is in focus. But CALLBACK functions have the HWND that they are running for as one of their arguments. I wanted to know how to affect the HWND in the argument by changing the HWND in the Window class that the CALLBACK is being called on.

Does that clear things up at all?

##### Share on other sites
Quote:
 Original post by silverphyre673...I wanted to know how to affect the HWND in the argument by changing the HWND in the Window class that the CALLBACK is being called on.Does that clear things up at all?

Like mud. You are trying to change which window responds whenever you get a WM_SETFOCUS event? Sounds like a nightmare.

Here's another example framework for you to get some ideas from. Maybe that will answer your questions.

http://www.randommonkeyworks.com/newsite/programming/computer/DWinLib/DWinLib.shtml

David

##### Share on other sites
Quote:
 Original post by silverphyre673:I wanted to know how to affect the HWND in the argument by changing the HWND in the Window class that the CALLBACK is being called on.Does that clear things up at all?

Err, not really, in fact I think it probably makes them less clear. However, I think I can hazard a guess at what you're after.

Use SetWindowLong with the GWL_USERDATA parameter to pass a pointer to the WindowClass object it's associated with. You can then use GetWindowLong in your message handler to retrieve it.

WindowClass::WindowClass(){   // create the window   hWnd mWindowHandle = CreateWindowEx(blah blah blah);   // use set window long to associate this window with this object.   SetWindowLong(mWindowHandle,GWL_USERDATA,(LONG)this);}LRESULT CALLBACK WindowClassMessageHandlerProc(HWND blah blah blah){    WindowClass* pWindowClass = (WindowClass*)GetWindowLong(hWnd,GWL_USERDATA);     // handle messages here, but be wary - if the message arrives between   // the call to CreateWindowEx and SetWindowLong, pWindowClass will be null.   // in other words - CHECK IT BEFORE YOU DEREFERENCE IT}

If that's not what you're after, I think you might have to try and explain it again, a little more clearly.