1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| #include <stdio.h>
#include <windows.h>
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
static int _on = 0;
void
borderless_set(HWND window, int on)
{
LONG style;
style = GetWindowLong(window, GWL_STYLE);
if (on)
SetWindowLong(window, GWL_STYLE, style | ~WS_CAPTION);
else
SetWindowLong(window, GWL_STYLE, style | WS_CAPTION);
}
int APIENTRY
WinMain (HINSTANCE hinstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASS wc;
RECT rect;
HWND window;
DWORD style;
MSG msg;
int width;
int height;
int x, y;
x = 100;
y = 100;
width = 320;
height = 200;
memset (&wc, 0, sizeof (WNDCLASS));
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = MainWndProc;
wc.hInstance = hinstance;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
wc.lpszClassName = "MaWinClass";
if(!RegisterClass(&wc)) return -1;
style = WS_OVERLAPPEDWINDOW | WS_SIZEBOX;
rect.left = x;
rect.top = y;
rect.right = x + width;
rect.bottom = y + height;
AdjustWindowRect (&rect, style, FALSE);
window = CreateWindowEx(0, "MaWinClass", "Titre",
style,
x, y, rect.right - rect.left, rect.bottom - rect.top,
NULL, NULL, hinstance, NULL);
if (!window) return -1;
ShowWindow(window, nCmdShow);
UpdateWindow(window);
/* the main loop */
while (1) {
while (PeekMessage (&msg, window, 0, 0, PM_NOREMOVE)) {
int res;
res = GetMessage (&msg, NULL, 0, 0);
TranslateMessage (&msg);
DispatchMessage (&msg);
if (res == 0) {
break;
}
}
}
return 0;
}
LRESULT CALLBACK
MainWndProc(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_RBUTTONDOWN:
PostQuitMessage(0);
return 0;
case WM_LBUTTONDOWN:
_on = 1 - _on;
printf ("%d\n", _on);
borderless_set (hwnd, _on);
return 0;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
} |
Partager