Check for window registration

Started by
6 comments, last by Colin Jeanne 17 years, 6 months ago
Once I have registered a window by using: if(!RegisterClassEx(&Host)) { MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); } how can I go about checking ot see if it has registered?
Advertisement
Well, if it goes the the "else" part of the if, then it has registerd (so if RegisterClassEx has returned non-zero).

You could do a GetClassInfo to retrieve, it, but it isn't neccesary.
What, exactly, do you believe the provided code to be doing?

CM
I thought the code I provided was registering the window? Is that not correct?

Quote:Original post by CTEagle
I thought the code I provided was registering the window? Is that not correct?

It is registering the window, and checking to make sure it was registered. How else could it possibly tell you that the registration failed?

CM
I think that I have failed to state my request clearly in my original post.

After my window has been registered, I want to be able to check to see if it has been registered from somewhere else in my code. I cannot use the same code as what I provided in my original post because the application will attempt to register the window again and of course I get a message stating that the registration failed.
As far as I know, Windows isn't in the habit of unregistering classes without warning, so you could get away with storing the return value and checking it as your leisure:
ATOM registered_state = RegisterClassEx(&Host);// Then at any point laterif (registered_state) {    // Window was successfully registered} else {    // Window was not successfully registered}
You are free to check the value of registered_state as many times as you like.

Regards
Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
I believe you're looking for GetClassInfoEx(). If your class is registered then this function will succeed.

This topic is closed to new replies.

Advertisement