Created
May 18, 2024 09:51
-
-
Save EncodeTheCode/7ba80899578f0041afcdf4973ea91618 to your computer and use it in GitHub Desktop.
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
#include <windows.h> | |
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { | |
switch (uMsg) { | |
case WM_CLOSE: | |
// Ignore the close message | |
return 0; | |
case WM_DESTROY: | |
// Ignore the destroy message | |
return 0; | |
default: | |
return DefWindowProc(hwnd, uMsg, wParam, lParam); | |
} | |
} | |
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { | |
const char CLASS_NAME[] = "Sample Window Class"; | |
WNDCLASS wc = { }; | |
wc.lpfnWndProc = WindowProc; | |
wc.hInstance = hInstance; | |
wc.lpszClassName = CLASS_NAME; | |
RegisterClass(&wc); | |
HWND hwnd = CreateWindowEx( | |
0, // Optional window styles. | |
CLASS_NAME, // Window class | |
"Sample Window", // Window text | |
WS_OVERLAPPEDWINDOW, // Window style | |
// Size and position | |
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, | |
NULL, // Parent window | |
NULL, // Menu | |
hInstance, // Instance handle | |
NULL // Additional application data | |
); | |
if (hwnd == NULL) { | |
return 0; | |
} | |
// Make the window topmost | |
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); | |
ShowWindow(hwnd, nCmdShow); | |
// Disable the close button | |
HMENU hMenu = GetSystemMenu(hwnd, FALSE); | |
if (hMenu != NULL) { | |
EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED); | |
} | |
MSG msg = { }; | |
while (GetMessage(&msg, NULL, 0, 0)) { | |
TranslateMessage(&msg); | |
DispatchMessage(&msg); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment