[API] Project : SimplePaint v4.0

simpled 2013.06.23 15:57 조회 수 : 6040

2011.06.07 SimplePaint_v4.0.exe


/*

버튼 : 그리기버튼

콤보박스: 두께, 윈도우 창 이름 변경

스크롤바 : 색상

 

목표 : 20분

경과시간 : 50분

 

다이얼로그는 리소스 편집기로 했다...

 

*/

 

BOOL bDrawMode;

COLORREF coMainColor;

INT iPenWidth, iRed, iGreen, iBlue;

 

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

{

        int wmId, wmEvent;

        PAINTSTRUCT ps;

        HDC hdc;

        static HPEN MyPen, OldPen;

        static BOOL bLBdown;

        static POINT poSpline;

 

 

        switch (message)

        {

               case WM_CREATE:

                       bDrawMode=FALSE;

                       iPenWidth=1;

                       coMainColor=RGB(0, 0, 0);

                       CreateWindow(TEXT("button"), TEXT("EDIT"),

                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,

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

                       break;

                case WM_LBUTTONDOWN:

                       bLBdown=TRUE;

                       poSpline.x=LOWORD(lParam);

                       poSpline.y=HIWORD(lParam);

                       break;

               case WM_MOUSEMOVE:

                       if(bLBdown)

                       {

                              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:

                       bLBdown=FALSE;

                       bDrawMode=FALSE;

                       break;

               case WM_COMMAND:

                       wmId    = LOWORD(wParam);

                       wmEvent = HIWORD(wParam);

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

                       switch (wmId)

                       {

                              case ID_BTN_DRAW:

                                      DialogBox(hInst, MAKEINTRESOURCE(IDD_OPTION), hWnd, Option);

                                      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_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;

}

 

 

INT_PTR CALLBACK Option(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)

{

        int wmId, wmEvent;

        PAINTSTRUCT ps;

        HDC hdc;

 

        switch (message)

        {

               case WM_INITDIALOG:

                       bDrawMode=TRUE;

                       SetDlgItemInt(hDlg, ID_RED, iRed, FALSE);

                       SetDlgItemInt(hDlg, ID_GREEN, iGreen, FALSE);

                       SetDlgItemInt(hDlg, ID_BLUE, iBlue, FALSE);

                       SetDlgItemInt(hDlg, ID_WIDTH, iPenWidth, FALSE);

                       return (INT_PTR)TRUE;

               case WM_COMMAND:

                       wmId    = LOWORD(wParam);

                       wmEvent = HIWORD(wParam);

                       switch(wmId)

                       {

                              case ID_RED:

                                      switch(wmEvent)

                                      {

                                             case EN_CHANGE:

                                                     iRed=GetDlgItemInt(hDlg, ID_RED, NULL, FALSE);

                                                     if(iRed<0)

                                                             iRed=0;

                                                     else if(iRed>255)

                                                             iRed=255;

                                                     break;

                                      }

                                      break;

                              case ID_GREEN:

                                      switch(wmEvent)

                                      {

                                             case EN_CHANGE:

                                                     iGreen=GetDlgItemInt(hDlg, ID_GREEN, NULL, FALSE);

                                                     if(iGreen<0)

                                                             iGreen=0;

                                                     else if(iGreen>255)

                                                             iGreen=255;

                                                     break;

                                      }

                                      break;

                              case ID_BLUE:

                                      switch(wmEvent)

                                      {

                                             case EN_CHANGE:

                                                     iBlue=GetDlgItemInt(hDlg, ID_BLUE, NULL, FALSE);

                                                     if(iBlue<0)

                                                             iBlue=0;

                                                     else if(iBlue>255)

                                                             iBlue=255;

                                                     break;

                                      }

                                      break;

                              case ID_WIDTH:

                                      switch(wmEvent)

                                      {

                                             case EN_CHANGE:

                                                     iPenWidth=GetDlgItemInt(hDlg, ID_WIDTH, NULL, FALSE);

                                                     if(iPenWidth<0)

                                                             iPenWidth=0;

                                                     else if(iPenWidth>4)

                                                             iPenWidth=4;

                                                     break;

                                      }

                                      break;

                              case IDOK:

                              case ID_OK:

                              case IDCANCEL:

                              case ID_CANCEL:

                                     

                                      coMainColor=RGB(iRed, iGreen, iBlue);

                                      EndDialog(hDlg, LOWORD(wParam));

                                      return (INT_PTR)TRUE;

                                      break;

                              default:

                                      DefWindowProc(hDlg, message, wParam, lParam);

                                      break;

                       }

        }

        return (INT_PTR)FALSE;

}