-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: change the render function of the window
- Loading branch information
1 parent
2925809
commit 7260cde
Showing
7 changed files
with
73 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.