C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 23rd, 2005, 06:08 PM
PAK-9 PAK-9 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 1 PAK-9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 9 sec
Reputation Power: 0
Problem creating an MDI interface

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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Problem creating an MDI interface


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT