通过Windows API实现的MDI简易程序

##

#include <windows.h>
#include <tchar.h> HINSTANCE hInst; ATOM WindowRegister(WNDPROC lpfnWndProc, char *lpClname, HBRUSH hbrBack)
{
WNDCLASSEX wnd;
wnd.cbClsExtra = ;
wnd.cbSize = sizeof(WNDCLASSEX);
wnd.cbWndExtra = ;
wnd.hbrBackground = hbrBack;
wnd.hCursor = LoadCursor(NULL, IDC_ARROW);
wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wnd.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wnd.hInstance = hInst;
wnd.lpfnWndProc = lpfnWndProc;
wnd.lpszClassName = lpClname;
wnd.lpszMenuName = NULL;
wnd.style = CS_HREDRAW | CS_VREDRAW;
return RegisterClassEx(&wnd);
} LRESULT CALLBACK ClientProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HWND hWndEdit;
RECT rect;
switch (uMsg)
{
case WM_CREATE:
GetClientRect(hWnd, &rect);
hWndEdit = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("Edit"), NULL,
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_MULTILINE,
, , rect.right, rect.bottom, hWnd, NULL, hInst, NULL);
return ;
case WM_SIZE:
hWndEdit = GetWindow(hWnd, GW_CHILD); GetClientRect(hWnd, &rect);
SetWindowPos(hWndEdit, NULL, , , rect.right, rect.bottom, SWP_NOMOVE | SWP_NOZORDER);
break;
case WM_MDIACTIVATE:
return ;
} return DefMDIChildProc(hWnd, uMsg, wParam, lParam);
} LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HWND hClient;
HMENU hMenu;
MDICREATESTRUCT mdic;
CLIENTCREATESTRUCT ccs;
HWND hChild; switch (uMsg)
{
case WM_CREATE:
WindowRegister(ClientProc, _T("Client"), (HBRUSH)GetStockObject(WHITE_BRUSH));
hMenu = CreateMenu();
AppendMenu(hMenu, MF_STRING, , _T("New(&N)"));
SetMenu(hWnd, hMenu); ccs.hWindowMenu = NULL;
ccs.idFirstChild = ; hClient = CreateWindow(_T("MDICLIENT"), NULL,
WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN,
, , , , hWnd, NULL, hInst, &ccs);
return ;
case WM_DESTROY: PostQuitMessage(); return ;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case :
mdic.szClass = _T("Client");
mdic.szTitle = _T("Document");
mdic.hOwner = hInst;
mdic.x = CW_USEDEFAULT;
mdic.y = CW_USEDEFAULT;
mdic.cx = CW_USEDEFAULT;
mdic.cy = CW_USEDEFAULT;
mdic.style = ;
mdic.lParam = ; hChild = (HWND)SendMessage(hClient, WM_MDICREATE, , (LPARAM)&mdic);
break;
default:
hChild = (HWND)SendMessage(hClient, WM_MDIGETACTIVE, , );
if(IsWindow(hChild))
SendMessage(hChild, WM_COMMAND, wParam, lParam);
break;
}
break;
}
return DefFrameProc(hWnd, hClient, uMsg, wParam, lParam);
} INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nShowCmd)
{
MSG msg;
HWND hClient;
HWND hWnd; WindowRegister(WndProc, _T("Sample"), (HBRUSH)(COLOR_APPWORKSPACE + ));
hInst = hInstance;
hWnd = CreateWindow(_T("Sample"), _T("Sample"),WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,, , , , NULL, NULL, hInstance, NULL); if (!hWnd)
return FALSE;
hClient=GetWindow(hWnd, GW_CHILD); ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd); while (GetMessage(&msg, NULL, , ))
{
if (!TranslateMDISysAccel(hClient, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
上一篇:Python图表数据可视化Seaborn:2. 分类数据可视化-分类散点图|分布图(箱型图|小提琴图|LV图表)|统计图(柱状图|折线图)


下一篇:文字编辑器FCKeditor 简介以及基本配置和使用方法