Hi there
Sorry if this is a lot of text, I've tried to just post the relevant stuff
I am tying to create an MDI interface in C++ but I'm not using MFC or any other libraries I'm just using API calls. Basically something is going wrong because my call to CreateWindow to make the frame window returns 0. Allow me to paste some of the relevant code:
So thats where it fails and I cant for the life of me figure out why. I might as well post my MDI Frame window proc too:
I dont know if this is relevant too but if I change "return DefFrameProc(..." to "return return DefWindowProc(..." it will create the window fine, but of course I need to use DefFrameProc because its an MDI frame.
Any help would be much appreciated, if there is any other parts of the code you need to see please ask.
Sorry if this is a lot of text, I've tried to just post the relevant stuff
I am tying to create an MDI interface in C++ but I'm not using MFC or any other libraries I'm just using API calls. Basically something is going wrong because my call to CreateWindow to make the frame window returns 0. Allow me to paste some of the relevant code:
Code:
//First this function is called to register the windows
inline bool WinObject::RegisterWindows(WNDPROC FrameProc, WNDPROC ChildProc)
{
WNDCLASSEX Win;
Win.cbSize = sizeof(WNDCLASSEX);
Win.style = CS_HREDRAW | CS_VREDRAW;
Win.lpfnWndProc = FrameProc;
Win.cbClsExtra = 0;
Win.cbWndExtra = 0;
Win.hInstance = hInstance;
Win.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_MSCYOUNG);
Win.hCursor = LoadCursor(NULL, IDC_ARROW);
Win.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
Win.lpszMenuName = (LPCTSTR)IDC_MSCYOUNG;
Win.lpszClassName = FrameClass;
Win.hIconSm = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL);
if(RegisterClassEx(&Win)==0) return FALSE;
Win.lpfnWndProc = ChildProc;
Win.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_CHILDICON);
Win.hIconSm = LoadIcon(hInstance, (LPCTSTR)IDI_CHILDICON);
Win.lpszMenuName = (LPCTSTR) NULL;
Win.cbWndExtra = 0;
Win.lpszClassName = ChildClass;
if(RegisterClassEx(&Win)==0) return FALSE;
return TRUE;
}
//Then this function is called to create the frame window
inline HWND WinObject::CreateMainWin()
{
HWND MainWin;
MainWin = CreateWindow( // This call to CreateWindow returns 0
FrameClass,
AppTitleEX,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
DWORD Oops = GetLastError(); // This gives error code 1400 (ERROR_INVALID_WINDOW_HANDLE)
return MainWin;
}
Code:
LRESULT CALLBACK MDIProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
switch (message)
{
case WM_CREATE:
CLIENTCREATESTRUCT ccs;
ccs.hWindowMenu = GetSubMenu(GetMenu(FrameHwnd), WINDOWMENU);
ccs.idFirstChild = MDI_CHILD;
ClientHwnd = CreateWindow("MDICLIENT"
,NULL
,WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL
,0,0,0,0
,FrameHwnd
,NULL
,hInstance
,&ccs);
ShowWindow(ClientHwnd,SW_SHOW);
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
<lots of stuff here that isnt important>
default:
return DefFrameProc(hWnd, ClientHwnd, WM_COMMAND, wParam, lParam);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefFrameProc(hWnd, ClientHwnd, WM_COMMAND, wParam, lParam);
}
return 0;
}
Any help would be much appreciated, if there is any other parts of the code you need to see please ask.