[API] Project : SimplePaint v1.0

simpled 2013.06.23 15:56 조회 수 : 6548

2011.06.06 Simple_v1.0.exe


/*

버튼 : 그리기버튼

체크박스 : 두께

라디오버튼 : 색상

목표 : 20분

결과 : 괜춘했음. 1시간안에 성공 가능.

*/

 

 

enum {BTN_DRAW=3000, ID_W1, ID_W2, ID_W3, ID_RED, ID_GREEN, ID_BLUE, ID_MOUSEPOS};

TCHAR *cW[]={TEXT("Width : 1"), TEXT("Width : 2"), TEXT("Width : 3")};

COLORREF coMainColor;

INT iPenWidth;

BOOL bLB, bDrawMode;

POINT poSPLINE;

HPEN MyPen, OldPen;

 

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

{

        int wmId, wmEvent;

        PAINTSTRUCT ps;

        HDC hdc;

       

 

        switch (message)

        {

               case WM_CREATE:

                       CreateWindow(TEXT("button"), TEXT("Draw"),

                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,

                              0, 0, 100, 30, hWnd, (HMENU)BTN_DRAW, hInst, NULL);

                       for(int iPoint=ID_W1, iActive=0; iPoint<=ID_W3; iPoint++, iActive++)

                       {

                              CreateWindow(TEXT("button"), cW[iActive],

                                      WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,

                                      0, 40+(20*iActive), 100, 20, hWnd, (HMENU)iPoint, hInst, NULL);

                       }

                       SendMessage(GetDlgItem(hWnd, ID_W1), BM_SETCHECK, BST_CHECKED, 0);

                       iPenWidth=1;

                       CreateWindow(TEXT("button"), TEXT("RED"),

                              WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON | WS_GROUP,

                              0, 100, 100, 20, hWnd, (HMENU)ID_RED, hInst, NULL);

                       CreateWindow(TEXT("button"), TEXT("GREEN"),

                              WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,

                              0, 120, 100, 20, hWnd, (HMENU)ID_GREEN, hInst, NULL);

                       CreateWindow(TEXT("button"), TEXT("BLUE"),

                              WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,

                              0, 140, 100, 20, hWnd, (HMENU)ID_BLUE, hInst, NULL);

                       CheckRadioButton(hWnd, ID_RED, ID_GREEN, ID_RED);

                       coMainColor=RGB(255, 0, 0);

 

                       CreateWindow(TEXT("static"), TEXT("마우스위치"),

                              WS_CHILD | WS_VISIBLE,

                              0, 200, 100, 20, hWnd, (HMENU)ID_MOUSEPOS, hInst, NULL);

                       break;

 

               case WM_COMMAND:

                       wmId    = LOWORD(wParam);

                       wmEvent = HIWORD(wParam);

                       // 메뉴의선택영역을구문분석합니다.

                       switch (wmId)

                       {

                              case BTN_DRAW:

                                      if(bDrawMode)

                                             bDrawMode=FALSE;

                                      else

                                             bDrawMode=TRUE;

                                      break;

                              case ID_RED:

                                      coMainColor=RGB(255, 0, 0);

                                      break;

                              case ID_GREEN:

                                      coMainColor=RGB(0, 255, 0);

                                      break;

                              case ID_BLUE:

                                      coMainColor=RGB(0, 0, 255);

                                      break;

                              case ID_W1:

                              case ID_W2:

                              case ID_W3:

                                      iPenWidth=wmId-ID_W1+1;

                                      for(int iPoint=ID_W1; iPoint<=ID_W3; iPoint++)

                                      {

                                             if(iPoint==wmId) continue;

                                             SendMessage(GetDlgItem(hWnd, iPoint), BM_SETCHECK, BST_UNCHECKED, 0);

                                      }

                                      break;

                              case IDM_ABOUT:

                                      DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);

                                      break;

                              case IDM_EXIT:

                                      DestroyWindow(hWnd);

                                      break;

                              default:

                                      return DefWindowProc(hWnd, message, wParam, lParam);

                       }

                       break;

               case WM_LBUTTONDOWN:

                       bLB=TRUE;

                       poSPLINE.x=LOWORD(lParam);

                       poSPLINE.y=HIWORD(lParam);

                       break;

               case WM_MOUSEMOVE:

                       if(bDrawMode==TRUE && bLB==TRUE)

                       {

                              hdc=GetDC(hWnd);

                              MyPen=CreatePen(PS_SOLID, iPenWidth, coMainColor);

                              OldPen=(HPEN)SelectObject(hdc, MyPen);

 

                              MoveToEx(hdc, poSPLINE.x, poSPLINE.y, NULL);

                              poSPLINE.x=LOWORD(lParam);

                              poSPLINE.y=HIWORD(lParam);

                              LineTo(hdc, poSPLINE.x, poSPLINE.y);

 

                              SelectObject(hdc, OldPen);

                              DeleteObject(MyPen);

                              ReleaseDC(hWnd, hdc);

                       }

                       break;

               case WM_LBUTTONUP:

                       bLB=FALSE;

                       bDrawMode=FALSE;

                       break;

               case WM_PAINT:

                       hdc = BeginPaint(hWnd, &ps);

                       // TODO: 여기에그리기코드를추가합니다.

                       EndPaint(hWnd, &ps);

                       break;

 

               case WM_DESTROY:

                       PostQuitMessage(0);

                       break;

 

               default:

                       return DefWindowProc(hWnd, message, wParam, lParam);

        }

        return 0;

}