Skip to content

Instantly share code, notes, and snippets.

@yongjun823
Created April 30, 2018 13:58
Show Gist options
  • Select an option

  • Save yongjun823/9596afbe2461be541cb09e7c55d6e83f to your computer and use it in GitHub Desktop.

Select an option

Save yongjun823/9596afbe2461be541cb09e7c55d6e83f to your computer and use it in GitHub Desktop.
mfc example pen color & bold controll
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
POINTS pt;
static int x;
static int y;
static bool isDraw = false;
static int select_color = RGB(0, 0, 0);
static auto point_size = 1;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// 메뉴 선택을 구문 분석합니다.
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
// color
case ID_Red:
select_color = RGB(255, 0, 0);
break;
case ID_Green:
select_color = RGB(0, 255, 0);
break;
case ID_Blue:
select_color = RGB(0, 0, 255);
break;
case ID_Black:
select_color = RGB(0, 0, 0);
break;
// bold
case ID_1Point:
point_size = 1;
break;
case ID_3Point:
point_size = 3;
break;
case ID_5Point:
point_size = 5;
break;
// clear
case ID_Clear:
InvalidateRect(hWnd, NULL, TRUE);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 여기에 그리기 코드를 추가합니다.
EndPaint(hWnd, &ps);
break;
case WM_LBUTTONDOWN:
pt = MAKEPOINTS(lParam);
x = pt.x;
y = pt.y;
isDraw = true;
break;
case WM_MOUSEMOVE:
if(isDraw)
{
hdc = GetDC(hWnd);
MoveToEx(hdc, x, y, NULL);
pt = MAKEPOINTS(lParam);
x = pt.x;
y = pt.y;
const auto hpen = CreatePen(PS_SOLID, point_size, select_color);
const auto hbrush = CreateSolidBrush(select_color);
SelectObject(hdc, hpen);
SelectObject(hdc, hbrush);
SetDCPenColor(hdc, select_color);
LineTo(hdc, x, y);
DeleteObject(hpen);
DeleteObject(hbrush);
ReleaseDC(hWnd, hdc);
break;
}
break;
case WM_LBUTTONUP:
isDraw = false;
break;
case WM_LBUTTONDBLCLK: // 윈도우 스타일 지정 CS_DBLCLKS
InvalidateRect(hWnd, NULL, true);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment