Create the CWnd
-
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.
-
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.
You might want to check out the return value of GetLastError when the call fails. Perhaps that will give you some extra info.
-
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.
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"