Re: In the need for some advice!

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Robby wrote:

Hi,

I am a beginer in VC++ and have discovered how to use child windows and assigning the child window's required logic to a CALLBACK childWndProc function as so:

LRESULT CALLBACK CW1_WndProc (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam) {

//All code required for child window, ex: buttons, display of text and so forth....

}

However, I created a header file where this ChildWndProc function resides. And so, I have included the ChildWndProc at the top of my main application file with the following line:

#include "CW1_WndProc.h" //Child Window proc 1

The problem is that my ChildWndProc CALLBACK function is approximately 500 lines.
Now, for my next child window, should I create a new header file for my second ChildWndProc or should I create it in the same header file as the first one.

My dilema is if I would create all my CALLBACKS in the same header file, in the event where I would need 20 child windows, well, this file would be huge!

On the other hand if I create a seperate header file for every CALLBACK function, and in the event where I would need 20 child windows, well, I would have a large number of header files, which can be combersome!

Can someone advise me the correct way of going about this.

All suggestions are appreciated!
Thankyou!


Robby:

I never really coded in C, but it seems to me the "C++ way" described by Simon is optimal there also. Some reasons:

1. The reason you want to split things into different files is because otherwise if you change anything the whole project has to be recompiled. For a big project this can be very time consuming, not to mention that a huge file is very cumbersome to work with.

2. One of the reasons to use headers is so that you can include the same stuff in different implementation files (translation units). Therefore you do not want to put function definitions in the header, or they will be multiply-defined. C++ has a mechanism (the inline keyword) for avoiding this "one-definition rule", but traditional C does not.

3. Therefore, just put the function prototypes in a header (or headers), and put the definitions in one or more implementation files. In fact a ..h/.c pair for each WndProc sounds good to me. Include each .h file in its corresponding .c file and in your main.c file. This scheme will minimize your compile time.

4. Having many small files is no problem, because the VC IDE is very good at keeping them organized for you.

David Wilkinson
.


Quantcast