접기
IDR_MENU1 MENU DISCARDABLE
BEGIN
POPUP "File"
BEGIN
MENUITEM "New Draw", ID_FILE_NEWDRAW
MENUITEM "New Edit", ID_FILE_NEWEDIT
END
END
IDR_MENU2 MENU DISCARDABLE
BEGIN
POPUP "File"
BEGIN
MENUITEM "New Draw", ID_FILE_NEWDRAW
MENUITEM "New Edit", ID_FILE_NEWEDIT
END
POPUP "Window"
BEGIN
MENUITEM "Tile", 40005
MENUITEM "Cascade", 40006
MENUITEM "Arrange Icon", ID_WIN_ARRANGE
END
POPUP "Draw"
BEGIN
MENUITEM "Line", ID_DRAW_LINE
MENUITEM "Ellipse", ID_DRAW_ELLIPSE
MENUITEM "Rectange", ID_DRAW_RECTANGLE
MENUITEM "Chose Color", ID_DRAW_CHOOSECOLOR
END
END
IDR_MENU3 MENU DISCARDABLE
BEGIN
POPUP "File"
BEGIN
MENUITEM "New Draw", ID_FILE_NEWDRAW
MENUITEM "New Edit", ID_FILE_NEWEDIT
END
POPUP "Window"
BEGIN
MENUITEM "Tile", ID_WIN_TILE
MENUITEM "Cascade", ID_WIN_CASCADE
MENUITEM "Arrange Icon", 40007
END
POPUP "Edit"
BEGIN
MENUITEM "Cut", ID_EDIT_CUT
MENUITEM "Copy", ID_EDIT_COPY
MENUITEM "Paste", ID_EDIT_PASTE
END
END
LRESULT CALLBACK MDIEditProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
switch (iMessage) {
case WM_CREATE:
... SetWindowLong(hWnd, 0, ...) ...
return 0;
case WM_MDIACTIVATE :
if (lParam==(LPARAM)hWnd)
SendMessage(g_hMDIClient,WM_MDISETMENU ,
(WPARAM)hMenu2,(LPARAM)hMenu2W);
else
SendMessage(g_hMDIClient,WM_MDISETMENU ,
(WPARAM)hMenu1,(LPARAM)hMenu1W);
DrawMenuBar(g_hFrameWnd);
return 0;
... GetWindowLong(hWnd, 0)) ...
}
return(DefMDIChildProc (hWnd,iMessage,wParam,lParam));
}
LRESULT CALLBACK MDIDrawProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
switch (iMessage) {
case WM_CREATE:
... SetWindowLong(hWnd, 0, ...) ...
return 0;
case WM_MDIACTIVATE :
if (lParam==(LPARAM)hWnd)
SendMessage(g_hMDIClient,WM_MDISETMENU ,
(WPARAM)hMenu2,(LPARAM)hMenu2W);
else
SendMessage(g_hMDIClient,WM_MDISETMENU ,
(WPARAM)hMenu1,(LPARAM)hMenu1W);
DrawMenuBar(g_hFrameWnd);
return 0;
... GetWindowLong(hWnd, 0)) ...
}
return(DefMDIChildProc (hWnd,iMessage,wParam,lParam));
}
#define IDM_WINDOWCHILD 41000
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE: {
CLIENTCREATESTRUCT ccs;
// MDI Client 윈도우 만듬
ccs.hWindowMenu = GetSubMenu(GetMenu(hWnd), 1);
ccs.idFirstChild = IDM_WINDOWCHILD;
g_hMDIClient = CreateWindow("MDICLIENT ", NULL, WS_CHILD | WS_VSCROLL |
WS_HSCROLL | WS_CLIPCHILDREN | WS_BORDER,
0,0,0,0,hWnd,(HMENU)NULL, g_hInst, (LPSTR)&ccs);
ShowWindow(g_hMDIClient, SW_SHOW);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_COMMAND: {
int wmId, wmEvent;
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_EXIT:
DestroyWindow(hWnd);
return 0;
// {
case ID_FILE_NEWEDIT: {
MDICREATESTRUCT mcs;
mcs.szClass=TEXT("MDIExamEdit");
mcs.szTitle=TEXT("Edit");
mcs.hOwner=g_hInst;
mcs.x=mcs.y=CW_USEDEFAULT;
mcs.cx=mcs.cy=CW_USEDEFAULT;
mcs.style=MDIS_ALLCHILDSTYLES;
SendMessage(g_hMDIClient, WM_MDICREATE , 0,
(LPARAM)(LPMDICREATESTRUCT)&mcs);
}
return 0;
case ID_FILE_NEWDRAW: {
MDICREATESTRUCT mcs;
mcs.szClass=TEXT("MDIExamDraw");
mcs.szTitle=TEXT("Draw");
mcs.hOwner=g_hInst;
mcs.x=mcs.y=CW_USEDEFAULT;
mcs.cx=mcs.cy=CW_USEDEFAULT;
mcs.style=MDIS_ALLCHILDSTYLES;
SendMessage(g_hMDIClient, WM_MDICREATE , 0,
(LPARAM)(LPMDICREATESTRUCT)&mcs);
}
return 0;
case ID_WIN_TILE:
SendMessage(g_hMDIClient, WM_MDITILE ,
(WPARAM)MDITILE_HORIZONTAL , 0);
return 0;
// 계단식 정렬
case ID_WIN_CASCADE:
SendMessage(g_hMDIClient, WM_MDICASCADE ,
(WPARAM)MDITILE_SKIPDISABLED, 0);
return 0;
// 아이콘 정렬
case ID_WIN_ARRANGE:
SendMessage(g_hMDIClient, WM_MDIICONARRANGE , 0, 0);
return 0;
// }
case IDM_ABOUT:
DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
return 0;
}
}
break;
}
return(DefFrameProc (hWnd,g_hMDIClient,message,wParam,lParam));
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
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_MDIEXAM);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
// {
ATOM ret;
if ((ret = RegisterClassEx(&wcex)) == 0)
return ret;
wcex.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wcex.lpszClassName=TEXT("MDIExamEdit");
wcex.lpfnWndProc=MDIEditProc;
wcex.hIcon=LoadIcon(NULL,IDI_ASTERISK);
wcex.lpszMenuName=NULL;
wcex.hIconSm = LoadIcon(NULL,IDI_ASTERISK);
wcex.cbWndExtra=sizeof(DWORD_PTR);
if ((ret = RegisterClassEx(&wcex)) == 0)
return ret;
wcex.lpszClassName=TEXT("MDIExamDraw");
wcex.lpfnWndProc=MDIDrawProc;
wcex.hIcon=LoadIcon(NULL,IDI_ERROR);
wcex.lpszMenuName=NULL;
wcex.hIconSm = LoadIcon(NULL,IDI_ERROR);
wcex.cbWndExtra=sizeof(DWORD);
wcex.style=CS_DBLCLKS;
// }
return RegisterClassEx(&wcex);
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
...
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MDIEXAM);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateMDISysAccel (g_hMDIClient, &msg) &&
!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
접기