// NewHello.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
HDC memDC, hDC;
HBITMAP memBM;
int winWidth, winHeight, left, right, top, bottom;
//RECT sRect;
void AddSegmentAtMessagePos(HDC hDC, HWND hwnd, BOOL bDraw){
DWORD dwPos;
POINTS points;
POINT point;
dwPos = GetMessagePos();
points = MAKEPOINTS(dwPos);
point.x = points.x;
point.y = points.y;
ScreenToClient(hwnd, &point);
DPtoLP(memDC, &point, 1);
if (bDraw) LineTo(memDC, point.x, point.y);
else MoveToEx(memDC, point.x, point.y, NULL);
}
void DrawHello(HWND hwnd){
MSG msg;
if (GetCapture() != NULL) return;
if (memDC != NULL){
SetCapture(hwnd);
AddSegmentAtMessagePos(memDC, hwnd, FALSE);
while(GetMessage(&msg, NULL, 0, 0)){
if(GetCapture() != hwnd) break;
switch (msg.message){
case WM_MOUSEMOVE:
AddSegmentAtMessagePos(memDC, hwnd, TRUE);
break;
case WM_LBUTTONUP:
goto ExitLoop;
default:
DispatchMessage(&msg);
}
}
ExitLoop:
ReleaseCapture();
//ReleaseDC(hwnd, hDC);
}
}
void PageFlip(HWND hwnd){
BitBlt(hDC, left, top, right, bottom, memDC, left, top, SRCCOPY);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
switch(uMsg){
case WM_LBUTTONDOWN:
DrawHello(hwnd);
break;
case WM_PAINT:
PageFlip(hwnd);
break;
case WM_DESTROY:
ReleaseCapture();
ReleaseDC(hwnd, hDC);
DeleteDC(hDC);
DeleteDC(memDC);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
// TODO: Place code here.
MSG msg;
HWND hwnd;
WNDCLASS wndClass;
if(hPrevInstance == NULL){
memset(&wndClass, 0, sizeof(wndClass));
wndClass.style = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = WndProc;
wndClass.hInstance = hInstance;
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW +1);
wndClass.lpszClassName = "HELLO";
if(!RegisterClass(&wndClass)){
return false;
}
}
hwnd = CreateWindow("HELLO", "ECTHA SKETCH", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
//Create window DC
hDC = GetDC(hwnd);
//Find window width and height
RECT sRect;
GetWindowRect(hwnd, &sRect);
winWidth = sRect.right - sRect.left;
winHeight = sRect.bottom - sRect.top;
left = sRect.left;
right = sRect.right;
top = sRect.top;
bottom = sRect.bottom;
//Create a compatible memory device context
memDC = CreateCompatibleDC(hDC);
//Create Memory Bitmap
memBM = CreateCompatibleBitmap(hDC, winWidth, winHeight);
while(GetMessage(&msg, NULL, 0, 0)){
DispatchMessage(&msg);
}
return msg.wParam;
}
The bank."