#include <windows.h>
#include "resource.h"
HINSTANCE g_hInstance = 0;
void DrawPit(HDC hdc)
{
for (int i = 0; i < 255; i++)
{
for (int j = 0; j < 255; j++)
{
SetPixel(hdc, i, j, RGB(255, i, j));
}
}
}
void DrawLine(HDC hdc)
{
MoveToEx(hdc, 100, 100,NULL);
LineTo(hdc, 300, 300);
LineTo(hdc, 400, 0);
LineTo(hdc, 100, 100);
}
void DrawRect(HDC hdc)
{
Rectangle(hdc, 100, 100, 300, 300);
}
void DrawEll(HDC hdc)
{
Ellipse(hdc, 100, 100, 300, 300);
}
void DrawBmp(HDC hdc)
{
HBITMAP hBmp = LoadBitmap(g_hInstance, (CHAR*)IDB_BITMAP1);
HDC hMemdc = CreateCompatibleDC(hdc);
HGDIOBJ nOldBmp = SelectObject(hMemdc, hBmp);
BitBlt(hdc, 50, 50, 48, 48, hMemdc, 0, 0, SRCCOPY);
StretchBlt(hdc, 200, 200, 100, 100, hMemdc, 0, 0, 48, 48, SRCCOPY);
SelectObject(hMemdc, nOldBmp);
DeleteObject(hBmp);
DeleteDC(hMemdc);
}
void OnPaint(HWND hWnd)
{
PAINTSTRUCT ps = { 0 };
HDC hdc = BeginPaint(hWnd, &ps);
HPEN hPen = CreatePen(PS_SOLID, 10, RGB(255, 0, 0));
HGDIOBJ nOldPen = SelectObject(hdc, hPen);
HGDIOBJ hBrush = GetStockObject(NULL_BRUSH);
HGDIOBJ nOldBrush = SelectObject(hdc, hBrush);
DrawEll(hdc);
DrawBmp(hdc);
SelectObject(hdc, nOldPen);
DeleteObject(hPen);
SelectObject(hdc, nOldBrush);
EndPaint(hWnd,&ps);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT msgID, WPARAM wParam, LPARAM lParam)
{
switch (msgID)
{
case WM_PAINT:
OnPaint(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, msgID, wParam, lParam);
}
int CALLBACK WinMain(HINSTANCE hIns, HINSTANCE hPreIns, LPSTR IpCmdLine, int nCmdShow)
{
g_hInstance = hIns;
WNDCLASS wc = { 0 };
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 2);
wc.hCursor = NULL;
wc.hIcon = NULL;
wc.hInstance = hIns;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = "Main";
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wc);
HWND hWnd = CreateWindowEx(0, "Main", "window", WS_OVERLAPPEDWINDOW, 100, 100, 500, 500, NULL, NULL, hIns, NULL);
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
MSG nMsg = { 0 };
while (GetMessage(&nMsg, NULL, 0, 0))
{
TranslateMessage(&nMsg);
DispatchMessage(&nMsg);
}
return 0;
}