定数 | 解説 |
---|---|
MDITILE_HORIZONTAL | MDI クライアントウィンドウの横幅一杯に 上下に並べて表示する |
MDITILE_SKIPDISABLED | 使用禁止状態の MDI 子ウィンドウを除外する |
MDITILE_VERTICAL | MDI クライアントウィンドウの高さ一杯に 左右に並べて表示する |
//resource.h #define IDM_EXIT 0x1001 #define IDM_NEW 0x2001 #define IDM_CAS 0x2002 #define IDM_ARR 0x2003 #define IDM_MAX 0x2004 #define IDM_NEXT 0x2005 #define IDM_RES 0x2006 #define IDM_TILH 0x2007 #define IDM_TILV 0x2008 #define IDM_DEL 0x2009
//リソーススクリプト #include "resource.h" KITTY MENU { POPUP "File(&F)" { MENUITEM "終了(&X)" , IDM_EXIT } POPUP "Window(&W)" { MENUITEM "新規作成(&N)" , IDM_NEW MENUITEM "重ねて表示(&C)" , IDM_CAS MENUITEM "最小化を整列(&A)" , IDM_ARR MENUITEM "最大化(&M)" , IDM_MAX MENUITEM "次のウィンドウ(&E)" , IDM_NEXT MENUITEM "元のサイズ(&R)" , IDM_RES POPUP "並べて表示(&T)" { MENUITEM "上下(&H)" , IDM_TILH MENUITEM "左右(&V)" , IDM_TILV } MENUITEM "閉じる(&D)" , IDM_DEL } }
#include <windows.h> #include "resource.h" #define TITLE TEXT("Kitty on your lap") #define MDI_FRAME TEXT("FRAMEWINDOW") #define MDI_CHILD TEXT("MDICHILD") #define ID_CHILDWND 0x100 HINSTANCE hIns; HWND hClient; LRESULT CALLBACK FrameProc(HWND hWnd , UINT msg , WPARAM wp , LPARAM lp) { HDC hdc; PAINTSTRUCT ps; CLIENTCREATESTRUCT ccsClient; HWND hActive; switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_CREATE: ccsClient.hWindowMenu = GetSubMenu(GetMenu(hWnd) , 1); ccsClient.idFirstChild = ID_CHILDWND; hClient = CreateWindow(TEXT("MDICLIENT") , NULL , WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE , 0 , 0 , 0 , 0 , hWnd , (HMENU)1 , hIns , &ccsClient ); return 0; case WM_COMMAND: hActive = (HWND)SendMessage(hClient , WM_MDIGETACTIVE , 0 , 0); switch(LOWORD(wp)) { case IDM_EXIT: SendMessage(hWnd , WM_CLOSE , 0 , 0); return 0; case IDM_NEW: CreateMDIWindow(MDI_CHILD , TITLE , 0 , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , hClient , hIns , 0 ); return 0; case IDM_CAS: SendMessage(hClient , WM_MDICASCADE , MDITILE_SKIPDISABLED , 0); return 0; case IDM_ARR: SendMessage(hClient , WM_MDIICONARRANGE , 0 , 0); return 0; case IDM_MAX: SendMessage(hClient , WM_MDIMAXIMIZE , (WPARAM)hActive , 0); return 0; case IDM_NEXT: SendMessage(hClient , WM_MDINEXT , (WPARAM)hActive , 0); return 0; case IDM_RES: SendMessage(hClient , WM_MDIRESTORE , (WPARAM)hActive , 0); return 0; case IDM_TILH: SendMessage(hClient , WM_MDITILE , MDITILE_HORIZONTAL , 0); return 0; case IDM_TILV: SendMessage(hClient , WM_MDITILE , MDITILE_VERTICAL , 0); return 0; case IDM_DEL: SendMessage(hClient , WM_MDIDESTROY ,(WPARAM)hActive , 0); } } return DefFrameProc(hWnd , hClient , msg , wp , lp); } int WINAPI WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance , PSTR lpCmdLine , int nCmdShow) { HWND hWnd; MSG msg; WNDCLASS winc; hIns = hInstance; winc.style = CS_HREDRAW | CS_VREDRAW; winc.lpfnWndProc = FrameProc; winc.cbClsExtra = winc.cbWndExtra = 0; winc.hInstance = hInstance; winc.hIcon = LoadIcon(NULL , IDI_APPLICATION); winc.hCursor = LoadCursor(NULL , IDC_ARROW); winc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1); winc.lpszMenuName = TEXT("KITTY"); winc.lpszClassName = MDI_FRAME; if (!RegisterClass(&winc)) return 1; winc.lpfnWndProc = DefMDIChildProc; winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); winc.lpszClassName = MDI_CHILD; if (!RegisterClass(&winc)) return 1; hWnd = CreateWindow( MDI_FRAME , TITLE , WS_OVERLAPPEDWINDOW | WS_VISIBLE , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , NULL , NULL , hInstance , NULL ); if (hWnd == NULL) return 1; while (GetMessage(&msg , NULL , 0 , 0 )) { if (!TranslateMDISysAccel(hClient , &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; }
WORD WINAPI CascadeWindows( HWND hwndParent, UINT wHow , CONST RECT *lpRect, UINT cKids , const HWND FAR *lpKids );hwndParent は親ウィンドウのハンドルを指定します
WORD WINAPI TileWindows( HWND hwndParent, UINT wHow , CONST RECT *lpRect, UINT cKids , const HWND FAR *lpKids );hwndParent には親ウィンドウのハンドルを指定します
#include <windows.h> #include "resource.h" #define TITLE TEXT("Kitty on your lap") #define MDI_FRAME TEXT("FRAMEWINDOW") #define MDI_CHILD TEXT("MDICHILD") #define ID_CHILDWND 0x100 HINSTANCE hIns; HWND hClient; LRESULT CALLBACK FrameProc(HWND hWnd , UINT msg , WPARAM wp , LPARAM lp) { HDC hdc; PAINTSTRUCT ps; CLIENTCREATESTRUCT ccsClient; HWND hActive; switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_CREATE: ccsClient.hWindowMenu = GetSubMenu(GetMenu(hWnd) , 1); ccsClient.idFirstChild = ID_CHILDWND; hClient = CreateWindow(TEXT("MDICLIENT") , NULL , WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE , 0 , 0 , 0 , 0 , hWnd , (HMENU)1 , hIns , &ccsClient ); return 0; case WM_COMMAND: hActive = (HWND)SendMessage(hClient , WM_MDIGETACTIVE , 0 , 0); switch(LOWORD(wp)) { case IDM_EXIT: SendMessage(hWnd , WM_CLOSE , 0 , 0); return 0; case IDM_NEW: CreateMDIWindow(MDI_CHILD , TITLE , 0 , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , hClient , hIns , 0 ); return 0; case IDM_CAS: CascadeWindows(hClient , 0 , NULL , 0 , NULL); return 0; case IDM_ARR: ArrangeIconicWindows(hClient); return 0; case IDM_MAX: SendMessage(hClient , WM_MDIMAXIMIZE , (WPARAM)hActive , 0); return 0; case IDM_NEXT: SendMessage(hClient , WM_MDINEXT , (WPARAM)hActive , 0); return 0; case IDM_RES: SendMessage(hClient , WM_MDIRESTORE , (WPARAM)hActive , 0); return 0; case IDM_TILH: TileWindows(hClient , MDITILE_HORIZONTAL , NULL , 0 , NULL); return 0; case IDM_TILV: TileWindows(hClient , MDITILE_VERTICAL , NULL , 0 , NULL); return 0; case IDM_DEL: SendMessage(hClient , WM_MDIDESTROY ,(WPARAM)hActive , 0); } } return DefFrameProc(hWnd , hClient , msg , wp , lp); } int WINAPI WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance , PSTR lpCmdLine , int nCmdShow) { HWND hWnd; MSG msg; WNDCLASS winc; hIns = hInstance; winc.style = CS_HREDRAW | CS_VREDRAW; winc.lpfnWndProc = FrameProc; winc.cbClsExtra = winc.cbWndExtra = 0; winc.hInstance = hInstance; winc.hIcon = LoadIcon(NULL , IDI_APPLICATION); winc.hCursor = LoadCursor(NULL , IDC_ARROW); winc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1); winc.lpszMenuName = TEXT("KITTY"); winc.lpszClassName = MDI_FRAME; if (!RegisterClass(&winc)) return 1; winc.lpfnWndProc = DefMDIChildProc; winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); winc.lpszClassName = MDI_CHILD; if (!RegisterClass(&winc)) return 1; hWnd = CreateWindow( MDI_FRAME , TITLE , WS_OVERLAPPEDWINDOW | WS_VISIBLE , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , NULL , NULL , hInstance , NULL ); if (hWnd == NULL) return 1; while (GetMessage(&msg , NULL , 0 , 0 )) { if (!TranslateMDISysAccel(hClient , &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; }これは、上のプログラムのメッセージ処理を一部関数に置き換えたプログラムです
WORD WINAPI CascadeWindows( HWND hwndParent, UINT wHow , CONST RECT *lpRect, UINT cKids , const HWND FAR *lpKids );最小化されていないウィンドウを並べて表示します
WORD WINAPI TileWindows( HWND hwndParent, UINT wHow , CONST RECT *lpRect, UINT cKids , const HWND FAR *lpKids );最小化されていないウィンドウを並べて表示します
定数 | 解説 |
---|---|
MDITILE_HORIZONTAL | MDI クライアントウィンドウの横幅一杯に 上下に並べて表示する |
MDITILE_SKIPDISABLED | 使用禁止状態の MDI 子ウィンドウを除外する |
MDITILE_VERTICAL | MDI クライアントウィンドウの高さ一杯に 左右に並べて表示する |