mdi-problem
-
moin,
kann mir jemand sagen was hier falsch ist?
[code]
#include <windows.h>
#include "resource.h"LRESULT CALLBACK FrameWndProc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK CloseEnumProc(HWND, LPARAM);
LRESULT CALLBACK Client01Proc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Client02Proc(HWND, UINT, WPARAM, LPARAM);char chAppClass[128] = "MDI-Test";
char chClient01Class[128] = "Client01";
char chClient02Class[128] = "Client02";
HINSTANCE g_hinst;
HMENU g_hMenu, g_hMenuWindow;#define INIT_MENU 0
#define IDM_FIRSTCHILD 50000
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hwndFrame, hwndClient;
MSG msg;
WNDCLASS wndclass;
HACCEL hAccel;g_hinst = hInstance;
// Fensterklasse für Rahmenfenster
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = FrameWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = chAppClass;
RegisterClass(&wndclass);// Fensterklasse für Child01
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = Client01Proc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = sizeof(HANDLE);
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = chClient01Class;
RegisterClass(&wndclass);// Fensterklasse für Child02
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = Client02Proc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = sizeof(HANDLE);
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = chClient02Class;
RegisterClass(&wndclass);// menü laden
g_hMenu = LoadMenu(hInstance, "IDR_MENU1");
g_hMenuWindow = GetSubMenu(g_hMenu, INIT_MENU);
hAccel = LoadAccelerators(hInstance, "mditest");// Ramhmenfenster erstellen
hwndFrame = CreateWindow(chAppClass, "mditest",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, g_hMenu, hInstance, NULL);hwndClient = GetWindow(hwndFrame, GW_CHILD);
ShowWindow(hwndFrame, nCmdShow);
UpdateWindow(hwndFrame);while(GetMessage(&msg, NULL, 0, 0))
{
if(!TranslateMDISysAccel(hwndClient, &msg) && !TranslateAccelerator(hwndFrame, hAccel, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}return msg.wParam;
}LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndClient;
CLIENTCREATESTRUCT clientcreate;
HWND hwndChild;
MDICREATESTRUCT mdicreate;switch(message)
{
case WM_CREATE:clientcreate.hWindowMenu = g_hMenuWindow;
clientcreate.idFirstChild = IDM_FIRSTCHILD;hwndClient = CreateWindow("MDICLIENT", NULL,
WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
0, 0, 0, 0, hwnd, (HMENU) 1, g_hinst,
(PSTR) &clientcreate);return 0;
case WM_COMMAND:switch(LOWORD (wParam))
{
// neues childfenster vom typ01
case ID_DATEI_NEUESCHILD01:mdicreate.szClass = chClient01Class;
mdicreate.szTitle = "Client01";
mdicreate.hOwner = g_hinst;
mdicreate.x = CW_USEDEFAULT;
mdicreate.y = CW_USEDEFAULT;
mdicreate.cx = CW_USEDEFAULT;
mdicreate.cy = CW_USEDEFAULT;
mdicreate.style = 0;
mdicreate.lParam = 0;hwndChild = (HWND) SendMessage (hwndClient, WM_MDICREATE, 0,
(LPARAM) (LPMDICREATESTRUCT) &mdicreate);return 0;
// neues childfenster vom typ02
case ID_DATEI_NEUESCHILD02:mdicreate.szClass = chClient02Class;
mdicreate.szTitle = "Client02";
mdicreate.hOwner = g_hinst;
mdicreate.x = CW_USEDEFAULT;
mdicreate.y = CW_USEDEFAULT;
mdicreate.cx = CW_USEDEFAULT;
mdicreate.cy = CW_USEDEFAULT;
mdicreate.style = 0;
mdicreate.lParam = 0;hwndChild = (HWND) SendMessage (hwndClient, WM_MDICREATE, 0,
(LPARAM) (LPMDICREATESTRUCT) &mdicreate);return 0;
// programm beenden
case ID_DATEI_BEENDEN:
SendMessage(hwnd, WM_CLOSE, 0, 0);
break;// aktives fenster schließen
case ID_FENSTER_AKTUELLESSCHLIEEN:
hwndChild = (HWND) SendMessage(hwndClient, WM_MDIGETACTIVE, 0, 0);
if(SendMessage(hwndChild, WM_QUERYENDSESSION, 0, 0))
SendMessage(hwndClient, WM_MDIDESTROY, (WPARAM) hwndChild, 0);break;
// alle fenster schließen
case ID_FENSTER_ALLESCHLIEEN:
EnumChildWindows(hwndClient, CloseEnumProc, 0);
break;default:
hwndChild = (HWND)SendMessage(hwndClient, WM_MDIGETACTIVE, 0, 0);
if(IsWindow(hwndChild))
SendMessage(hwndChild, WM_COMMAND, wParam, lParam);
break;
}break;
case WM_QUERYENDSESSION:
case WM_CLOSE:
SendMessage(hwnd, WM_COMMAND, ID_FENSTER_ALLESCHLIEEN, 0);
if(NULL != GetWindow(hwndClient, GW_CHILD))
return 0;
break;case WM_DESTROY:
PostQuitMessage(0);
break;
}return DefFrameProc(hwnd, NULL, message, wParam, lParam);
}BOOL CALLBACK CloseEnumProc(HWND hwnd, LPARAM lParam)
{
if(GetWindow(hwnd, GW_OWNER))
return TRUE;SendMessage(GetParent(hwnd), WM_MDIRESTORE, (WPARAM) hwnd, 0);
if(!SendMessage(hwnd, WM_QUERYENDSESSION, 0, 0))
return TRUE;SendMessage(GetParent(hwnd), WM_MDIDESTROY, (WPARAM) hwnd, 0);
return TRUE;
}LRESULT CALLBACK Client01Proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndClient, hwndFrame;
HDC hdc;
RECT rect;
PAINTSTRUCT ps;switch(message)
{
case WM_CREATE:hwndClient = GetParent(hwnd);
hwndFrame = GetParent(hwndClient);break;
case WM_COMMAND:
DrawMenuBar(hwndFrame);
return 0;case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
DrawText(hdc, "hallo", -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);EndPaint(hwnd, &ps);
return 0;
case WM_QUERYENDSESSION:
case WM_CLOSE:
//return 0;
break;case WM_DESTROY:
//return 0;
break;
}return DefMDIChildProc(hwnd, message, wParam, lParam);
}LRESULT CALLBACK Client02Proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndClient, hwndFrame;switch(message)
{
case WM_CREATE:hwndClient = GetParent(hwnd);
hwndFrame = GetParent(hwndClient);break;
case WM_COMMAND:
break;
case WM_PAINT:
break;
case WM_CLOSE:
break;
case WM_DESTROY:
break;
}return DefMDIChildProc(hwnd, message, wParam, lParam);
}
[code]danke schonmal
Marcel
-
so wird dir bestimmt niemand helfen
-
Du könntest ja Code-Tags nehmen, dann wird's gleich übersichtlicher...
cu
-
du könntest auch mal sagen was nicht funktioniert
-
ka, ich kenn mich mit mdi nicht aus :D. Hast du den Petzold, wenn ja, schau da rein...
cu