Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem creating an MDI interface

Status
Not open for further replies.

PAK9

Programmer
Jun 23, 2005
1
0
0
GB
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:
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;
}
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:
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;
}
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.
 
MDI is a MFC concept. Making your own would be quite painful. Use MFC.

/Per
[sub]
www.perfnurt.se[/sub]
 
You may wish to invest in "Programming Windows, 5th Edition" by Charles Petzold. Also, Dev-C++ comes with an MDI example if I remember correctly.
 
Strictly speaking, MDI is not a MFC concept. It's an interface style (or even standard de facto) - it's IBM invention.
Now MS declares MDI as obsolete.
 
There used to be examples of MDI programs in the M$ C++ compiler examples directory.

The one that springs to mind is an MDI version of notepad.

And they were all in C...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top