From f2f389b77c1e61693b1de35c4f5049ffa71a163b Mon Sep 17 00:00:00 2001 From: Shulga Konstantin Date: Sun, 6 Sep 2020 13:43:49 +0300 Subject: [PATCH] feat: draw a picture in bmp format in the window --- Lab_1/Lab_1/Lab_1.cpp | 32 +++++++++++++- Lab_1/Lab_1/Lab_1.rc | 69 ++++++++++++++++++++++++++++++ Lab_1/Lab_1/Lab_1.vcxproj | 9 ++++ Lab_1/Lab_1/Lab_1.vcxproj.filters | 15 +++++++ Lab_1/Lab_1/bitmap1.bmp | Bin 0 -> 8310 bytes Lab_1/Lab_1/resource.h | 16 +++++++ 6 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 Lab_1/Lab_1/Lab_1.rc create mode 100644 Lab_1/Lab_1/bitmap1.bmp create mode 100644 Lab_1/Lab_1/resource.h diff --git a/Lab_1/Lab_1/Lab_1.cpp b/Lab_1/Lab_1/Lab_1.cpp index e046652..92ea0e9 100644 --- a/Lab_1/Lab_1/Lab_1.cpp +++ b/Lab_1/Lab_1/Lab_1.cpp @@ -1,8 +1,16 @@ #include #include +#include + +#include "resource.h"; + +typedef std::basic_string, + std::allocator > String; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); + TCHAR WinName[] = _T("Lab_1"); +HINSTANCE hInst; int APIENTRY _tWinMain(HINSTANCE This, HINSTANCE Prev, LPTSTR cmd, int mode) { @@ -21,7 +29,9 @@ int APIENTRY _tWinMain(HINSTANCE This, HINSTANCE Prev, LPTSTR cmd, int mode) wc.cbWndExtra = 0; // No extra window info. // Fill window with white color. - wc.hbrBackground = (HBRUSH)(WHITE_BRUSH); + wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + + hInst = This; // Class registration if (!RegisterClass(&wc)) @@ -54,8 +64,28 @@ int APIENTRY _tWinMain(HINSTANCE This, HINSTANCE Prev, LPTSTR cmd, int mode) // receives messages from the queue for this application. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { + PAINTSTRUCT ps; + HDC hdc; + HBITMAP hBitmap; + + static HDC memBitMap; + static BITMAP bm; + switch (message) { + case WM_CREATE: + hBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1)); + GetObject(hBitmap, sizeof(bm), &bm); + hdc = GetDC(hWnd); + memBitMap = CreateCompatibleDC(hdc); + SelectObject(memBitMap, hBitmap); + ReleaseDC(hWnd, hdc); + break; + case WM_PAINT: + hdc = BeginPaint(hWnd, &ps); + BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, memBitMap, 0, 0, SRCCOPY); + EndPaint(hWnd, &ps); + break; case WM_DESTROY: PostQuitMessage(0); break; diff --git a/Lab_1/Lab_1/Lab_1.rc b/Lab_1/Lab_1/Lab_1.rc new file mode 100644 index 0000000..38d855f --- /dev/null +++ b/Lab_1/Lab_1/Lab_1.rc @@ -0,0 +1,69 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Bitmap +// + +IDB_BITMAP1 BITMAP "bitmap1.bmp" + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/Lab_1/Lab_1/Lab_1.vcxproj b/Lab_1/Lab_1/Lab_1.vcxproj index 89692c7..b848882 100644 --- a/Lab_1/Lab_1/Lab_1.vcxproj +++ b/Lab_1/Lab_1/Lab_1.vcxproj @@ -141,6 +141,15 @@ + + + + + + + + + diff --git a/Lab_1/Lab_1/Lab_1.vcxproj.filters b/Lab_1/Lab_1/Lab_1.vcxproj.filters index 2954ba3..33c5184 100644 --- a/Lab_1/Lab_1/Lab_1.vcxproj.filters +++ b/Lab_1/Lab_1/Lab_1.vcxproj.filters @@ -19,4 +19,19 @@ Source Files + + + Header Files + + + + + Resource Files + + + + + Resource Files + + \ No newline at end of file diff --git a/Lab_1/Lab_1/bitmap1.bmp b/Lab_1/Lab_1/bitmap1.bmp new file mode 100644 index 0000000000000000000000000000000000000000..6f31407fca29d355a4b12d1c358773bcc5fa34d5 GIT binary patch literal 8310 zcmeIuu?@r^5ClLhxqvUhq3dw|?Kq|lcSC1*;c4QfIk@G7AerlXA7$2^JkxdcR`yJ( zW9E!ca`dn2dR*6^oVjYP<;+m}+@<$1rL)FW;!y+$5FkK+009C72oNAZfB*pk1PBly SK!5-N0t5&UAV7e?-wV8OT{v0* literal 0 HcmV?d00001 diff --git a/Lab_1/Lab_1/resource.h b/Lab_1/Lab_1/resource.h new file mode 100644 index 0000000..9d29ca6 --- /dev/null +++ b/Lab_1/Lab_1/resource.h @@ -0,0 +1,16 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Lab_1.rc +// +#define IDB_BITMAP1 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif