Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Create the CWnd

Create the CWnd

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TrungHuynh
    wrote on last edited by
    #1

    Hello I have a class derived form CWnd class CTitle: public CWnd { public: BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext*pContext) { BOOL bResult = CWnd::CreateEx (0 ,CBMSTITLEBAR_CLASSNAME, lpszWindowName, dwStyle,rect, pParentWnd, nID, pContext); return bResult; } //CBMSTITLEBAR_CLASSNAME class name i have alredy // registered yet by call AfxRegisterClass // it' ok BOOL Init(); }; //in the init function i create CTitle BOOL CTitle:: Init() { if(Create(pszTitle,WS_VISIBLE | WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, rcSubstitute, m_pParentWnd, 0)) return TRUE; else return FALSE; } I'm sure that the m_pParentWnd, pzTitle, rcSubstitue are correct: because it run as well But in the init function, i call create with last parameter : 0 (ID of window) it runs ok, but i change it to another values, the Create fucntion is false. Any one could help me ? what is the reason Thanks so much.

    M D 2 Replies Last reply
    0
    • T TrungHuynh

      Hello I have a class derived form CWnd class CTitle: public CWnd { public: BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext*pContext) { BOOL bResult = CWnd::CreateEx (0 ,CBMSTITLEBAR_CLASSNAME, lpszWindowName, dwStyle,rect, pParentWnd, nID, pContext); return bResult; } //CBMSTITLEBAR_CLASSNAME class name i have alredy // registered yet by call AfxRegisterClass // it' ok BOOL Init(); }; //in the init function i create CTitle BOOL CTitle:: Init() { if(Create(pszTitle,WS_VISIBLE | WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, rcSubstitute, m_pParentWnd, 0)) return TRUE; else return FALSE; } I'm sure that the m_pParentWnd, pzTitle, rcSubstitue are correct: because it run as well But in the init function, i call create with last parameter : 0 (ID of window) it runs ok, but i change it to another values, the Create fucntion is false. Any one could help me ? what is the reason Thanks so much.

      M Offline
      M Offline
      Maarten Kools
      wrote on last edited by
      #2

      You might want to check out the return value of GetLastError when the call fails. Perhaps that will give you some extra info.

      1 Reply Last reply
      0
      • T TrungHuynh

        Hello I have a class derived form CWnd class CTitle: public CWnd { public: BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext*pContext) { BOOL bResult = CWnd::CreateEx (0 ,CBMSTITLEBAR_CLASSNAME, lpszWindowName, dwStyle,rect, pParentWnd, nID, pContext); return bResult; } //CBMSTITLEBAR_CLASSNAME class name i have alredy // registered yet by call AfxRegisterClass // it' ok BOOL Init(); }; //in the init function i create CTitle BOOL CTitle:: Init() { if(Create(pszTitle,WS_VISIBLE | WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, rcSubstitute, m_pParentWnd, 0)) return TRUE; else return FALSE; } I'm sure that the m_pParentWnd, pzTitle, rcSubstitue are correct: because it run as well But in the init function, i call create with last parameter : 0 (ID of window) it runs ok, but i change it to another values, the Create fucntion is false. Any one could help me ? what is the reason Thanks so much.

        D Offline
        D Offline
        Diddy
        wrote on last edited by
        #3

        The last parameter (the ID) is also used as the menu handler for the window. If that value is non-NULL, the system will attempt to load the menu given in nID and attach it to the window. If you step into Create until you get here: // allow modification of several common create parameters AfxHookWindowCreate(this); HWND hWnd = ::CreateWindowEx(cs.dwExStyle, cs.lpszClass, cs.lpszName, cs.style, cs.x, cs.y, cs.cx, cs.cy, cs.hwndParent, cs.hMenu, cs.hInstance, cs.lpCreateParams); #ifdef _DEBUG if (hWnd == NULL) { TRACE1("Warning: Window creation failed: GetLastError returns 0x%8.8X\n", GetLastError()); } #endif You will see if you put a watch on "@ERR" GetLastError returns 1401, "@ERR,hr" will then show you that maps to "Invaid Menu Handle"

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups