Skip to content

Commit

Permalink
fix: change the render function of the window
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKonstantinSh committed Sep 15, 2020
1 parent 2925809 commit 7260cde
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 203 deletions.
20 changes: 10 additions & 10 deletions Lab_1/Lab_1.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30309.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lab_1", "Lab_1\Lab_1.vcxproj", "{1D32933E-0C89-4FAA-8183-F729ABF26DDF}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lab_1", "Lab_1\Lab_1.vcxproj", "{805D143F-4925-408E-8E98-71A5B106E6DF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -13,19 +13,19 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1D32933E-0C89-4FAA-8183-F729ABF26DDF}.Debug|x64.ActiveCfg = Debug|x64
{1D32933E-0C89-4FAA-8183-F729ABF26DDF}.Debug|x64.Build.0 = Debug|x64
{1D32933E-0C89-4FAA-8183-F729ABF26DDF}.Debug|x86.ActiveCfg = Debug|Win32
{1D32933E-0C89-4FAA-8183-F729ABF26DDF}.Debug|x86.Build.0 = Debug|Win32
{1D32933E-0C89-4FAA-8183-F729ABF26DDF}.Release|x64.ActiveCfg = Release|x64
{1D32933E-0C89-4FAA-8183-F729ABF26DDF}.Release|x64.Build.0 = Release|x64
{1D32933E-0C89-4FAA-8183-F729ABF26DDF}.Release|x86.ActiveCfg = Release|Win32
{1D32933E-0C89-4FAA-8183-F729ABF26DDF}.Release|x86.Build.0 = Release|Win32
{805D143F-4925-408E-8E98-71A5B106E6DF}.Debug|x64.ActiveCfg = Debug|x64
{805D143F-4925-408E-8E98-71A5B106E6DF}.Debug|x64.Build.0 = Debug|x64
{805D143F-4925-408E-8E98-71A5B106E6DF}.Debug|x86.ActiveCfg = Debug|Win32
{805D143F-4925-408E-8E98-71A5B106E6DF}.Debug|x86.Build.0 = Debug|Win32
{805D143F-4925-408E-8E98-71A5B106E6DF}.Release|x64.ActiveCfg = Release|x64
{805D143F-4925-408E-8E98-71A5B106E6DF}.Release|x64.Build.0 = Release|x64
{805D143F-4925-408E-8E98-71A5B106E6DF}.Release|x86.ActiveCfg = Release|Win32
{805D143F-4925-408E-8E98-71A5B106E6DF}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F5EF02C5-75A8-4FCC-86CC-6E324B1EAE71}
SolutionGuid = {571BAF3D-8401-47F0-A299-8FE9B367693D}
EndGlobalSection
EndGlobal
129 changes: 54 additions & 75 deletions Lab_1/Lab_1/Lab_1.cpp
Original file line number Diff line number Diff line change
@@ -1,97 +1,76 @@
#include <Windows.h>
#include <tchar.h>
#include <xstring>

#include "resource.h";

typedef std::basic_string<TCHAR, std::char_traits<TCHAR>,
std::allocator<TCHAR> > String;
constexpr auto WINDOW_NAME = "Lab_1";

ATOM RegisterWindowClass(HINSTANCE);
BOOL InitWindowInstance(HINSTANCE, int);
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)
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR cmdLine, int cmdShowMode)
{
HWND hWnd; // Window descriptor.
MSG msg; // Structure for storing the message.
WNDCLASS wc; // Window class.

wc.hInstance = This;
wc.lpszClassName = WinName; // Window name.
wc.lpfnWndProc = WndProc; // Callback window function.
wc.style = CS_HREDRAW | CS_VREDRAW; // Window style.
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); // Default window icon.
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Default mouse cursor.
wc.lpszMenuName = NULL; // Window has no menu.
wc.cbClsExtra = 0; // No extra class info.
wc.cbWndExtra = 0; // No extra window info.

// Fill window with white color.
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);

hInst = This;

// Class registration
if (!RegisterClass(&wc))
return 0;
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(cmdLine);

MSG msg;

RegisterWindowClass(hInstance);

hWnd = CreateWindow(WinName, // Window name.
_T("Lab_1"), // Window title.
WS_OVERLAPPEDWINDOW, // Window style.
CW_USEDEFAULT, // X.
CW_USEDEFAULT, // Y.
CW_USEDEFAULT, // Window width.
CW_USEDEFAULT, // Window height.
HWND_DESKTOP, // Parent window descriptor.
NULL, // Window has no menu.
This, // Application descriptor.
NULL); // No extra info.

ShowWindow(hWnd, mode);

// Message processing cycle.
while (GetMessage(&msg, NULL, 0, 0)) {
if (!InitWindowInstance(hInstance, cmdShowMode))
return FALSE;

while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return 0;
return (int)msg.wParam;
}

// The window function is called by the operating system and
// receives messages from the queue for this application.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
ATOM RegisterWindowClass(HINSTANCE hInstance)
{
WNDCLASSEX windowClassEx;

windowClassEx.cbSize = sizeof(WNDCLASSEX);
windowClassEx.style = CS_HREDRAW | CS_VREDRAW;
windowClassEx.lpfnWndProc = WndProc;
windowClassEx.cbClsExtra = 0;
windowClassEx.cbWndExtra = 0;
windowClassEx.hInstance = hInstance;
windowClassEx.hIcon = LoadIcon(0, IDI_WINLOGO);;
windowClassEx.hCursor = LoadCursor(0, IDC_ARROW);
windowClassEx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
windowClassEx.lpszMenuName = 0;
windowClassEx.lpszClassName = WINDOW_NAME;
windowClassEx.hIconSm = 0;

return RegisterClassEx(&windowClassEx);
}

BOOL InitWindowInstance(HINSTANCE hInstance, int cmdShowMode)
{
PAINTSTRUCT ps;
HDC hdc;
HBITMAP hBitmap;
HWND hWnd;

hWnd = CreateWindow(WINDOW_NAME, WINDOW_NAME, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

if (!hWnd)
return FALSE;

static HDC memBitMap;
static BITMAP bm;
ShowWindow(hWnd, cmdShowMode);
UpdateWindow(hWnd);

return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
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:
case WM_DESTROY:
PostQuitMessage(0);
break;
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}

return 0;
}
}
69 changes: 0 additions & 69 deletions Lab_1/Lab_1/Lab_1.rc

This file was deleted.

27 changes: 9 additions & 18 deletions Lab_1/Lab_1/Lab_1.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{1d32933e-0c89-4faa-8183-f729abf26ddf}</ProjectGuid>
<ProjectGuid>{805d143f-4925-408e-8e98-71a5b106e6df}</ProjectGuid>
<RootNamespace>Lab1</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
Expand All @@ -30,7 +30,7 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
Expand Down Expand Up @@ -86,7 +86,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
Expand All @@ -100,11 +100,11 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand All @@ -114,11 +114,11 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
Expand All @@ -128,11 +128,11 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand All @@ -141,15 +141,6 @@
<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: 0 additions & 15 deletions Lab_1/Lab_1/Lab_1.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,4 @@
<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 removed Lab_1/Lab_1/bitmap1.bmp
Binary file not shown.
16 changes: 0 additions & 16 deletions Lab_1/Lab_1/resource.h

This file was deleted.

0 comments on commit 7260cde

Please sign in to comment.