locked
Take a look at my subclassing code... RRS feed

  • Question

  • I'm doing things the old style for reasons beyond the scope of this question.

    HWND hwndChild;

    WNDPROC wpMyChildWndProc; // Subclass procedure LRESULT APIENTRY MyChildWndSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { return CallWindowProc(wpMyChildWndProc, hWnd, uMsg, wParam, lParam); } LRESULT APIENTRY MyChildWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_MDICREATE: // create child window hwndChild = CreateWindowExA( WS_EX_MDICHILD, _T("CChildFrame"), // name of window class _T("Test"), // title-bar string WS_CHILD | WS_VISIBLE, //| WS_VSCROLL | MDIS_ALLCHILDSTYLES | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, // mdi child window styles 0, // default horizontal position 0, // default vertical position 0, // default width 0, // default height (HWND) hwndMain, // owner window (HMENU) NULL, // use class menu (HINSTANCE) hInst, // handle to application instance (LPVOID) &wndChild); // window-creation data if (!hwndChild) { AfxMessageBox(_T("Failed to create MDI child window.")); return -1; } // Subclass the edit control. wpMyChildWndProc = (WNDPROC) SetWindowLong(hwndChild, GWL_WNDPROC, (LONG) MyChildWndSubclassProc); // // Continue the initialization procedure. // ShowWindow(hwndChild, SW_SHOW); UpdateWindow(hwndChild); return 0; case WM_COMMAND: // Test for the identifier of a command item. switch(LOWORD(wParam)) { case ID_FILE_NEW: theApp.OnFileNew(); // application-defined //case IDM_FI_CLOSE: // DoFileClose(); // application-defined //break; // Process other menu commands. } return 0; case WM_DESTROY: // Remove the subclass from the edit control. SetWindowLong(hwndChild, GWL_WNDPROC, (LONG) wpMyChildWndProc); // // Continue the cleanup procedure. // return 0; default: return DefMDIChildProcA(hwndChild, uMsg, wParam, lParam); } return 0; UNREFERENCED_PARAMETER(lParam); }

    This code generates no response in my GUI and all I'm trying to do is determine the pipeline for a "File > New" menu command.

    It all gets started with a line of code in my initialization of the mdi child attributes...

    	wndChild.lpfnWndProc = (WNDPROC) wpMyChildWndProc,

    Thanks for your time.


    PAC


    • Edited by PACMAN_1 Sunday, April 15, 2012 11:26 AM
    Sunday, April 15, 2012 11:23 AM

Answers

  • The posted source code has too many flaws to be corrected in this post.  I've abandoned this approach of subclassing altogether, because I don't need to add features to my existing class the old school way.  This deviation from my progressive programming helped me gain more insight into the evolution of MFC. 

    PAC


    • Marked as answer by PACMAN_1 Saturday, May 5, 2012 6:05 AM
    • Edited by PACMAN_1 Saturday, May 5, 2012 6:26 AM
    Saturday, May 5, 2012 6:04 AM

All replies

  • Where did you define wpMyChildWndProc;?

    NEU_ShieldEdge

    Monday, April 16, 2012 6:50 AM
  • Hello Luke,  The code snippet above is a modified version of one I found in the MSDN Library.  wpMyChildWndProc (the wp stands for WNDPROC) is defined in the second statement above as a "data variable" according to the compiler, but I thought it seemed more like a function pointer.  I thought it was just a placeholder to make the whole subclassing system work with the CallWindowProc(...) mechanism.  So there is no function definition for wpMyChildWndProc.  Thanks.


    PAC

    Monday, April 16, 2012 10:55 AM
  • The posted source code has too many flaws to be corrected in this post.  I've abandoned this approach of subclassing altogether, because I don't need to add features to my existing class the old school way.  This deviation from my progressive programming helped me gain more insight into the evolution of MFC. 

    PAC


    • Marked as answer by PACMAN_1 Saturday, May 5, 2012 6:05 AM
    • Edited by PACMAN_1 Saturday, May 5, 2012 6:26 AM
    Saturday, May 5, 2012 6:04 AM