Sign in to follow this  

Windows Programming Question(s)

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Maybe i need to continue reading more, but it seems to me that all the programs i've done with windows so far, have just consisted of me initializing the windows in main, and writing the callback function, and the callback function gets pretty big with all the switch statements. My question is, is it normal to do all your work in the callback function, or is it better to break it down into functions, like one for handling the menu, one for handling mouse clicks etc... Also, other than cbSize, what is the difference between WINDOWCLASSEX and WINDOWCLASS, i read a few tutes that used WINDOWCLASS, but both books i've looked at use WINDOWCLASSEX. Is one better than the other? or is it just personaly preference?

Share this post


Link to post
Share on other sites
If your callback function is getting too big, I would definitely put events into separate functions, just for the convenience factor. As for WNDCLASS vs. WNDCLASSEX, there isn't much of a difference. WNDCLASSEX just has two extra properties: cbSize, which holds the size, and hIconSm, which specifies the icon that's displayed on the taskbar. This pretty much explains the differences.

Share this post


Link to post
Share on other sites
WNDCLASS and WNDCLASSEX

typedef struct _WNDCLASS {
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
};






typedef struct _WNDCLASSEX {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
HICON hIconSm;
};





As you can see, wndclassex (which is the one I prefer) is slightly larger.

EDIT: Beaten by 6 seconds

Share this post


Link to post
Share on other sites
It's not that they're getting too big, it's just chat i missed a break statement, in the menu handling case, so after it did one menu selection,k it fell through to the WM_DESTROY case, which of course posts the quit message, not the intended purpose, and it took me a while to find it. Also, i can see them getting big really fast, which is why i have started working with multiple files:)

Share this post


Link to post
Share on other sites
Quote:
Original post by Cor-Bob
It's not that they're getting too big, it's just chat i missed a break statement, in the menu handling case, so after it did one menu selection,k it fell through to the WM_DESTROY case, which of course posts the quit message, not the intended purpose, and it took me a while to find it. Also, i can see them getting big really fast, which is why i have started working with multiple files:)


You could try using if else instead of switch.Spliting it up into multiple funtions is a very good idea.

Share this post


Link to post
Share on other sites
Thanks for all the replies, i didn't think to look in the header(s) at the declarations of the structures. I guess for clarity's sake most books try to only use one file when demonstrating a new technique, and when it comes to windows programming it's expected that you're already familiar with the language.

Share this post


Link to post
Share on other sites
Another thing you might want to consider is the amount of processing you do in your window procedure. If you're going to be doing some heavy duty processing you should probably start a new thread and let it handle things. Otherwise you may prevent further messages from being delivered to your window procedure.

cheers
sam

Share this post


Link to post
Share on other sites
There's a thing called "separating interface and implementation". I do all my interface stuff (handling menus, button clicks, ...) in one big WndProc. With some helper functions, if neccesary (to prevent code copying). The interface is procedural programmed. Then I have an implementation. Usually highly objectect-oriented. When the interface processes the button click (gray something, or idontnowwhatever) it calls a function from interface.

Oxyd

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this