Note that there are some explanatory texts on larger screens.

plurals
  1. POManual alternative to message map?
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>I found a code sample that allows me to add controls manually (exerpts below):</p> <pre><code>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); }; </code></pre> <p>.cpp file:</p> <pre><code>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 -&gt; Create("&amp;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-&gt;ShowWindow(m_nCmdShow); m_pMainWnd-&gt;UpdateWindow(); return TRUE; } </code></pre> <p>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.</p> <p>The only solution I've been able to find looks like this:</p> <pre><code>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(&amp;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(&amp;Msg, NULL, 0, 0) ) { TranslateMessage(&amp;Msg); DispatchMessage(&amp;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; } </code></pre> <p>Which is great, except.. I don't have a WinMain...</p> <p>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.</p> <p>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...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload