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 714341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:03:51+00:00 2026-05-14T05:03:51+00:00

I wish to improve my code and file structure in larger Win32 projects with

  • 0

I wish to improve my code and file structure in larger Win32 projects with plenty of windows and controls. Currently, I tend to have one header and one source file for the entire implementation of a window or dialog. This works fine for small projects, but now it has come to the point where these implementations are starting to reach 1000-2000 lines, which is tedious to browse.

A typical source file of mine looks like this:

static LRESULT CALLBACK on_create(const HWND hwnd, WPARAM wp, LPARAM lp) {
    setup_menu(hwnd);
    setup_list(hwnd);
    setup_context_menu(hwnd);

    /* clip */

    return 0;
}

static LRESULT CALLBACK on_notify(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
    const NMHDR* header = (const NMHDR*)lp;

    /* At this point I feel that the control's event handlers doesn't
     * necessarily belong in the same source file. Perhaps I could move
     * each control's creation code and event handlers into a separate
     * source file? Good practice or cause of confusion? */

    switch (header->idFrom) {
    case IDC_WINDOW_LIST:
        switch (header->code) {
        case NM_RCLICK:
            return on_window_list_right_click(hwnd, wp, lp);

        /* clip */
        }
    }
}

static LRESULT CALLBACK wndmain_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
    switch (msg) {
    case WM_CREATE:
        return on_create(hwnd, wp, lp);

    case WM_CLOSE:
        return on_close(hwnd, wp, lp);

    case WM_NOTIFY:
        return on_notify(hwnd, wp, lp);

    /* It doesn't matter much how the window proc looks as it just forwards
     * events to the appropriate handler. */

    /* clip */

    default:
        return DefWindowProc(hwnd, msg, wp, lp);
    }
}

But now as the window has a lot more controls, and these controls in turn have their own message handlers, and then there’s the menu click handlers, and so on… I’m getting lost, and I really need advice on how to structure this mess up in a good and sensible way.

I have tried to find good open source examples of structuring Win32 code, but I just get more confused since there are hundreds of files, and within each of these files that seem GUI related, the Win32 GUI code seems so far encapsulated away. And when I finally find a CreateWindowEx statement, the window proc is nowhere to be found.

Any advice on how to structure all the code while remaining sane would be greatly appreciated.

Thanks!

I don’t wish to use any libraries or frameworks as I find the Win32 API interesting and valuable for learning.

Any insight into how you structure your own GUI code could perhaps serve as inspiration.

  • 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-05-14T05:03:51+00:00Added an answer on May 14, 2026 at 5:03 am

    For starters, I’d take a look at the message crackers in windowsx.h; they’ll save you writing tedious case statements in your window procedures, and they suggest a certain discipline in function names.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.