[Visual C] 기본 win32api view형태 제작

/*
* @Project  : Black Board Project
* @Architecture : Kim Bom
* winmain.c
*
* @Created by KimBom On 2015. 10. 09...
* @Copyright (C) 2015 KimBom. All rights reserved.
*/
#include
#include 
POINT point[1000][100000] = { 0 };  //painting point matrix
COLORREF colors[1000] = { 0 };   //line colors
int row[1000] = { 0 };     //count of point
int col = 0;       //count of line
BOOL clk = FALSE;      //is click mouse left button click
COLORREF color = RGB(255, 255, 255); //default color
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE instance, HINSTANCE preInstance, LPSTR lrowCmd, int nCmdShow) {
	static char* title = "BlackBoard";
	HWND hWnd;
	MSG msg;
	WNDCLASS wndClass = { CS_HREDRAW | CS_VREDRAW, WndProc, 0, 0, instance, LoadIcon(NULL, IDC_ICON), LoadCursor(NULL, IDC_ARROW), GetStockObject(WHITE_BRUSH), NULL, title };
	HMENU hMenu = CreateMenu();
	HMENU hPopupMenu = CreateMenu();
	AppendMenu(hPopupMenu, MF_STRING, 100, "Red");
	AppendMenu(hPopupMenu, MF_STRING, 101, "Green");
	AppendMenu(hPopupMenu, MF_STRING, 102, "Blue");
	AppendMenu(hPopupMenu, MF_STRING, 103, "White");
	AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hPopupMenu, "Color");
	hPopupMenu = CreateMenu();
	AppendMenu(hPopupMenu, MF_STRING, 200, "New");
	AppendMenu(hPopupMenu, MF_STRING, 201, "Info");
	AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hPopupMenu, "Help");
	RegisterClass(&wndClass);
	hWnd = CreateWindow(title, title, WS_OVERLAPPEDWINDOW, 500, 500, 500, 500, NULL, hMenu, instance, NULL);
	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);
	while (GetMessage(&msg, NULL, 0, 0)) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
	PAINTSTRUCT ps;
	HDC hdc;
	RECT rect;
	int i;
	GetClientRect(hWnd, &rect);
	switch (msg) {
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		HDC memDC = CreateCompatibleDC(hdc);
		HBITMAP bmpBuffer = CreateCompatibleBitmap(hdc, rect.right, rect.bottom);
		HBITMAP pBitmap = (HBITMAP)SelectObject(memDC, bmpBuffer);
		PatBlt(memDC, 0, 0, rect.right, rect.bottom, BLACKNESS);
		for (i = 0; i <= col; i++) {
			HPEN pen = CreatePen(PS_SOLID, 1, colors[i]);
			HPEN oldPen = (HPEN)SelectObject(memDC, pen);
			Polyline(memDC, point[i], row[i]);
			SelectObject(memDC, oldPen);
			DeleteObject(pen);
		}
		BitBlt(hdc, 0, 0, rect.right, rect.bottom, memDC, 0, 0, SRCCOPY);
		SelectObject(memDC, pBitmap);
		DeleteDC(memDC);
		DeleteObject(bmpBuffer);
		EndPaint(hWnd, &ps);
		break;
	case WM_LBUTTONDOWN:clk = TRUE; colors[col] = color; break;
	case WM_LBUTTONUP:clk = FALSE; col++; break;
	case WM_MOUSEMOVE:
		if (clk) {
			point[col][row[col]].x = LOWORD(lParam);
			point[col][row[col]++].y = HIWORD(lParam);
			InvalidateRect(hWnd, &rect, TRUE);
		}break;
	case WM_ERASEBKGND:
		return TRUE;
	case WM_DESTROY:
		PostQuitMessage(0);
		return TRUE;
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case 100:color = RGB(255, 80, 69); break;
		case 101:color = RGB(145, 255, 108); break;
		case 102:color = RGB(136, 168, 255); break;
		case 103:color = RGB(255, 255, 255); break;
		case 200:col = 0; memset(row, 0, sizeof(row)); break;
		case 201:MessageBox(hWnd, "Created by kimbom", "Developer", MB_OK); break;
		}
		InvalidateRect(hWnd, &rect, TRUE);
	}
	return DefWindowProc(hWnd, msg, wParam, lParam);
}