怎么用VC实现窗口嵌套,对话框作为子窗口
外层是对话框或者单文档,里层是对话框或者其他什么的,类似这个图的效果具体怎么实现的,给个思路,最好给个例子,824574978@qq.com...
外层是对话框或者单文档,里层是对话框或者其他什么的,类似这个图的效果
具体怎么实现的,给个思路,最好给个例子,824574978@qq.com 展开
具体怎么实现的,给个思路,最好给个例子,824574978@qq.com 展开
4个回答
展开全部
//MDI多重文件界面演示
#include <windows.h>
#include "resource.h"
#define IDM_FIRSTCHILD 50000
//函数声明
LRESULT CALLBACK FrameWndProc (HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK myclosewindowproc(HWND, LPARAM);
LRESULT CALLBACK HelloWndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK RectWndProc(HWND, UINT, WPARAM, LPARAM);
//子窗口类1的额外数据wndclass.cbWndExtra
typedef struct
{
UINT iColor;
COLORREF clrText;
}
HELLODATA,* PHELLODATA;
//子窗口类2的额外数据wndclass.cbWndExtra
typedef struct
{
short cxClient;
short cyClient;
}
RECTDATA, * PRECTDATA;
//全局变量
TCHAR szAppName[]=TEXT("MDI多重文件界面演示");
TCHAR szFrameClass[]=TEXT("框架窗口");
TCHAR szHelloClass[]=TEXT("子窗口类1");
TCHAR szRectClass[]=TEXT("子窗口类2");
HINSTANCE hInst;
HMENU hframemenu, hMenuHello, hMenuRect;//没有子窗口、子窗口类1、子窗口类2时的顶层菜单
HMENU hMenuInit, hMenuHelloWindow, hMenuRectWindow;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow)
{
MSG msg;
WNDCLASS wndclass;
HACCEL hAccel;//快捷键
HWND hwndFrame,hwndclient;//框架窗口、客户窗口
hInst=hInstance;//保存全局变量
//注册框架窗口类
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=szFrameClass;
if (!RegisterClass (&wndclass))
{
MessageBox(NULL,TEXT("This program requires Windows NT!"),szAppName,MB_ICONERROR);
return 0;
}
//注册子窗口类1
wndclass.lpfnWndProc=HelloWndProc;
wndclass.cbWndExtra=sizeof(HANDLE);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject (WHITE_BRUSH);
wndclass.lpszClassName=szHelloClass;
RegisterClass (&wndclass);
//注册子窗口类2
wndclass.lpfnWndProc=RectWndProc;
wndclass.cbWndExtra=sizeof(HANDLE);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszClassName=szRectClass;
RegisterClass(&wndclass);
//加载菜单
hframemenu=LoadMenu(hInstance,MAKEINTRESOURCE(IDR_FRAMEMENU));
hMenuHello=LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENU1));
hMenuRect=LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENU2));
hMenuInit=GetSubMenu(hframemenu,0);
hMenuHelloWindow=GetSubMenu(hMenuHello,2);
hMenuRectWindow=GetSubMenu(hMenuRect,1);
//加载快捷键
hAccel=LoadAccelerators (hInstance, szAppName);
//创建框架窗口,注意:WS_CLIPCHILDREN样式
hwndFrame=CreateWindow(szFrameClass,szFrameClass,WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,hframemenu,hInstance,NULL);
ShowWindow(hwndFrame,iCmdShow);
UpdateWindow (hwndFrame);
hwndclient=GetWindow(hwndFrame,GW_CHILD);//返回框架窗口Z序最顶层的子窗口,即客户窗口
//消息循环
while(GetMessage(&msg,NULL,0,0))
{
if(!TranslateMDISysAccel(hwndclient,&msg)&&!TranslateAccelerator(hwndFrame,hAccel,&msg))
{
TranslateMessage(&msg);
DispatchMessage (&msg);
}
}
//删除不是主窗口菜单的菜单
DestroyMenu(hMenuHello);
DestroyMenu(hMenuRect);
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:
//创建客户窗口,MDICLIENT为系统预定义的类名,将CLIENTCREATESTRUCT作为参数
clientcreate.hWindowMenu=hMenuInit;//客户窗口一旦建立一个子窗口,把子窗口标题加到hMenuInit的底部。
clientcreate.idFirstChild=IDM_FIRSTCHILD;//与子窗口列表中第1个窗口相关联的菜单ID
hwndclient=CreateWindow(TEXT("MDICLIENT"),TEXT("客户窗口"),WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,0,0,0,0,hwnd,(HMENU)1,hInst,(PSTR) &clientcreate);
break;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case IDM_FILE_NEWHELLO://创建1个子窗口类1的窗口
mdicreate.szClass=szHelloClass;
mdicreate.szTitle=TEXT("Hello");
mdicreate.hOwner=hInst;
mdicreate.x=CW_USEDEFAULT;
mdicreate.y=CW_USEDEFAULT;
mdicreate.cx=CW_USEDEFAULT;
mdicreate.cy=CW_USEDEFAULT;
mdicreate.style=WS_HSCROLL|WS_VSCROLL;
mdicreate.lParam=0;
hwndChild=(HWND)SendMessage(hwndclient,WM_MDICREATE,0,(LPARAM)(LPMDICREATESTRUCT)&mdicreate);
break;
case IDM_FILE_NEWRECT://创建1个子窗口类2的窗口
mdicreate.szClass=szRectClass;
mdicreate.szTitle=TEXT("随机矩形");
mdicreate.hOwner=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);
break;
case IDM_FILE_CLOSE://关闭活动的子窗口
hwndChild=(HWND)SendMessage (hwndclient,WM_MDIGETACTIVE, 0, 0);
if(SendMessage(hwndChild,WM_QUERYENDSESSION,0,0))
{
SendMessage(hwndclient,WM_MDIDESTROY,(WPARAM)hwndChild,0);
}
break;
case IDM_APP_EXIT://退出程序
SendMessage (hwnd, WM_CLOSE, 0, 0);
break;
case IDM_WINDOW_TILE:
SendMessage(hwndclient,WM_MDITILE,0,0);
break;
case IDM_WINDOW_CASCADE:
SendMessage(hwndclient,WM_MDICASCADE,0,0);
break;
case IDM_WINDOW_ARRANGE:
SendMessage(hwndclient,WM_MDIICONARRANGE,0,0);
break;
case IDM_WINDOW_CLOSEALL://关闭所有子窗口
EnumChildWindows(hwndclient,myclosewindowproc,0);//遍历所有子窗口
break;
default://未处理的WM_COMMAND传递给活动的子窗口
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,IDM_WINDOW_CLOSEALL,0);
if(GetWindow(hwndclient,GW_CHILD))//如果还有子窗口,返回0
{
return 0;
}
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
}
return DefFrameProc (hwnd, hwndclient, message, wParam, lParam);
}
BOOL CALLBACK myclosewindowproc(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 HelloWndProc (HWND hwnd, UINT message,WPARAM wParam, LPARAM lParam)
{
static COLORREF clrTextArray[]={RGB(255,0,0),RGB(0,255,0),RGB(0,0,255),RGB(0,0,0),RGB(255,255,255)};
static HWND hwndclient,hwndFrame;
HDC hdc;
HMENU hMenu;
PHELLODATA pHelloData;
PAINTSTRUCT ps;
RECT rect;
switch(message)
{
case WM_CREATE:
pHelloData = (PHELLODATA) HeapAlloc (GetProcessHeap (),HEAP_ZERO_MEMORY, sizeof (HELLODATA));
pHelloData->iColor=IDM_COLOR_BLACK;
pHelloData->clrText = RGB (0, 0, 0);
SetWindowLong (hwnd, 0, (long) pHelloData);
hwndclient=GetParent(hwnd);
hwndFrame=GetParent(hwndclient);
break;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case IDM_COLOR_BLACK:
case IDM_COLOR_RED:
case IDM_COLOR_GREEN:
case IDM_COLOR_BLUE:
case IDM_COLOR_WHITE:
pHelloData=(PHELLODATA)GetWindowLong (hwnd, 0);
hMenu=GetMenu(hwndFrame);
CheckMenuItem(hMenu,pHelloData->iColor,MF_UNCHECKED);
pHelloData->iColor=LOWORD(wParam);
CheckMenuItem (hMenu,pHelloData->iColor,MF_CHECKED);
pHelloData->clrText=clrTextArray[wParam-IDM_COLOR_RED];
InvalidateRect (hwnd, NULL, FALSE);
break;
}
break;
case WM_PAINT:
hdc=BeginPaint (hwnd, &ps);
pHelloData=(PHELLODATA) GetWindowLong (hwnd, 0);
SetTextColor(hdc, pHelloData->clrText);
GetClientRect(hwnd, &rect);
DrawText(hdc,TEXT("Hello,World!"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
EndPaint (hwnd, &ps);
break;
case WM_MDIACTIVATE:
pHelloData=(PHELLODATA)GetWindowLong(hwnd,0);
if (lParam==(LPARAM)hwnd)
{
SendMessage(hwndclient,WM_MDISETMENU,(WPARAM)hMenuHello,(LPARAM)hMenuHelloWindow);
CheckMenuItem (hMenuHello,pHelloData->iColor,MF_CHECKED);
}
else
{
SendMessage (hwndclient, WM_MDISETMENU, (WPARAM)hframemenu,(LPARAM) hMenuInit);
CheckMenuItem (hMenuHello,pHelloData->iColor,MF_UNCHECKED);
}
DrawMenuBar (hwndFrame);
return 0;
case WM_QUERYENDSESSION:
case WM_CLOSE:
break;
case WM_DESTROY:
pHelloData = (PHELLODATA) GetWindowLong (hwnd, 0);
HeapFree (GetProcessHeap (), 0, pHelloData);
return 0;
}
return DefMDIChildProc (hwnd, message, wParam, lParam);
}
//
LRESULT CALLBACK RectWndProc(HWND hwnd, UINT message,WPARAM wParam, LPARAM lParam)
{
static HWND hwndclient,hwndFrame;
HBRUSH hBrush;
HDC hdc;
PRECTDATA pRectData;
PAINTSTRUCT ps;
switch (message)
{
case WM_CREATE:
pRectData = (PRECTDATA) HeapAlloc (GetProcessHeap (),HEAP_ZERO_MEMORY, sizeof (RECTDATA));
SetWindowLong (hwnd, 0, (long) pRectData);
SetTimer (hwnd, 1, 250, NULL);
hwndclient = GetParent (hwnd);
hwndFrame = GetParent (hwndclient);
return 0;
case WM_SIZE:
if (wParam != SIZE_MINIMIZED)
{
pRectData = (PRECTDATA) GetWindowLong (hwnd, 0);
pRectData->cxClient = LOWORD (lParam);
pRectData->cyClient = HIWORD (lParam);
}
break;//WM_SIZE must be processed by DefMDIChildProc
case WM_TIMER:
pRectData=(PRECTDATA)GetWindowLong (hwnd, 0);
hdc=GetDC(hwnd);
hBrush=CreateSolidBrush(RGB(rand()%256,rand()%256,rand ()%256));
SelectObject(hdc,hBrush);
Rectangle(hdc,rand()%pRectData->cxClient,rand()%pRectData->cyClient,rand()%pRectData->cxClient,rand()%pRectData->cyClient);
ReleaseDC (hwnd, hdc);
DeleteObject (hBrush);
return 0;
case WM_PAINT:
InvalidateRect (hwnd, NULL, TRUE);
hdc = BeginPaint (hwnd, &ps);
EndPaint (hwnd, &ps);
return 0;
case WM_MDIACTIVATE:
if (lParam == (LPARAM) hwnd)
{
SendMessage (hwndclient, WM_MDISETMENU, (WPARAM) hMenuRect, (LPARAM) hMenuRectWindow);
}
else
{
SendMessage (hwndclient, WM_MDISETMENU, (WPARAM) hframemenu, (LPARAM) hMenuInit);
}
DrawMenuBar (hwndFrame);
return 0;
case WM_DESTROY:
pRectData = (PRECTDATA) GetWindowLong (hwnd, 0);
HeapFree (GetProcessHeap (), 0, pRectData);
KillTimer (hwnd, 1);
return 0;
}
return DefMDIChildProc (hwnd, message, wParam, lParam);
}
#include <windows.h>
#include "resource.h"
#define IDM_FIRSTCHILD 50000
//函数声明
LRESULT CALLBACK FrameWndProc (HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK myclosewindowproc(HWND, LPARAM);
LRESULT CALLBACK HelloWndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK RectWndProc(HWND, UINT, WPARAM, LPARAM);
//子窗口类1的额外数据wndclass.cbWndExtra
typedef struct
{
UINT iColor;
COLORREF clrText;
}
HELLODATA,* PHELLODATA;
//子窗口类2的额外数据wndclass.cbWndExtra
typedef struct
{
short cxClient;
short cyClient;
}
RECTDATA, * PRECTDATA;
//全局变量
TCHAR szAppName[]=TEXT("MDI多重文件界面演示");
TCHAR szFrameClass[]=TEXT("框架窗口");
TCHAR szHelloClass[]=TEXT("子窗口类1");
TCHAR szRectClass[]=TEXT("子窗口类2");
HINSTANCE hInst;
HMENU hframemenu, hMenuHello, hMenuRect;//没有子窗口、子窗口类1、子窗口类2时的顶层菜单
HMENU hMenuInit, hMenuHelloWindow, hMenuRectWindow;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow)
{
MSG msg;
WNDCLASS wndclass;
HACCEL hAccel;//快捷键
HWND hwndFrame,hwndclient;//框架窗口、客户窗口
hInst=hInstance;//保存全局变量
//注册框架窗口类
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=szFrameClass;
if (!RegisterClass (&wndclass))
{
MessageBox(NULL,TEXT("This program requires Windows NT!"),szAppName,MB_ICONERROR);
return 0;
}
//注册子窗口类1
wndclass.lpfnWndProc=HelloWndProc;
wndclass.cbWndExtra=sizeof(HANDLE);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject (WHITE_BRUSH);
wndclass.lpszClassName=szHelloClass;
RegisterClass (&wndclass);
//注册子窗口类2
wndclass.lpfnWndProc=RectWndProc;
wndclass.cbWndExtra=sizeof(HANDLE);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszClassName=szRectClass;
RegisterClass(&wndclass);
//加载菜单
hframemenu=LoadMenu(hInstance,MAKEINTRESOURCE(IDR_FRAMEMENU));
hMenuHello=LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENU1));
hMenuRect=LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENU2));
hMenuInit=GetSubMenu(hframemenu,0);
hMenuHelloWindow=GetSubMenu(hMenuHello,2);
hMenuRectWindow=GetSubMenu(hMenuRect,1);
//加载快捷键
hAccel=LoadAccelerators (hInstance, szAppName);
//创建框架窗口,注意:WS_CLIPCHILDREN样式
hwndFrame=CreateWindow(szFrameClass,szFrameClass,WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,hframemenu,hInstance,NULL);
ShowWindow(hwndFrame,iCmdShow);
UpdateWindow (hwndFrame);
hwndclient=GetWindow(hwndFrame,GW_CHILD);//返回框架窗口Z序最顶层的子窗口,即客户窗口
//消息循环
while(GetMessage(&msg,NULL,0,0))
{
if(!TranslateMDISysAccel(hwndclient,&msg)&&!TranslateAccelerator(hwndFrame,hAccel,&msg))
{
TranslateMessage(&msg);
DispatchMessage (&msg);
}
}
//删除不是主窗口菜单的菜单
DestroyMenu(hMenuHello);
DestroyMenu(hMenuRect);
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:
//创建客户窗口,MDICLIENT为系统预定义的类名,将CLIENTCREATESTRUCT作为参数
clientcreate.hWindowMenu=hMenuInit;//客户窗口一旦建立一个子窗口,把子窗口标题加到hMenuInit的底部。
clientcreate.idFirstChild=IDM_FIRSTCHILD;//与子窗口列表中第1个窗口相关联的菜单ID
hwndclient=CreateWindow(TEXT("MDICLIENT"),TEXT("客户窗口"),WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,0,0,0,0,hwnd,(HMENU)1,hInst,(PSTR) &clientcreate);
break;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case IDM_FILE_NEWHELLO://创建1个子窗口类1的窗口
mdicreate.szClass=szHelloClass;
mdicreate.szTitle=TEXT("Hello");
mdicreate.hOwner=hInst;
mdicreate.x=CW_USEDEFAULT;
mdicreate.y=CW_USEDEFAULT;
mdicreate.cx=CW_USEDEFAULT;
mdicreate.cy=CW_USEDEFAULT;
mdicreate.style=WS_HSCROLL|WS_VSCROLL;
mdicreate.lParam=0;
hwndChild=(HWND)SendMessage(hwndclient,WM_MDICREATE,0,(LPARAM)(LPMDICREATESTRUCT)&mdicreate);
break;
case IDM_FILE_NEWRECT://创建1个子窗口类2的窗口
mdicreate.szClass=szRectClass;
mdicreate.szTitle=TEXT("随机矩形");
mdicreate.hOwner=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);
break;
case IDM_FILE_CLOSE://关闭活动的子窗口
hwndChild=(HWND)SendMessage (hwndclient,WM_MDIGETACTIVE, 0, 0);
if(SendMessage(hwndChild,WM_QUERYENDSESSION,0,0))
{
SendMessage(hwndclient,WM_MDIDESTROY,(WPARAM)hwndChild,0);
}
break;
case IDM_APP_EXIT://退出程序
SendMessage (hwnd, WM_CLOSE, 0, 0);
break;
case IDM_WINDOW_TILE:
SendMessage(hwndclient,WM_MDITILE,0,0);
break;
case IDM_WINDOW_CASCADE:
SendMessage(hwndclient,WM_MDICASCADE,0,0);
break;
case IDM_WINDOW_ARRANGE:
SendMessage(hwndclient,WM_MDIICONARRANGE,0,0);
break;
case IDM_WINDOW_CLOSEALL://关闭所有子窗口
EnumChildWindows(hwndclient,myclosewindowproc,0);//遍历所有子窗口
break;
default://未处理的WM_COMMAND传递给活动的子窗口
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,IDM_WINDOW_CLOSEALL,0);
if(GetWindow(hwndclient,GW_CHILD))//如果还有子窗口,返回0
{
return 0;
}
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
}
return DefFrameProc (hwnd, hwndclient, message, wParam, lParam);
}
BOOL CALLBACK myclosewindowproc(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 HelloWndProc (HWND hwnd, UINT message,WPARAM wParam, LPARAM lParam)
{
static COLORREF clrTextArray[]={RGB(255,0,0),RGB(0,255,0),RGB(0,0,255),RGB(0,0,0),RGB(255,255,255)};
static HWND hwndclient,hwndFrame;
HDC hdc;
HMENU hMenu;
PHELLODATA pHelloData;
PAINTSTRUCT ps;
RECT rect;
switch(message)
{
case WM_CREATE:
pHelloData = (PHELLODATA) HeapAlloc (GetProcessHeap (),HEAP_ZERO_MEMORY, sizeof (HELLODATA));
pHelloData->iColor=IDM_COLOR_BLACK;
pHelloData->clrText = RGB (0, 0, 0);
SetWindowLong (hwnd, 0, (long) pHelloData);
hwndclient=GetParent(hwnd);
hwndFrame=GetParent(hwndclient);
break;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case IDM_COLOR_BLACK:
case IDM_COLOR_RED:
case IDM_COLOR_GREEN:
case IDM_COLOR_BLUE:
case IDM_COLOR_WHITE:
pHelloData=(PHELLODATA)GetWindowLong (hwnd, 0);
hMenu=GetMenu(hwndFrame);
CheckMenuItem(hMenu,pHelloData->iColor,MF_UNCHECKED);
pHelloData->iColor=LOWORD(wParam);
CheckMenuItem (hMenu,pHelloData->iColor,MF_CHECKED);
pHelloData->clrText=clrTextArray[wParam-IDM_COLOR_RED];
InvalidateRect (hwnd, NULL, FALSE);
break;
}
break;
case WM_PAINT:
hdc=BeginPaint (hwnd, &ps);
pHelloData=(PHELLODATA) GetWindowLong (hwnd, 0);
SetTextColor(hdc, pHelloData->clrText);
GetClientRect(hwnd, &rect);
DrawText(hdc,TEXT("Hello,World!"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
EndPaint (hwnd, &ps);
break;
case WM_MDIACTIVATE:
pHelloData=(PHELLODATA)GetWindowLong(hwnd,0);
if (lParam==(LPARAM)hwnd)
{
SendMessage(hwndclient,WM_MDISETMENU,(WPARAM)hMenuHello,(LPARAM)hMenuHelloWindow);
CheckMenuItem (hMenuHello,pHelloData->iColor,MF_CHECKED);
}
else
{
SendMessage (hwndclient, WM_MDISETMENU, (WPARAM)hframemenu,(LPARAM) hMenuInit);
CheckMenuItem (hMenuHello,pHelloData->iColor,MF_UNCHECKED);
}
DrawMenuBar (hwndFrame);
return 0;
case WM_QUERYENDSESSION:
case WM_CLOSE:
break;
case WM_DESTROY:
pHelloData = (PHELLODATA) GetWindowLong (hwnd, 0);
HeapFree (GetProcessHeap (), 0, pHelloData);
return 0;
}
return DefMDIChildProc (hwnd, message, wParam, lParam);
}
//
LRESULT CALLBACK RectWndProc(HWND hwnd, UINT message,WPARAM wParam, LPARAM lParam)
{
static HWND hwndclient,hwndFrame;
HBRUSH hBrush;
HDC hdc;
PRECTDATA pRectData;
PAINTSTRUCT ps;
switch (message)
{
case WM_CREATE:
pRectData = (PRECTDATA) HeapAlloc (GetProcessHeap (),HEAP_ZERO_MEMORY, sizeof (RECTDATA));
SetWindowLong (hwnd, 0, (long) pRectData);
SetTimer (hwnd, 1, 250, NULL);
hwndclient = GetParent (hwnd);
hwndFrame = GetParent (hwndclient);
return 0;
case WM_SIZE:
if (wParam != SIZE_MINIMIZED)
{
pRectData = (PRECTDATA) GetWindowLong (hwnd, 0);
pRectData->cxClient = LOWORD (lParam);
pRectData->cyClient = HIWORD (lParam);
}
break;//WM_SIZE must be processed by DefMDIChildProc
case WM_TIMER:
pRectData=(PRECTDATA)GetWindowLong (hwnd, 0);
hdc=GetDC(hwnd);
hBrush=CreateSolidBrush(RGB(rand()%256,rand()%256,rand ()%256));
SelectObject(hdc,hBrush);
Rectangle(hdc,rand()%pRectData->cxClient,rand()%pRectData->cyClient,rand()%pRectData->cxClient,rand()%pRectData->cyClient);
ReleaseDC (hwnd, hdc);
DeleteObject (hBrush);
return 0;
case WM_PAINT:
InvalidateRect (hwnd, NULL, TRUE);
hdc = BeginPaint (hwnd, &ps);
EndPaint (hwnd, &ps);
return 0;
case WM_MDIACTIVATE:
if (lParam == (LPARAM) hwnd)
{
SendMessage (hwndclient, WM_MDISETMENU, (WPARAM) hMenuRect, (LPARAM) hMenuRectWindow);
}
else
{
SendMessage (hwndclient, WM_MDISETMENU, (WPARAM) hframemenu, (LPARAM) hMenuInit);
}
DrawMenuBar (hwndFrame);
return 0;
case WM_DESTROY:
pRectData = (PRECTDATA) GetWindowLong (hwnd, 0);
HeapFree (GetProcessHeap (), 0, pRectData);
KillTimer (hwnd, 1);
return 0;
}
return DefMDIChildProc (hwnd, message, wParam, lParam);
}
追问
resource.h是什么?? 可以把完整的小例子给我吗??谢谢了
追答
发给你了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
给你个例子,在邮箱。
追问
十分感谢,可是我要的不是这种效果阿,我想要那种窗口嵌套的效果,外层窗口里面嵌套子窗口,子窗口可以打开关闭,最大化最小化之类的,就像上面的图里的样子
追答
这个还没研究额,呵呵
不过vc6.0默认mfc工程的多文档就是这种形式的,你可以看看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这是多文档视图,利用MFC可以创建多文档应用程序
追问
具体怎么实现的,给个思路,最好给个例子,824574978@qq.com
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
非模态对话框,MoveWindow
追问
具体怎么实现的,给个思路,最好给个例子,824574978@qq.com
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询