Лабораторна робота 6
«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);
SetTextColor(hdc, RGB(0,0,0));
}
HWND b1;
char szIconName[] = "ICON2";
char szCursorName[] = "CURSOR1";
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(0,250,0));
SetBkMode(hdc, TRANSPARENT);
TextOut (hdc,520,30,text1,strLength(text1));
HPEN hPen1=CreatePen(PS_DASH, 3, RGB(0,0,0));
SelectObject(hdc, hPen1);
/**/HBRUSH NewBrush = CreateSolidBrush(RGB(255, 0, 0));
SelectObject(hdc, NewBrush);
Ellipse(hdc, 150,150,400,400);
/**/HBRUSH NewBrush_2 = CreateSolidBrush(RGB(255, 255, 0));
SelectObject(hdc, NewBrush_2);
hPen1=CreatePen(PS_DASH, 4, RGB(255,0,0));
SelectObject(hdc, hPen1);
Ellipse(hdc, 450,300,800,400);
RECT r_1;
r_1.left=750;
r_1.top=100;
r_1.right=1100;
r_1.bottom=250;
FillRect(hdc, &r_1, (HBRUSH)CreateSolidBrush(RGB(238,130,238)));
HBRUSH hBrush=CreateHatchBrush(HS_BDIAGONAL, RGB(255,255,255));
SelectObject(hdc,hBrush);
HPEN hPen2=CreatePen(PS_DASHDOT, 1, RGB(255,140,0));
RECT r;
r.left=10;
r.top=70;
r.right=200;
r.bottom=150;
FillRect(hdc, &r, (HBRUSH)CreateSolidBrush(RGB(30,144,255)));//30 144 255
SelectObject(hdc, hPen2);
Rectangle(hdc, 10,70,200,150);
ValidateRect(hwnd, NULL);
viewFormatText(lf,hFont,hdc,"Batang",false,false, false, 10,25,10,900);
TextOut (hdc,50,170,"Прямокутник",strLength("Прямокутник"));
viewFormatText(lf,hFont,hdc,"Batang",true,false, true, 16,25,10,900);
TextOut (hdc,250,300,"Коло",strLength("Коло"));
viewFormatText(lf,hFont,hdc,"Arial",false,false, true, 12,50,16,900);
TextOut (hdc,590,390,"Еліпс",strLength("Еліпс"));
viewFormatText(lf,hFont,hdc,"Times New Roman",true,false, false, 12,50,16,900);
TextOut (hdc,790,253,"Фіолетовий",strLength("Фіолетовий"));
viewFormatText(lf,hFont,hdc,"Times New Roman",true,false, false, 9,25,10,900);
TextOut (hdc,840,243,"прямокутник",strLength("прямокутник"));
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;
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(100, 100, 100));//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»
ICON2 ICON "icon7.ico"
CURSOR1 CURSOR "main_cur.cur"
