#include <windows.h> LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); HINSTANCE g_hInst;
LPCTSTR lpszClass = TEXT("KKIMSSI"); // 창 제목
enum{ ID_R1 = 101, ID_R2, ID_R3, ID_R4, ID_R5, ID_R6, };
HWND r1; HWND r2; HWND r3; HWND r4; HWND r5; HWND r6;
int Graph = 0; COLORREF Color = RGB(0,0,0);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow) // WinMain , API Main 함수 { // nCmdShow 인자의 갯수가 온다 HWND hWnd; // Window Handler // LPSTR 는 char * 배열 C의 main 의 2번째 인자 MSG Message; WNDCLASS WndClass; /* 1. 윈도우 구조체 생성 ( Class ) */ g_hInst = hInstance;
/* 2.1 구조체에 값을 넣어 스타일을 변화시켜준다 */ WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0; WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // 바탕색 WndClass.hCursor = LoadCursor(NULL, IDC_ARROW); // 마우스 모양 WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); WndClass.hInstance = hInstance; WndClass.lpfnWndProc = WndProc; WndClass.lpszClassName = lpszClass; WndClass.lpszMenuName = NULL; WndClass.style = CS_HREDRAW|CS_VREDRAW; /* 2.2 앞에 모든 Class 값을 등록시켜주는 함수 */ RegisterClass(&WndClass);
/* 3. 창 만들기 */ hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, NULL,(HMENU)NULL,hInstance,NULL); /* 4. 창을 화면에 출력 하는 함수 */ ShowWindow(hWnd,nCmdShow);
/* 5. 창에서 일어나는 메세지 처리 (클릭, 닫기 등등..) */ while(GetMessage(&Message,NULL,0,0)) { TranslateMessage(&Message); DispatchMessage(&Message); } return (int)Message.wParam; }
/* 마우스나 키보드를 움직이면 OS 에서 자동으로 호출 */ /* 메세지 처리는 여기서 처리된다 */ LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; HBRUSH MyBrush; HBRUSH OldBrush; HPEN MyPen; HPEN OldPen;
switch(iMessage) { case WM_CREATE: CreateWindow(TEXT("button"),TEXT("Graph"),WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 5, 5,120, 110, hWnd, (HMENU)0, g_hInst, NULL); CreateWindow(TEXT("button"),TEXT("Color"),WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 145, 5,120, 110, hWnd, (HMENU)1, g_hInst, NULL); r1 = CreateWindow(TEXT("button"),TEXT("Rectangle"),WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON | WS_GROUP, 10, 20,100, 30, hWnd, (HMENU)ID_R1, g_hInst, NULL); r2 = CreateWindow(TEXT("button"),TEXT("Ellipse"),WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON, 10, 50,100, 30, hWnd, (HMENU)ID_R2, g_hInst, NULL); r3 = CreateWindow(TEXT("button"),TEXT("Line"),WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON, 10, 80,100, 30, hWnd, (HMENU)ID_R3, g_hInst, NULL); r4 = CreateWindow(TEXT("button"),TEXT("Black"),WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON, 150, 20,100, 30, hWnd, (HMENU)ID_R4, g_hInst, NULL); r5 = CreateWindow(TEXT("button"),TEXT("Red"),WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON, 150, 50,100, 30, hWnd, (HMENU)ID_R5, g_hInst, NULL); r6 = CreateWindow(TEXT("button"),TEXT("Blue"),WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON, 150, 80,100, 30, hWnd, (HMENU)ID_R6, g_hInst, NULL); CheckRadioButton(hWnd,ID_R1, ID_R3, ID_R1); CheckRadioButton(hWnd,ID_R4, ID_R6, ID_R4); break; case WM_COMMAND: switch (LOWORD(wParam)) { case ID_R1: Graph = 0; break; case ID_R2: Graph = 1; break; case ID_R3: Graph = 2; break; case ID_R4: Color = RGB(0,0,0); break; case ID_R5: Color = RGB(255,0,0); break; case ID_R6: Color = RGB(0,0,255); break; } InvalidateRect(hWnd,NULL,TRUE); return 0; case WM_PAINT: hdc = BeginPaint(hWnd,&ps); MyBrush = CreateSolidBrush(Color); // GDI 오브젝트를 위에서 정해준 RGB 값으로 저장한 후 출력 ( 도형 ) OldBrush = (HBRUSH)SelectObject(hdc,MyBrush); MyPen = CreatePen(PS_SOLID,1,Color); // GDI 오브젝트를 위에서 정해준 RGB 값으로 저장한 후 출력 ( 도선 ) OldPen = (HPEN)SelectObject(hdc,MyPen); switch (Graph) { case 0 : Rectangle(hdc, 10, 200, 200, 300); break; case 1 : Ellipse(hdc,10, 200, 200 ,300 ); break; case 2 : MoveToEx(hdc,10,200,NULL); LineTo(hdc,200,300); break; } SelectObject(hdc,OldBrush); SelectObject(hdc,OldPen); DeleteObject(MyBrush); DeleteObject(MyPen); EndPaint(hWnd,&ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return(DefWindowProc(hWnd,iMessage,wParam,lParam)); }
|