Reputation: 20076
My win32 program has become a little to large to keep in one main file. My plan is to split the code into three files, a main file for the procs, a file to handle files and a file to handle fonts. I'm having trouble splitting the file though, i dont know how i should include them in order for them to act as one main file. For example some of my main:
#include <iostream>
#include <windows.h>
#include "resource.h"
#include <commctrl.h>
#include "hideconsole.h"
#define IDC_MAIN_MDI 101
#define IDC_MAIN_TOOL 102
#define IDC_MAIN_STATUS 103
#define IDC_CHILD_EDIT 101
#define ID_MDI_FIRSTCHILD 50000
const char szClassName[] = "MainClass"; //window class
const char szChildClassName[] = "ChildClass"; //child class
HWND g_hMDIClient = NULL;
HWND g_hMainWindow = NULL;
//functions and procs for windows
how should i separate these files? i tried before but i couldnt wrap my head around getting all of the files to have access to mains variables. Could anyone give me some pointers? thanks!
Upvotes: 3
Views: 425
Reputation: 28302
For the global variables (non-constants) you should put in a header file:
extern HWND g_hMDIClient = NULL;
extern HWND g_hMainWindow = NULL;
You will leave the non-extern version in your main cpp file (it can be in any file but you might as well not move them). Simply move the constants and macros into the header file, the compiler can figure them out on it's own. Finally, include this header file in all your cpp files.
For functions you need the declarations in the header files and the definitions in the code files.
Header file:
void myFunc();
Code file:
void myFunc()
{
// Do something
}
Upvotes: 1