Regarding MDI windows...

Started by
1 comment, last by Xtremehobo 20 years ago
How come the client window in my MDI window setup doesn''t have an "active" colored titlebar? the code:

// DMX.cpp : Defines the entry point for the application.

//


#include "stdafx.h"
#include "resource.h"

#define MAX_LOADSTRING 100

// Global Variables:

HINSTANCE hInst;								// current instance

HWND hwndChannels;

// Foward declarations of functions included in this code module:

ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK	ChannelsProc(HWND hwnd, UINT Message, WPARAM wParam,LPARAM lParam);

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	// TODO: Place code here.

	MSG msg;
	HACCEL hAccelTable;

	MyRegisterClass(hInstance);

	// Perform application initialization:

	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_DMX);

	// Main message loop:

	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateMDISysAccel(msg.hwnd, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return msg.wParam;
}



//

//  FUNCTION: MyRegisterClass()

//

//  PURPOSE: Registers the window class.

//

//  COMMENTS:

//

//    This function and its usage is only necessary if you want this code

//    to be compatible with Win32 systems prior to the ''RegisterClassEx''

//    function that was added to Windows 95. It is important to call this function

//    so that the application will get ''well formed'' small icons associated

//    with it.

//

ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;
	ATOM rtn;

	wcex.cbSize = sizeof(WNDCLASSEX); 

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_DMX);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground   = (HBRUSH)CreateSolidBrush(RGB(90,92,100));//(COLOR_3DSHADOW+1);

	wcex.lpszMenuName	= (LPCSTR)IDC_DMX;
	wcex.lpszClassName	= "DMX";
	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

	rtn = RegisterClassEx(&wcex);

	wcex.lpfnWndProc     = (WNDPROC)ChannelsProc;
    wcex.lpszMenuName	   = NULL;
    wcex.lpszClassName   = "DMX_CHANNELS";
    wcex.hbrBackground   = (HBRUSH)(COLOR_3DFACE+1);

	rtn = RegisterClassEx(&wcex);

	return rtn;
 
}

//

//   FUNCTION: InitInstance(HANDLE, int)

//

//   PURPOSE: Saves instance handle and creates main window

//

//   COMMENTS:

//

//        In this function, we save the instance handle in a global variable and

//        create and display the main program window.

//

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable


   hWnd = CreateWindow("DMX", "Proscenium", WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//

//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)

//

//  PURPOSE:  Processes messages for the main window.

//

//  WM_COMMAND	- process the application menu

//  WM_PAINT	- Paint the main window

//  WM_DESTROY	- post a quit message and return

//

//

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;

	switch (message) 
	{

		case WM_CREATE:
		   hwndChannels = CreateWindow("DMX_CHANNELS", "Proscenium", WS_OVERLAPPEDWINDOW | WS_CHILD | WS_CLIPCHILDREN,
      10, 10, 450, 350, hWnd, NULL, hInst, NULL);
		   ShowWindow(hwndChannels,true);
		   UpdateWindow(hwndChannels);
		break;

		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			// Parse the menu selections:

			switch (wmId)
			{
				case IDM_EXIT:
				   DestroyWindow(hWnd);
				   break;
				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		case WM_PAINT:
			UpdateWindow(hwndChannels);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

LRESULT CALLBACK ChannelsProc(HWND hwnd, UINT Message, WPARAM wParam,
   LPARAM lParam)
{
   switch(Message)
   {
      // handle normal stuff...WM_CREATE etc...



      case WM_COMMAND:
         switch(LOWORD(wParam))
         {
            //handle various commands...

         }
      return 0;
   }
   return DefMDIChildProc(hwnd, Message, wParam, lParam);
}
I can only imagine this is a somewhat-common problem because I''m doing everything that a tutorial is telling me to do and I must be stupidly missing something very obvious here :-\ Thanks Regards, Matt Carpenter
pixelwrench.com | [email="matt[nospam]@pixelwrench[nospam]com"]email[/email] lethalhamster: gamedev keeps taking my money, but im too lazy to not let them
Advertisement
You''re creating your child window incorrectly. With MDI, to create a child window you have to send a WM_MDICREATE message to the MDI Client window.

Also the MDI frame window uses DefFrameProc() not DefWindowProc()

The better explaination

Thanks Salsa!Colin Jeanne | Invader''s Realm
"I forgot I had the Scroll Lock key until a few weeks ago when some asshole program used it. It even used it right" - Conner McCloud
ahh thanks, got it working
pixelwrench.com | [email="matt[nospam]@pixelwrench[nospam]com"]email[/email] lethalhamster: gamedev keeps taking my money, but im too lazy to not let them

This topic is closed to new replies.

Advertisement