Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8638935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:52:04+00:00 2026-06-12T10:52:04+00:00

My win32 program has become a little to large to keep in one main

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:52:05+00:00Added an answer on June 12, 2026 at 10:52 am

    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
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing C++ win32 console app. This application contains a main program
I'm debugging my C++ Win32 program in VS2010 and I always get Windows has
I have been trying to add a .cu file into my own(dll) win32 project
I have a Win32 C++ program that validates user input and updates the UI
The following C++ Win32 console program assigns an array to a pointer to void,
When I compile and run a simple Win32 GUI program in MinGW+MSys with command
On Win32, how can a C++ program determine how many threads are active in
In order to try out how to program with the Win32 API, I wrote
Using Visual Studio 2008, I created a C++ Win32 project. To release the program,
Okay, so at first when i run my win32 program the menu works fine,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.