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

  • Home
  • SEARCH
  • 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 625357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:18:02+00:00 2026-05-13T19:18:02+00:00

I am trying to create a GUI to display information read from a file.

  • 0

I am trying to create a GUI to display information read from a file. So I will need some number of pushbuttons, text fields, and radio buttons – but I won’t know how many I need until run-time.

I am using Visual Studio 6.0. My toolset is fairly non-negotiable, so please refrain from suggesting Java, or any C++ toolkit that does not come pre-installed in Visual Studio. My problem is that most of the tutorials I have found online focus on using the WYSIWYG editor – which requires knowing what controls are needed up front.

I found a code sample that allows me to add controls manually (exerpts below):

class CalcApp : public CWinApp
{
    ...
};

class CWindow : public CFrameWnd
{ 
    ...

    afx_msg void HandleButton2();
    afx_msg HBRUSH OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor );
    DECLARE_MESSAGE_MAP();
    virtual BOOL PreTranslateMessage(MSG* msg);
};

.cpp file:

BEGIN_MESSAGE_MAP( CWindow, CFrameWnd )

    ON_BN_CLICKED(IDC_BUTTON1, HandleButton1)
    ON_BN_CLICKED(IDC_BUTTON2, HandleButton2)

END_MESSAGE_MAP()

CWindow::CWindow()
{ 
    Create(NULL, "Title", 
            WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU, 
            CRect(CPoint(50,50),CSize(180,300))); 

    ...

    button2 = new CButton();
    button2 -> Create("&Quit",
            WS_CHILD|WS_VISIBLE|WS_TABSTOP,
            CRect(CPoint(2,202),CSize(152,38)),
            this, IDC_BUTTON2);
    }

    void CWindow::HandleButton2()
    {
        DestroyWindow ();
    }

    BOOL CalcApp::InitInstance()
    {
        m_pMainWnd = new CWindow();
        m_pMainWnd->ShowWindow(m_nCmdShow);
        m_pMainWnd->UpdateWindow();
        return TRUE;
    }

What I’m having trouble figuring out is how to handle the message processing without using the BEGIN_MESSAGE_MAP(), etc macros – which, again, require knowing how many handlers you need up front.

The only solution I’ve been able to find looks like this:

LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow)
{
    ...
    WndClsEx.lpfnWndProc   = WndProc;

    RegisterClassEx(&WndClsEx);

    hWnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,
                      ClsName,
                      WindowCaption,
                      WS_OVERLAPPEDWINDOW,
                      100,
                      120,
                      640,
                      480,
                      NULL,
                      NULL,
                      hInstance,
                      NULL);

    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);

    while( GetMessage(&Msg, NULL, 0, 0) )
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    return Msg.wParam;
}
//---------------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
    switch(Msg)
    {
    case WM_DESTROY:
        PostQuitMessage(WM_QUIT);
        break;
    default:
        return DefWindowProc(hWnd, Msg, wParam, lParam);
    }
    return 0;
}

Which is great, except.. I don’t have a WinMain…

My understanding is that you can either do a “Win32” application (the WinMain code above) or an “MFC” application (the CButton code above). But I can only find examples of manually adding controls for MFC, and I can only find examples of manually processing messages for Win32.

Can you point me to one of the things I’m missing here? Ideally, I want a solution for handling my own messages with MFC, but I’d settle for a good tutorial on creating controls with Win32…

  • 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-13T19:18:02+00:00Added an answer on May 13, 2026 at 7:18 pm

    Once upon a time I did something like this. I allocated a rage of control ids (not used in resource.h). Added controls with these ids dynamically to the page.

    To handle the event I took over the OnCommand on the Windows and listened for controls with ids in the range I was looking for.

    (I need to search old code to be more specific)

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

Sidebar

Related Questions

I am trying to create a GUI using java swing. From there I have
Hello I am trying to create an ASyncTask that will parse data from an
I'm trying to create a GUI Python app using Py2App, but am having trouble
I'm trying to create a GUI using Java by hand-coding it (without using GUI
I am trying to create my first GUI application using (Java + Eclipse +
I am trying to create this QT gui using a thread but no luck.
I am trying to create a simple GUI form which has only 2 elements
I'm trying to create a responsive gui, which basically means that I have an
I begin in GUI with Tkinter with Python. I'm trying to create a graphical
I'm trying, for the first time, to create a GUI in Ruby using Tk.

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.