Skip to content

Commit

Permalink
feat: draw a picture in bmp format in the window
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKonstantinSh committed Sep 6, 2020
1 parent 2ce4309 commit f2f389b
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 1 deletion.
32 changes: 31 additions & 1 deletion Lab_1/Lab_1/Lab_1.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#include <Windows.h>
#include <tchar.h>
#include <xstring>

#include "resource.h";

typedef std::basic_string<TCHAR, std::char_traits<TCHAR>,
std::allocator<TCHAR> > 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)
{
Expand All @@ -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))
Expand Down Expand Up @@ -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;
Expand Down
69 changes: 69 additions & 0 deletions Lab_1/Lab_1/Lab_1.rc
Original file line number Diff line number Diff line change
@@ -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

9 changes: 9 additions & 0 deletions Lab_1/Lab_1/Lab_1.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@
<ItemGroup>
<ClCompile Include="Lab_1.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Lab_1.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="bitmap1.bmp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
15 changes: 15 additions & 0 deletions Lab_1/Lab_1/Lab_1.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,19 @@
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Lab_1.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="bitmap1.bmp">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>
Binary file added Lab_1/Lab_1/bitmap1.bmp
Binary file not shown.
16 changes: 16 additions & 0 deletions Lab_1/Lab_1/resource.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f2f389b

Please sign in to comment.