Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
API_lab_Гребенюк(всі лістинги л_р).doc
Скачиваний:
0
Добавлен:
01.07.2025
Размер:
416 Кб
Скачать
☆

Лабораторна робота 5

«main.cpp»

#include <windows.h>

#include <string.h>

#include <iostream>

#include <cstring>

using namespace std;

void viewFormatText(LOGFONT lf, HFONT hFont, HDC hdc, string titleFont, bool italic, bool strike, bool underline,

int width, int height, int weight, int escapment ){

char Mass[100];

strcpy( Mass, titleFont.c_str() );

strcpy(lf.lfFaceName,Mass);

lf.lfHeight=height;

lf.lfItalic=italic;

lf.lfStrikeOut=strike;

lf.lfUnderline=underline;

lf.lfWidth=width;

lf.lfWeight=weight;

lf.lfCharSet=DEFAULT_CHARSET;

lf.lfPitchAndFamily=DEFAULT_PITCH;

lf.lfEscapement=escapment;

hFont = CreateFontIndirect(&lf);

SelectObject(hdc, hFont);

}

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[] = "ICON2";

char szCursorName[] = "CURSOR1";

char image_2[]={"IDB_2"}; //

char image_5[]={"IDB_5"}; //

char image_10[]={"IDB_10"}; //

char image_add[]={"IDB_add_image"};

HBITMAP hBitmap_2,hBitmap_5,hBitmap_10, hBitmap_addImage;

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;

LOGFONT lf;

HFONT hFont;

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(100,0,0));

SetBkMode(hdc, TRANSPARENT);

viewFormatText(lf,hFont,hdc,"Times New Roman",false,false, false, 15,20,15, -900);

TextOut (hdc,20,60,"Гребенюк Іван Андрійович",strLength("Гребенюк Іван Андрійович"));

viewFormatText(lf,hFont,hdc,"Batang",false,true, false, 10,25,10,50);

TextOut (hdc,20,30,"Двойка бубна",strLength("Двойка бубна"));

SetTextColor(hdc, RGB(0,250,0));

viewFormatText(lf,hFont,hdc,"Consolas",false,false, true, 16,25,30,-30);

TextOut (hdc,220,2,"Хрестова",strLength("Хрестова"));

viewFormatText(lf,hFont,hdc,"Consolas",false,false, true, 10,20,30,-10);

TextOut (hdc,320,30,"п'ятірка",strLength("п'ятірка"));

SetBkMode(hdc, OPAQUE);

viewFormatText(lf,hFont,hdc,"Segoe UI Semibold",true,true, true, 10,20,20,0);

TextOut (hdc,480,30,"Піка 10",strLength("Піка 10"));

SetTextColor(hdc, RGB(255,255,255));

SetBkMode(hdc, TRANSPARENT);

viewFormatText(lf,hFont,hdc,"Segoe UI Semibold",false,true, true, 15,20,20,0);

TextOut (hdc,680,35,"Бубна 2",strLength("Піка 10"));

SetTextColor(hdc, RGB(50,100,150));

viewFormatText(lf,hFont,hdc,"Verdana",false,false, true, 15,50,20,0);

TextOut (hdc,880,10,"Hrestova 5",strLength("Hrestova 5"));

SetTextColor(hdc, RGB(150,200,150));

viewFormatText(lf,hFont,hdc,"Verdana",true,true, true, 15,30,20,0);

TextOut (hdc,1080,10,"10 Pika",strLength("10 Pika"));

SetBkMode(hdc, OPAQUE);

SetTextColor(hdc, RGB(150,200,150));

viewFormatText(lf,hFont,hdc,"Verdana",true,true, true, 50,100,100,150);

TextOut (hdc,100,550,"Санта",strLength("Санта"));

SetBkMode(hdc, TRANSPARENT);

SetTextColor(hdc, RGB(238,233,233));//238 233 233

viewFormatText(lf,hFont,hdc,"Arial",false,false, false, 50,100,100,-170);

TextOut (hdc,800,480,"Клаус",strLength("Клаус"));

int pxLeft = 10;

imageView(hdc, hmdc,hBitmap_2,bm,SRCCOPY,10+pxLeft,60);

imageView(hdc, hmdc,hBitmap_5,bm,SRCCOPY,220+pxLeft,60);

imageView(hdc, hmdc,hBitmap_10,bm,SRCCOPY,430+pxLeft,60);

imageView(hdc, hmdc,hBitmap_2,bm,NOTSRCCOPY,pxLeft+430+210*1,60);

imageView(hdc, hmdc,hBitmap_5,bm,NOTSRCCOPY,pxLeft+430+210*2,60);

imageView(hdc, hmdc,hBitmap_10,bm,NOTSRCCOPY,pxLeft+430+210*3,60);

imageView(hdc, hmdc,hBitmap_addImage,bm,SRCCOPY,pxLeft+570,500);

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);

hBitmap_addImage = LoadBitmap(hInstance, image_add);

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 5 lab", "Error of create window!",

MB_ICONSTOP | MB_OK);

return 0;

}

hwnd = CreateWindowEx(

WS_EX_CLIENTEDGE,

g_szClassName,

"Гребенюк Іван 5 лаб ПЗС-1644",

WS_SYSMENU,

10, 30, 1280, 700,

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"

IDB_add_image BITMAP "add_imge1.bmp"

ICON2 ICON "icon7.ico"

CURSOR1 CURSOR "main_cur.cur"