´ÙÀ½ ÄÚµå ¿¹Á¦¿¡¼´Â ¸Þ´º Ç׸ñÀÌ ºñÆ®¸Ê Æ÷ÇÔ µÈ ¸Þ´º¸¦ ¸¸µå´Â ¹æ¹ýÀ» º¸¿© ÁÝ´Ï´Ù. ±×°ÍÀº µÎ °³ÀÇ ¸Þ´º¸¦ ¸¸µì´Ï´Ù. ù ¹øÂ°´Â ¼¼ °¡Áö ¸Þ´º Ç׸ñÀÌ ºñÆ®¸Ê Æ÷ÇÔ µÈ Â÷Æ® ¸Þ´º: ¿øÇü Â÷Æ®, ²ªÀº¼±Çü Â÷Æ® ¹× °¡·Î ¸·´ëÇü Â÷Æ®. ¿¹Á¦ ÀÀ¿ë ÇÁ·Î±×·¥ÀÇ ¸®¼Ò½º ÆÄÀÏ¿¡¼ ÀÌ·¯ÇÑ ºñÆ®¸ÊÀ» ·Îµå ÇÏ °í ´ÙÀ½ CreatePopupMenu ¹× AppendMenu ÇÔ¼ö¸¦ »ç¿ë ÇÏ ¿© ¸Þ´º ¹× ¸Þ´º Ç׸ñÀ» ¸¸µå´Â ¹æ¹ý.
µÎ ¹øÂ° ¸Þ´º´Â ¶óÀÎ ¸Þ´º°¡ ÀÌ´Ù. ½Ã½ºÅÛ¿¡¼ ¹Ì¸® Á¤ÀÇ µÈ Ææ¿¡ ÀÇÇØ Á¦°ø µÇ´Â ¼± ½ºÅ¸ÀÏÀ» Ç¥½Ã ÇÏ´Â ºñÆ®¸ÊÀ» Æ÷ÇÔ ÇÕ´Ï´Ù. ¼± ½ºÅ¸ÀÏ ºñÆ®¸Ê GDI ÇÔ¼ö¸¦ »ç¿ë ÇÏ ¿© ·±Å¸ÀÓ¿¡ ¸¸µé¾îÁý´Ï´Ù.
¿©±â´Â ÀÀ¿ë ÇÁ·Î±×·¥ÀÇ ¸®¼Ò½º Á¤ÀÇ ÆÄÀÏ¿¡¼ ºñÆ®¸Ê ¸®¼Ò½ºÀÇ Á¤ÀÇ.
¿øÇü ºñÆ®¸Ê pie.bmp ¼± ºñÆ®¸Ê line.bmp ºñÆ®¸Ê ¹Ù bar.bmp
ÀÀ¿ë ÇÁ·Î±×·¥ÀÇ Çì´õ ÆÄÀÏÀÇ °ü·Ã ºÎºÐÀ» ¿îÇ×.
/ / ¸Þ´º Ç׸ñ ½Äº°ÀÚ # define IDM_SOLID PS_SOLID # define IDM_DASH PS_DASH # define IDM_DASHDOT PS_DASHDOT # define IDM_DASHDOTDOT PS_DASHDOTDOT # define IDM_PIE 1 # define IDM_LINE 2 # define IDM_BAR 3 / ¼± À¯Çü Ç÷¡±× # / # define # define ´ë½Ã 2 # define # define DASHDOT 3 Á¡ 1 °íü 0 Á¤ÀÇ DASHDOTDOT 4 / °è»ê / ÆæÀÇ # define CPENS 5 / Â÷Æ® Çü½Ä Ç÷¡±× # / ¿øÇü 1 # define ÁÙ 2 3 ¹Ù # define Á¤ÀÇ / / ÇÁ·ÎÅä ŸÀÔ ±â´É LRESULT APIENTRY MainWndProc (HWNDUINT, WPARAM, LPARAM);
VOID MakeChartMenu(HWND);
VOID MakeLineMenu (HWND, HPEN, HBITMAP)
´ÙÀ½ ¿¹Á¦¿¡¼´Â ÀÀ¿ë ÇÁ·Î±×·¥¿¡¼ ¸Þ´º ¹× ¸Þ´º Ç׸ñ ºñÆ®¸ÊÀ» »ý¼º ÇÏ´Â ¹æ¹ýÀ» º¸¿© ÁÝ´Ï´Ù.
LRESULT APIENTRY MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HPEN hpen[CPENS];
static HBITMAP hbmp[CPENS];
int i;
switch (uMsg)
{
case WM_CREATE:
// Create the Chart and Line menus.
MakeChartMenu(hwnd);
MakeLineMenu(hwnd, hpen, hbmp);
return 0;
// Process other window messages.
case WM_DESTROY:
for (i = 0; i < CPENS; i++)
{
DeleteObject(hbmp[i]);
DeleteObject(hpen[i]);
}
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return NULL;
}
VOID MakeChartMenu(HWND hwnd)
{
HBITMAP hbmpPie; // handle to pie chart bitmap
HBITMAP hbmpLine; // handle to line chart bitmap
HBITMAP hbmpBar; // handle to bar chart bitmap
HMENU hmenuMain; // handle to main menu
HMENU hmenuChart; // handle to Chart menu
// Load the pie, line, and bar chart bitmaps from the
// resource-definition file.
hbmpPie = LoadBitmap(hinst, MAKEINTRESOURCE(PIE));
hbmpLine = LoadBitmap(hinst, MAKEINTRESOURCE(LINE));
hbmpBar = LoadBitmap(hinst, MAKEINTRESOURCE(BAR));
// Create the Chart menu and add it to the menu bar.
// Append the Pie, Line, and Bar menu items to the Chart
// menu.
hmenuMain = GetMenu(hwnd);
hmenuChart = CreatePopupMenu();
AppendMenu(hmenuMain, MF_STRING | MF_POPUP, (UINT) hmenuChart,
"Chart");
AppendMenu(hmenuChart, MF_BITMAP, IDM_PIE, (LPCTSTR) hbmpPie);
AppendMenu(hmenuChart, MF_BITMAP, IDM_LINE,
(LPCTSTR) hbmpLine);
AppendMenu(hmenuChart, MF_BITMAP, IDM_BAR, (LPCTSTR) hbmpBar);
return;
}
VOID MakeLineMenu(HWND hwnd, HPEN phpen, HBITMAP phbmp)
{
HMENU hmenuLines; // handle to Lines menu
HMENU hmenu; // handle to main menu
COLORREF crMenuClr; // menu-item background color
HBRUSH hbrBackground; // handle to background brush
HBRUSH hbrOld; // handle to previous brush
WORD wLineX; // width of line bitmaps
WORD wLineY; // height of line bitmaps
HDC hdcMain; // handle to main window's DC
HDC hdcLines; // handle to compatible DC
HBITMAP hbmpOld; // handle to previous bitmap
int i; // loop counter
// Create the Lines menu. Add it to the menu bar.
hmenu = GetMenu(hwnd);
hmenuLines = CreatePopupMenu();
AppendMenu(hmenu, MF_STRING | MF_POPUP,
(UINT) hmenuLines, "&Lines");
// Create a brush for the menu-item background color.
crMenuClr = GetSysColor(COLOR_MENU);
hbrBackground = CreateSolidBrush(crMenuClr);
// Create a compatible device context for the line bitmaps,
// and then select the background brush into it.
hdcMain = GetDC(hwnd);
hdcLines = CreateCompatibleDC(hdcMain);
hbrOld = SelectObject(hdcLines, hbrBackground);
// Get the dimensions of the check-mark bitmap. The width of
// the line bitmaps will be five times the width of the
// check-mark bitmap.
wLineX = GetSystemMetrics(SM_CXMENUCHECK) * (WORD) 5;
wLineY = GetSystemMetrics(SM_CYMENUCHECK);
// Create the bitmaps and select them, one at a time, into the
// compatible device context. Initialize each bitmap by
// filling it with the menu-item background color.
for (i = 0; i < CPENS; i++)
{
phbmp[i] = CreateCompatibleBitmap(hdcMain, wLineX, wLineY);
if (i == 0)
hbmpOld = SelectObject(hdcLines, phbmp[i]);
else
SelectObject(hdcLines, phbmp[i]);
ExtFloodFill(hdcLines, 0, 0, crMenuClr, FLOODFILLBORDER);
}
// Create the pens.
phpen[0] = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
phpen[1] = CreatePen(PS_DOT, 1, RGB(0, 0, 0));
phpen[2] = CreatePen(PS_DASH, 1, RGB(0, 0, 0));
phpen[3] = CreatePen(PS_DASHDOT, 1, RGB(0, 0, 0));
phpen[4] = CreatePen(PS_DASHDOTDOT, 1, RGB(0, 0, 0));
// Select a pen and a bitmap into the compatible device
// context, draw a line into the bitmap, and then append
// the bitmap as an item in the Lines menu.
for (i = 0; i < CPENS; i++)
{
SelectObject(hdcLines, phbmp[i]);
SelectObject(hdcLines, phpen[i]);
MoveToEx(hdcLines, 0, wLineY / 2, NULL);
LineTo(hdcLines, wLineX, wLineY / 2);
AppendMenu(hmenuLines, MF_BITMAP, i + 1,
(LPCTSTR) phbmp[i]);
}
// Release the main window's device context and destroy the
// compatible device context. Also, destroy the background
// brush.
ReleaseDC(hwnd, hdcMain);
SelectObject(hdcLines, hbrOld);
DeleteObject(hbrBackground);
SelectObject(hdcLines, hbmpOld);
DeleteDC(hdcLines);
return;
}