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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
#include <Windows.h>
#include <windowsx.h>
#include "defs.h"
static HWND X_BUTTON;
INT IS_MOUSE_DOWN_HEADER = FALSE;
WNDPROC X_BUTTON_PROC;
static HWND MAIN_WINDOW;
RECT MAIN_WINDOW_CLIENT_RECT;
INT W = 800;
INT H = 400;
INT IS_HOVERERING_X = FALSE;
PAINTSTRUCT ps;
int xSetButtonState(int state) {
HBITMAP xbmpSource;
HDC hdcSource;
HDC hdcDest;
hdcDest = BeginPaint(X_BUTTON, &ps); // Begin paint
hdcSource = CreateCompatibleDC(GetDC(0));
switch(state) {
case ID_BUTTON_STATE_HOVER:
xbmpSource = (HBITMAP)LoadImage(NULL, L"x_button_hover.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
SelectObject(hdcSource, xbmpSource);
BitBlt(hdcDest, 0, 0, 25, 20, hdcSource, 0, 0, SRCCOPY);
IS_HOVERERING_X = TRUE;
break;
case ID_BUTTON_STATE_NORMAL:
xbmpSource = (HBITMAP)LoadImage(NULL, L"x_button.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
SelectObject(hdcSource, xbmpSource);
BitBlt(hdcDest, 0, 0, 25, 20, hdcSource, 0, 0, SRCCOPY);
IS_HOVERERING_X = FALSE;
break;
case ID_BUTTON_STATE_PRESSED:
xbmpSource = (HBITMAP)LoadImage(NULL, L"x_button_pressed.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
SelectObject(hdcSource, xbmpSource);
BitBlt(hdcDest, 0, 0, 25, 20, hdcSource, 0, 0, SRCCOPY);
IS_HOVERERING_X = TRUE;
default:
return -1;
break;
}
EndPaint(X_BUTTON, &ps);
DeleteDC(hdcSource);
DeleteDC(hdcDest);
DeleteObject(xbmpSource);
return 0;
}
LRESULT CALLBACK xButtonProc(HWND hWindow, UINT message, WPARAM wParam, LPARAM lParam) {
POINT p;
GetCursorPos(&p);
ScreenToClient(MAIN_WINDOW, &p);
switch(message) {
case WM_LBUTTONDOWN:
{
if(p.x > (W - 30) && p.x < (W - 5) && p.y > 5 && p.y < 24) {
xSetButtonState(ID_BUTTON_STATE_PRESSED);
}
break;
}
case WM_MOUSEMOVE:
{
if(p.x > (W - 30) && p.x < (W - 5) && p.y > 5 && p.y < 24) {
xSetButtonState(ID_BUTTON_STATE_HOVER);
} else {
IS_HOVERERING_X = FALSE;
}
break;
}
case WM_PAINT:
{
if(IS_HOVERERING_X == FALSE) {
xSetButtonState(ID_BUTTON_STATE_NORMAL);
}
break;
}
case WM_LBUTTONUP:
{
if(p.x > (W - 30) && p.x < (W - 5) && p.y > 5 && p.y < 24) {
DestroyWindow(MAIN_WINDOW);
}
break;
}
default:
{
return CallWindowProc(X_BUTTON_PROC, hWindow, message, wParam, lParam);
}
}
return 0;
}
LRESULT CALLBACK WinProc(HWND hWindow, UINT message, WPARAM wParam, LPARAM lParam) {
switch(message) {
case WM_MOUSEMOVE:
{
int x = GET_X_LPARAM(lParam);
int y = GET_Y_LPARAM(lParam);
if(x > 0 && x < (W - 32) && y > 0 && y < 28) {
SetCursor(LoadCursor(NULL, IDC_SIZEALL));
switch(wParam) {
case MK_LBUTTON:
{
POINT p_screen;
GetCursorPos(&p_screen);
MoveWindow(MAIN_WINDOW, p_screen.x - x, p_screen.y - y, W, H, FALSE);
break;
}
}
} else {
SetCursor(LoadCursor(NULL, IDC_ARROW));
}
break;
}
case WM_SIZE:
{
GetClientRect(MAIN_WINDOW, &MAIN_WINDOW_CLIENT_RECT);
W = MAIN_WINDOW_CLIENT_RECT.right - MAIN_WINDOW_CLIENT_RECT.left;
H = MAIN_WINDOW_CLIENT_RECT.bottom - MAIN_WINDOW_CLIENT_RECT.top;
break;
}
case WM_PAINT:
{
W = 800;
H = 400;
HBITMAP bmpWindowTopLeft = (HBITMAP)LoadImage(NULL, L"window_top_left_129_40.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HBITMAP bmpWindowTopRight = (HBITMAP)LoadImage(NULL, L"window_top_right_34_40.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HBITMAP bmpWindowBottomLeft = (HBITMAP)LoadImage(NULL, L"window_bottom_left_40_40.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HBITMAP bmpWindowBottomRight = (HBITMAP)LoadImage(NULL, L"window_bottom_right_40_40.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HBITMAP bmpWindowLeftCenter = (HBITMAP)LoadImage(NULL, L"window_left_center_40_1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HBITMAP bmpWindowRightCenter = (HBITMAP)LoadImage(NULL, L"window_right_center_40_1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HBITMAP bmpWindowBottomCenter = (HBITMAP)LoadImage(NULL, L"window_bottom_center_1_40.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HBITMAP bmpWindowTopCenter = (HBITMAP)LoadImage(NULL, L"window_top_center_1_40.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HBITMAP bmpWindowCenter = (HBITMAP)LoadImage(NULL, L"window_center_2_2.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HBITMAP bmpWindowTitle = (HBITMAP)LoadImage(NULL, L"window_title.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HDC hdcSource;
HDC hdcDest;
hdcDest = BeginPaint(MAIN_WINDOW, &ps); // Begin paint
hdcSource = CreateCompatibleDC(GetDC(0));
SelectObject(hdcSource, bmpWindowTopLeft);
BitBlt(hdcDest, 0, 0, 129, 40, hdcSource, 0, 0, SRCCOPY);
SelectObject(hdcSource, bmpWindowTopRight);
BitBlt(hdcDest, (W - 34), 0, 34, 40, hdcSource, 0, 0, SRCCOPY);
SelectObject(hdcSource, bmpWindowTopCenter);
StretchBlt(hdcDest, 129, 0, (W - 34) - 129, 40, hdcSource, 0, 0, 1, 40, SRCCOPY);
SelectObject(hdcSource, bmpWindowBottomLeft);
BitBlt(hdcDest, 0, (H - 40), 40, 40, hdcSource, 0, 0, SRCCOPY);
SelectObject(hdcSource, bmpWindowBottomRight);
BitBlt(hdcDest, (W - 40), (H - 40), 40, 40, hdcSource, 0, 0, SRCCOPY);
SelectObject(hdcSource, bmpWindowBottomCenter);
StretchBlt(hdcDest, 40, (H - 40), (W - 40) - 40, 40, hdcSource, 0, 0, 1, 40, SRCCOPY);
SelectObject(hdcSource, bmpWindowLeftCenter);
StretchBlt(hdcDest, 0, 40, 40, (H - 40) - 40, hdcSource, 0, 0, 40, 1, SRCCOPY);
SelectObject(hdcSource, bmpWindowRightCenter);
StretchBlt(hdcDest, (W - 40), 40, 40, (H - 40) - 40, hdcSource, 0, 0, 40, 1, SRCCOPY);
SelectObject(hdcSource, bmpWindowCenter);
StretchBlt(hdcDest, 40, 40, (W - 40) - 40, (H - 40) - 40, hdcSource, 0, 0, 2, 2, SRCCOPY);
SelectObject(hdcSource, bmpWindowTitle);
BitBlt(hdcDest, 5, 5, 102, 20, hdcSource, 0, 0, SRCCOPY);
EndPaint(MAIN_WINDOW, &ps); // End paint
DeleteDC(hdcDest);
DeleteDC(hdcSource);
DeleteObject(bmpWindowTopLeft);
DeleteObject(bmpWindowTopRight);
DeleteObject(bmpWindowBottomLeft);
DeleteObject(bmpWindowBottomRight);
DeleteObject(bmpWindowLeftCenter);
DeleteObject(bmpWindowRightCenter);
DeleteObject(bmpWindowBottomCenter);
DeleteObject(bmpWindowTopCenter);
DeleteObject(bmpWindowTopLeft);
break;
}
case WM_CREATE:
{
X_BUTTON = CreateWindow(
L"BUTTON",
L"",
WS_VISIBLE | WS_CHILD | BS_OWNERDRAW,
(W - 30), 5,
25, 19,
hWindow,
(HMENU) ID_X_BUTTON,
NULL,
NULL
);
X_BUTTON_PROC = (WNDPROC) SetWindowLong(X_BUTTON, GWL_WNDPROC, (LONG) xButtonProc);
break;
}
case WM_CLOSE:
DestroyWindow(MAIN_WINDOW);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWindow, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow) {
WNDCLASSEX window;
MSG message;
window.cbSize = sizeof(WNDCLASSEX);
window.cbClsExtra = 0;
window.cbWndExtra = 0;
window.hInstance = hInstance;
window.style = 0;
window.lpszClassName = L"MAIN_CLASS";
window.lpfnWndProc = WinProc;
window.lpszMenuName = NULL;
window.hbrBackground = (HBRUSH) TRANSPARENT;
window.hCursor = LoadCursor(hInstance, IDC_ARROW);
window.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
window.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
if(!RegisterClassEx(&window)) {
MessageBox(NULL, L"Could not register window class!", L"Error", MB_OK | MB_ICONERROR);
return 0;
}
MAIN_WINDOW = CreateWindowEx(
NULL,
L"MAIN_CLASS",
L"STYLING",
WS_POPUP | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN,
50, 50,
W, H,
NULL,
NULL,
hInstance,
NULL
);
if(MAIN_WINDOW == NULL) {
MessageBox(NULL, L"Could not create window!", L"Error", MB_OK | MB_ICONERROR);
return 0;
}
ShowWindow(MAIN_WINDOW, nCmdShow);
UpdateWindow(MAIN_WINDOW);
while(GetMessage(&message, MAIN_WINDOW, 0, 0) > 0) {
TranslateMessage(&message);
DispatchMessage(&message);
}
return (int) message.wParam;
}
|