Лабораторна робота 4
«main.cpp»
#include <windows.h>
void imageView(HDC hdc, HDC hmdc,HBITMAP hB,BITMAP bmt,DWORD dw,int ofLeft, int ofHeight){
hmdc=CreateCompatibleDC(hdc);
SelectObject(hmdc, hB);
GetObject(hB, sizeof(bmt), (LPSTR) &bmt);
BitBlt(hdc, ofLeft,ofHeight, bmt.bmWidth, bmt.bmHeight, hmdc, 5,5, dw);
DeleteDC(hmdc);
}
HWND b1;
char szIconName[] = "ICON1";
char szCursorName[] = "CURSOR1";
char image_2[]={"IDB_2"};
char image_5[]={"IDB_5"};
char image_10[]={"IDB_10"};
HBITMAP hBitmap_2,hBitmap_5,hBitmap_10;
BITMAP bm;
const char g_szClassName[] = "myWindowClass";
int strLength(const char* str)
{
int size = 0;
while(*str++) ++size;
return size;
}
char text1[]={"Виберіть будь-яку карту"};
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hdc, hmdc;
PAINTSTRUCT ps;
switch(msg)
{
case WM_CREATE:
b1 = CreateWindow("BUTTON", " Системний курсор",WS_VISIBLE|WS_CHILD|WS_BORDER,500,3,200,30,
hwnd, (HMENU) 1, NULL, NULL);
break;
case WM_COMMAND:
switch(LOWORD(wParam)){
case 1: SetClassLong(hwnd,GCL_HCURSOR,(LONG) LoadCursor(NULL, MAKEINTRESOURCE(NULL)));
break;
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
{
hdc = BeginPaint (hwnd, &ps);
SetTextColor(hdc, RGB(0,250,0));
SetBkMode(hdc, TRANSPARENT);
TextOut (hdc,
520,
30,
text1,
strLength(text1));
imageView(hdc, hmdc,hBitmap_2,bm,SRCCOPY,10,60);
imageView(hdc, hmdc,hBitmap_5,bm,SRCCOPY,220,60);
imageView(hdc, hmdc,hBitmap_10,bm,SRCCOPY,430,60);
imageView(hdc, hmdc,hBitmap_2,bm,NOTSRCCOPY,430+210*1,60);
imageView(hdc, hmdc,hBitmap_5,bm,NOTSRCCOPY,430+210*2,60);
imageView(hdc, hmdc,hBitmap_10,bm,NOTSRCCOPY,430+210*3,60);
EndPaint (hwnd, &ps);
}
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
hBitmap_2=LoadBitmap(hInstance, image_2);
hBitmap_5=LoadBitmap(hInstance, image_5);
hBitmap_10=LoadBitmap(hInstance, image_10);
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, szIconName);
wc.hCursor = LoadCursor(hInstance, szCursorName);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, szIconName);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Grebenuk Ivan 4 lab", "Error of create window!",
MB_ICONSTOP | MB_OK);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Гребенюк Іван 4 лаб ПЗС-1644",
WS_SYSMENU,
10, 30, 1280, 500,
NULL, NULL, hInstance, NULL);
HBRUSH brush = CreateSolidBrush(RGB(112, 121, 205));//162 181 205
SetClassLongPtr(hwnd, GCLP_HBRBACKGROUND, (LONG)brush);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
«res.rc»
IDB_2 BITMAP "2.bmp"
IDB_5 BITMAP "5.bmp"
IDB_10 BITMAP "10.bmp"
ICON1 ICON "blood.ico"
ICON2 ICON "icon7.ico"
CURSOR1 CURSOR "main_cur.cur"
