-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.cpp
More file actions
2480 lines (2084 loc) · 82.2 KB
/
Copy pathWindow.cpp
File metadata and controls
2480 lines (2084 loc) · 82.2 KB
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Including some important header files.
#include "Window.h"
#pragma comment(lib, "Build\\Font.lib")
namespace Function
{
static BOOL GetWindowMaximizedStatus(HWND hWnd)
{
// Help to check wether the window is maximized or not.
WINDOWPLACEMENT placement = {0};
placement.length = sizeof(WINDOWPLACEMENT);
if (GetWindowPlacement(hWnd, &placement))
{
return placement.showCmd == SW_SHOWMAXIMIZED;
}
return FALSE;
}
RECT GetButtonRect(RECT windowRect, int buttonWidth, int buttonHeight, int otherButtonDifference)
{
RECT buttonRect;
buttonRect.left = windowRect.right - windowRect.left - buttonWidth - otherButtonDifference;
buttonRect.right = windowRect.right - windowRect.left - 1 - otherButtonDifference;
buttonRect.top = 1;
buttonRect.bottom = buttonHeight + 1;
return buttonRect;
}
HICON __LoadImageFromFile(std::string path)
{
// Important for the loading of the icon from a local file.
HICON image = NULL;
std::wstring pathWString = std::wstring(path.begin(), path.end());
const WCHAR *pathWChar = pathWString.c_str();
Gdiplus::Bitmap bitmap(pathWChar, false);
bitmap.GetHICON(&image);
return image;
}
void SetCursorF(HCURSOR hCursor)
{
SetCursor(hCursor);
}
void SetDefaultConfiguration()
{
// Setting the default configuration.
std::ofstream file;
file.open("TkinterWindow.Config", std::ios::out);
file << "Width=800" << std::endl;
file << "Height=600" << std::endl;
file << "XPosition=";
file << std::to_string((GetSystemMetrics(SM_CXSCREEN) - 800) / 2) << std::endl;
file << "YPosition=";
file << std::to_string((GetSystemMetrics(SM_CYSCREEN) - 600) / 2) << std::endl;
file << "Theme=RandomTheme" << std::endl;
file << "WindowStatus=Normal" << std::endl;
}
std::string GetConfigurationValue(std::string value)
{
// Getting the value from the configuration file.
std::ifstream existFileCheck("TkinterWindow.Config");
if (!existFileCheck.is_open())
{
SetDefaultConfiguration();
}
else
{
existFileCheck.close();
}
std::ifstream filein("TkinterWindow.Config");
for (std::string line; std::getline(filein, line);)
{
if (line.find(value) != std::string::npos)
{
std::string value = line.substr(line.find("=") + 1);
filein.close();
return value;
}
}
return "0";
}
std::string GetThemeConfigValue(std::string value)
{
// Getting the value of the theme.
std::ifstream themeFile("Themes\\" + GetConfigurationValue("Theme") + "\\" + GetConfigurationValue("Theme") + ".Config", std::ios::in);
if (!themeFile.is_open())
{
MessageBoxA(NULL, "The theme file is not found.", "TkinterWindow", MB_OK | MB_ICONERROR);
exit(-1);
return "";
}
for (std::string line; std::getline(themeFile, line);)
{
if (line.find(value) != std::string::npos)
{
std::string value = line.substr(line.find("=") + 1);
themeFile.close();
return value;
}
}
if ("Themes\\" + GetConfigurationValue("Theme") + "\\" + GetConfigurationValue("Theme") + ".Config" == "Themes\\RandomTheme.Config")
{
return "";
}
else
{
std::ifstream themeFileD("Themes\\" + GetConfigurationValue("Theme") + "\\" + GetConfigurationValue("Theme") + ".Config", std::ios::in);
if (!themeFileD.is_open())
{
MessageBoxA(NULL, "The theme file is not found.", "TkinterWindow", MB_OK | MB_ICONERROR);
return "";
}
for (std::string line; std::getline(themeFileD, line);)
{
if (line.find(value) != std::string::npos)
{
std::string value = line.substr(line.find("=") + 1);
themeFileD.close();
return value;
}
}
return "";
}
}
COLORREF GetColorFromText(std::string text)
{
// Getting the color from the text.
if (text.find(",") != std::string::npos)
{
std::string color = text.substr(text.find("=") + 1);
std::string red = color.substr(0, color.find(","));
color.replace(0, color.find(",") + 1, "");
std::string green = color.substr(0, color.find(","));
color.replace(0, color.find(",") + 1, "");
std::string blue = color.substr(0, color.length());
int redInt = std::stoi(red);
int greenInt = std::stoi(green);
int blueInt = std::stoi(blue);
return RGB(redInt, greenInt, blueInt);
}
return RGB(0, 0, 0);
}
void LoadThemeData(Function::THEME *theme, HINSTANCE hInstance)
{
// Loading the theme data.
theme->windowBorderFocusColor = GetColorFromText(GetThemeConfigValue("WindowBorderFocusColor"));
theme->transparentColor = GetColorFromText(GetThemeConfigValue("TransparentColor"));
theme->windowBackgroundColor = GetColorFromText(GetThemeConfigValue("WindowBackgroundColor"));
theme->windowBorderUnfocusColor = GetColorFromText(GetThemeConfigValue("WindowBorderUnfocusColor"));
theme->windowBorderRadius = std::stoi(GetThemeConfigValue("WindowBorderRadius"));
theme->windowTitleBarBackgroundColor = GetColorFromText(GetThemeConfigValue("WindowTitleBarBackgroundColor"));
theme->windowFocusIconPath = GetThemeConfigValue("WindowFocusIconPath");
theme->windowUnfocusIconPath = GetThemeConfigValue("WindowUnfocusIconPath");
theme->windowTitleBarTextFocusColor = GetColorFromText(GetThemeConfigValue("WindowTitleBarTextFocusColor"));
theme->windowTitleBarTextUnfocusColor = GetColorFromText(GetThemeConfigValue("WindowTitleBarTextUnfocusColor"));
theme->windowCloseButtonTextFocusColor = GetColorFromText(GetThemeConfigValue("WindowCloseButtonTextFocusColor"));
theme->windowCloseButtonTextUnfocusColor = GetColorFromText(GetThemeConfigValue("WindowCloseButtonTextUnfocusColor"));
theme->windowCloseButtonTextHoverColor = GetColorFromText(GetThemeConfigValue("WindowCloseButtonTextHoverColor"));
theme->windowCloseButtonBackgroundHoverColor = GetColorFromText(GetThemeConfigValue("WindowCloseButtonBackgroundHoverColor"));
theme->windowMaximizeButtonTextFocusColor = GetColorFromText(GetThemeConfigValue("WindowMaximizeButtonTextFocusColor"));
theme->windowMaximizeButtonTextUnfocusColor = GetColorFromText(GetThemeConfigValue("WindowMaximizeButtonTextUnfocusColor"));
theme->windowMaximizeButtonTextHoverColor = GetColorFromText(GetThemeConfigValue("WindowMaximizeButtonTextHoverColor"));
theme->windowMaximizeButtonBackgroundHoverColor = GetColorFromText(GetThemeConfigValue("WindowMaximizeButtonBackgroundHoverColor"));
theme->windowMinimizeButtonTextFocusColor = GetColorFromText(GetThemeConfigValue("WindowMinimizeButtonTextFocusColor"));
theme->windowMinimizeButtonTextUnfocusColor = GetColorFromText(GetThemeConfigValue("WindowMinimizeButtonTextUnfocusColor"));
theme->windowMinimizeButtonTextHoverColor = GetColorFromText(GetThemeConfigValue("WindowMinimizeButtonTextHoverColor"));
theme->windowMinimizeButtonBackgroundHoverColor = GetColorFromText(GetThemeConfigValue("WindowMinimizeButtonBackgroundHoverColor"));
theme->windowSettingButtonTextFocusColor = GetColorFromText(GetThemeConfigValue("WindowSettingButtonTextFocusColor"));
theme->windowSettingButtonTextUnfocusColor = GetColorFromText(GetThemeConfigValue("WindowSettingButtonTextUnfocusColor"));
theme->windowSettingButtonTextHoverColor = GetColorFromText(GetThemeConfigValue("WindowSettingButtonTextHoverColor"));
theme->windowSettingButtonBackgroundHoverColor = GetColorFromText(GetThemeConfigValue("WindowSettingButtonBackgroundHoverColor"));
theme->windowCursor = (HCURSOR)LoadImageA(hInstance, (LPCSTR)Function::GetThemeConfigValue("WindowCursor").c_str(), IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE | LR_LOADTRANSPARENT);
theme->windowTopLeftResizeCursor = (HCURSOR)LoadImageA(hInstance, (LPCSTR)Function::GetThemeConfigValue("WindowTopLeftResizeCursor").c_str(), IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE | LR_LOADTRANSPARENT);
theme->windowLeftResizeCursor = (HCURSOR)LoadImageA(hInstance, (LPCSTR)Function::GetThemeConfigValue("WindowLeftResizeCursor").c_str(), IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE | LR_LOADTRANSPARENT);
theme->windowBottomLeftResizeCursor = (HCURSOR)LoadImageA(hInstance, (LPCSTR)Function::GetThemeConfigValue("WindowBottomLeftResizeCursor").c_str(), IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE | LR_LOADTRANSPARENT);
theme->windowTopResizeCursor = (HCURSOR)LoadImageA(hInstance, (LPCSTR)Function::GetThemeConfigValue("WindowTopResizeCursor").c_str(), IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE | LR_LOADTRANSPARENT);
theme->windowBottomResizeCursor = (HCURSOR)LoadImageA(hInstance, (LPCSTR)Function::GetThemeConfigValue("WindowBottomResizeCursor").c_str(), IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE | LR_LOADTRANSPARENT);
theme->windowTopRightResizeCursor = (HCURSOR)LoadImageA(hInstance, (LPCSTR)Function::GetThemeConfigValue("WindowTopRightResizeCursor").c_str(), IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE | LR_LOADTRANSPARENT);
theme->windowRightResizeCursor = (HCURSOR)LoadImageA(hInstance, (LPCSTR)Function::GetThemeConfigValue("WindowRightResizeCursor").c_str(), IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE | LR_LOADTRANSPARENT);
theme->windowBottomRightResizeCursor = (HCURSOR)LoadImageA(hInstance, (LPCSTR)Function::GetThemeConfigValue("WindowBottomRightResizeCursor").c_str(), IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE | LR_LOADTRANSPARENT);
theme->windowStatusBarBackgroundColor = GetColorFromText(GetThemeConfigValue("WindowStatusBarBackgroundColor"));
theme->windowStatusBarTextFocusColor = GetColorFromText(GetThemeConfigValue("WindowStatusBarTextFocusColor"));
theme->windowStatusBarTextUnfocusColor = GetColorFromText(GetThemeConfigValue("WindowStatusBarTextUnfocusColor"));
}
void WriteDataToConfigurationFile(std::string value, std::string data)
{
// Writing data to the configuration file.
std::ifstream filein("TkinterWindow.Config");
std::string fileContent;
std::string line;
while (std::getline(filein, line))
{
if (line.find(value) != std::string::npos)
{
line = value + "=" + data;
}
fileContent += line + "\n";
}
filein.close();
std::ofstream fileout("TkinterWindow.Config");
fileout << fileContent;
fileout.close();
}
}
namespace TkinterWindow
{
// [ Starting ] Private Functions.
LRESULT Window::__WindowProcedure(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// Assigning the procedure to the class procedure.
if (message == WM_NCCREATE)
{
// Setting the class as user data.
CREATESTRUCT *lParamStruct = (CREATESTRUCT *)lParam;
TkinterWindow::Window *lpLabelClass = (TkinterWindow::Window *)lParamStruct->lpCreateParams;
SetWindowLongPtrA(hWnd, GWLP_USERDATA, (LONG_PTR)lpLabelClass);
return DefWindowProcA(hWnd, message, wParam, lParam);
}
else
{
// Getting the class as user data that stored in NC_CREATE.
TkinterWindow::Window *windowObject = reinterpret_cast<TkinterWindow::Window *>(static_cast<LONG_PTR>(GetWindowLongPtrA(hWnd, GWLP_USERDATA)));
if (windowObject)
{
// Returning and calling to the class procedure.
return windowObject->__TkinterWindow_WindowProc(hWnd, message, wParam, lParam);
}
else
{
// Returning and calling to the default window procedure.
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
return 0;
}
LRESULT Window::__TkinterWindow_WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// The procedure of the window.
switch (message)
{
case WM_SETCURSOR:
{
// Setting the cursor.
POINT mousePosition;
GetCursorPos(&mousePosition);
ScreenToClient(hWnd, &mousePosition);
if (Function::GetWindowMaximizedStatus(hWnd))
{
Function::SetCursorF(__theme.windowCursor);
}
else
{
if ((mousePosition.x < 8) && (mousePosition.y < 8))
{
Function::SetCursorF(__theme.windowTopLeftResizeCursor);
}
else if ((mousePosition.x > __width - 6) && (mousePosition.y < 6))
{
Function::SetCursorF(__theme.windowTopRightResizeCursor);
}
else if ((mousePosition.x > __width - 8) && (mousePosition.y < 8))
{
Function::SetCursorF(__theme.windowTopResizeCursor);
}
else if ((mousePosition.y > __height - 8) && (mousePosition.x < 8))
{
Function::SetCursorF(__theme.windowBottomLeftResizeCursor);
}
else if ((mousePosition.y > __height - 8) && (mousePosition.x > __width - 8))
{
Function::SetCursorF(__theme.windowBottomRightResizeCursor);
}
else if (mousePosition.x < 3)
{
Function::SetCursorF(__theme.windowLeftResizeCursor);
}
else if (mousePosition.x > __width - 4)
{
Function::SetCursorF(__theme.windowRightResizeCursor);
}
else if (mousePosition.y < 3)
{
Function::SetCursorF(__theme.windowTopResizeCursor);
}
else if (mousePosition.y > __height - 4)
{
Function::SetCursorF(__theme.windowBottomResizeCursor);
}
else
{
Function::SetCursorF(__theme.windowCursor);
}
}
return TRUE;
}
case WM_PAINT:
{
// Painting the window.
PAINTSTRUCT ps;
HDC hDC = BeginPaint(hWnd, &ps);
// Getting about the focus.
bool isFocused = !!GetFocus();
// Getting the window size.
RECT windowRect;
GetWindowRect(hWnd, &windowRect);
int width = windowRect.right - windowRect.left;
int height = windowRect.bottom - windowRect.top;
// Painting the background with transparent color.
HBRUSH transparentBrush = CreateSolidBrush(__theme.transparentColor);
FillRect(hDC, &ps.rcPaint, transparentBrush);
DeleteObject(transparentBrush);
// The difference between maximized window and normal window
if (Function::GetWindowMaximizedStatus(hWnd))
{
__differenceX = 8;
__differenceY = 8;
__widthDifference = 8;
__heightDifference = 8;
}
else
{
__differenceX = 0;
__differenceY = 0;
__widthDifference = 0;
__heightDifference = 0;
}
// Painting the border and the background with the accurate color.
HBRUSH backgroundBrush = CreateSolidBrush(__theme.windowBackgroundColor);
HPEN borderPen;
if (isFocused)
{
borderPen = CreatePen(PS_SOLID, 1, __theme.windowBorderFocusColor);
}
else
{
borderPen = CreatePen(PS_SOLID, 1, __theme.windowBorderUnfocusColor);
}
SelectObject(hDC, backgroundBrush);
SelectObject(hDC, borderPen);
RoundRect(hDC, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom, __theme.windowBorderRadius, __theme.windowBorderRadius);
DeleteObject(backgroundBrush);
DeleteObject(borderPen);
// Painting the title bar.
HBRUSH titleBarBrush = CreateSolidBrush(__theme.windowTitleBarBackgroundColor);
HPEN titleBarPen = CreatePen(PS_SOLID, 1, __theme.windowTitleBarBackgroundColor);
SelectObject(hDC, titleBarBrush);
RoundRect(hDC, 0, 0, width, __titleBarHeight, __theme.windowBorderRadius, __theme.windowBorderRadius);
SelectObject(hDC, titleBarPen);
Rectangle(hDC, 1 - __differenceX, 10 - __differenceY, width - 1 + __widthDifference, __titleBarHeight + __heightDifference);
DeleteObject(titleBarPen);
DeleteObject(titleBarBrush);
// Drawing the icon.
if (isFocused)
{
HICON icon = Function::__LoadImageFromFile(__theme.windowFocusIconPath);
DrawIconEx(hDC, 10 + __differenceX, 5 + __differenceY, icon, 20, 20, 0, NULL, DI_NORMAL);
}
else
{
HICON icon = Function::__LoadImageFromFile(__theme.windowUnfocusIconPath);
DrawIconEx(hDC, 10 + __differenceX, 5 + __differenceY, icon, 20, 20, 0, NULL, DI_NORMAL);
}
// Drawing the title.
SetBkMode(hDC, TRANSPARENT);
if (isFocused)
{
SetTextColor(hDC, __theme.windowTitleBarTextFocusColor);
}
else
{
SetTextColor(hDC, __theme.windowTitleBarTextUnfocusColor);
}
__titleTextFont.SetFontSize(16);
__titleTextFont.GetFontObject(hDC);
RECT titleTextRect;
titleTextRect.left = 35 + __differenceX;
titleTextRect.top = 1 + __differenceY;
titleTextRect.right = width - 1 + __widthDifference;
titleTextRect.bottom = __titleBarHeight + __heightDifference;
DrawTextA(hDC, __windowTitle.c_str(), __windowTitle.length(), &titleTextRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
__titleTextFont.DeleteFontObject();
// Drawing the buttons of the window.
__buttonState.isAllButtonPaint = false;
SendMessageA(hWnd, WM_NCMOUSEMOVE, NULL, NULL);
// Drawing the status bar.
SetBkMode(hDC, TRANSPARENT);
if (isFocused)
{
SetTextColor(hDC, __theme.windowStatusBarTextFocusColor);
}
else
{
SetTextColor(hDC, __theme.windowStatusBarTextUnfocusColor);
}
HBRUSH statusBarBrush = CreateSolidBrush(__theme.windowStatusBarBackgroundColor);
HPEN statusBarPenB = CreatePen(PS_SOLID, 1, __theme.windowStatusBarBackgroundColor);
HPEN statusBarPen;
if (isFocused)
{
statusBarPen = CreatePen(PS_SOLID, 1, __theme.windowBorderFocusColor);
}
else
{
statusBarPen = CreatePen(PS_SOLID, 1, __theme.windowBorderUnfocusColor);
}
__statusBarTextFont.GetFontObject(hDC);
SelectObject(hDC, statusBarPen);
SelectObject(hDC, statusBarBrush);
__heightDifference -= 1;
RoundRect(hDC, 0, height - __statusBarHeight - __heightDifference, width - 1, height - 1, __theme.windowBorderRadius, __theme.windowBorderRadius);
DeleteObject(statusBarPen);
SelectObject(hDC, statusBarPenB);
Rectangle(hDC, 1, height - __statusBarHeight - __heightDifference, width - 2, height - 10);
DeleteObject(statusBarPenB);
DeleteObject(statusBarBrush);
__heightDifference += 1;
RECT statusBarRect;
statusBarRect.left = 10 + __differenceX;
statusBarRect.right = width - 10 - __widthDifference;
statusBarRect.top = height - __statusBarHeight - __heightDifference;
statusBarRect.bottom = height - 1 - __heightDifference;
DrawTextA(hDC, __statusBarText.c_str(), __statusBarText.length(), &statusBarRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
__statusBarTextFont.DeleteFontObject();
EndPaint(hWnd, &ps);
break;
}
case WM_NCMOUSEMOVE:
{
// controlling the hovering functionalities of the buttons.
POINT cursorPoint;
GetCursorPos(&cursorPoint);
ScreenToClient(hWnd, &cursorPoint);
RECT windowRect;
GetWindowRect(hWnd, &windowRect);
// The difference between maximized window and normal window
if (Function::GetWindowMaximizedStatus(hWnd))
{
__differenceX = 8;
__differenceY = 8;
__widthDifference = 8;
__heightDifference = 8;
}
else
{
__differenceX = 0;
__differenceY = 0;
__widthDifference = 0;
__heightDifference = 0;
}
bool coloringTop = false;
bool coloringTopRight = false;
if (!Function::GetWindowMaximizedStatus(hWnd))
{
if ((cursorPoint.x > __width - 6) && (cursorPoint.y < 6))
{
coloringTopRight = true;
}
else if (cursorPoint.x > __width - 4)
{
coloringTopRight = true;
}
else if (cursorPoint.y < 3)
{
coloringTopRight = true;
coloringTop = true;
}
}
// Difference in the paint and move getting.
windowRect.right += 1;
windowRect.top += 1;
HDC hDC = GetDC(hWnd);
// Checking for the close button hovering.
if ((PtInRect(&Function::GetButtonRect(windowRect, 45, __titleBarHeight + __differenceY, 0 + __widthDifference), cursorPoint)) && (coloringTopRight == false))
{
if (!__buttonState.isCloseButtonHover)
{
__buttonState.isCloseButtonHover = true;
__DrawCloseButton(hDC, windowRect, 45, __titleBarHeight);
}
}
else
{
if ((__buttonState.isCloseButtonHover) || (!__buttonState.isAllButtonPaint))
{
__buttonState.isCloseButtonHover = false;
__DrawCloseButton(hDC, windowRect, 45, __titleBarHeight);
}
}
// checking for the maximize button hovering.
if ((PtInRect(&Function::GetButtonRect(windowRect, 42, __titleBarHeight + __differenceY, 45 + __widthDifference), cursorPoint)) && (coloringTop == false))
{
if (!__buttonState.isMaximizeButtonHover)
{
__buttonState.isMaximizeButtonHover = true;
__DrawMaximizeButton(hDC, windowRect, 42, __titleBarHeight);
}
}
else
{
if ((__buttonState.isMaximizeButtonHover) || (!__buttonState.isAllButtonPaint))
{
__buttonState.isMaximizeButtonHover = false;
__DrawMaximizeButton(hDC, windowRect, 42, __titleBarHeight);
}
}
// checking for the minimize button hovering.
if ((PtInRect(&Function::GetButtonRect(windowRect, 42, __titleBarHeight + __differenceY, 87 + __widthDifference), cursorPoint)) && (coloringTop == false))
{
if (!__buttonState.isMinimizeButtonHover)
{
__buttonState.isMinimizeButtonHover = true;
__DrawMinimizeButton(hDC, windowRect, 42, __titleBarHeight);
}
}
else
{
if ((__buttonState.isMinimizeButtonHover) || (!__buttonState.isAllButtonPaint))
{
__buttonState.isMinimizeButtonHover = false;
__DrawMinimizeButton(hDC, windowRect, 42, __titleBarHeight);
}
}
// checking for the menu button hovering.
if ((PtInRect(&Function::GetButtonRect(windowRect, 42, __titleBarHeight + __differenceY, 129 + __widthDifference), cursorPoint)) && (coloringTop == false))
{
if (!__buttonState.isSettingButtonHover)
{
__buttonState.isSettingButtonHover = true;
__DrawSettingButton(hDC, windowRect, 42, __titleBarHeight);
}
}
else
{
if ((__buttonState.isSettingButtonHover) || (!__buttonState.isAllButtonPaint))
{
__buttonState.isSettingButtonHover = false;
__DrawSettingButton(hDC, windowRect, 42, __titleBarHeight);
}
}
__buttonState.isAllButtonPaint = true;
coloringTop = false;
coloringTopRight = false;
ReleaseDC(hWnd, hDC);
break;
}
case WM_NCHITTEST:
{
// Making the window draggable and resizable.
LRESULT hit = DefWindowProcA(hWnd, message, wParam, lParam);
if (hit == HTNOWHERE)
{
return hit;
}
POINT mousePosition;
GetCursorPos(&mousePosition);
ScreenToClient(hWnd, &mousePosition);
if ((mousePosition.x > 8) && (mousePosition.x < 30) && (mousePosition.y > 5) && (mousePosition.y < 30 + __differenceY))
{
return HTMENU;
}
else if ((mousePosition.x < 8) && (mousePosition.y < 8))
{
return HTTOPLEFT;
}
else if ((mousePosition.x > __width - 6) && (mousePosition.y < 6))
{
return HTTOPRIGHT;
}
else if ((mousePosition.y > __height - 8) && (mousePosition.x < 8))
{
return HTBOTTOMLEFT;
}
else if ((mousePosition.y > __height - 8) && (mousePosition.x > __width - 8))
{
return HTBOTTOMRIGHT;
}
else if ((mousePosition.y > 3) && (mousePosition.y < 31 + __differenceY) && (mousePosition.x > 3) && (mousePosition.x < __width - 3))
{
return HTCAPTION;
}
else if (mousePosition.x < 3)
{
return HTLEFT;
}
else if (mousePosition.x > __width - 4)
{
return HTRIGHT;
}
else if (mousePosition.y < 3)
{
return HTTOP;
}
else if (mousePosition.y > __height - 4)
{
return HTBOTTOM;
}
else if (__buttonState.isMaximizeButtonHover)
{
return HTMAXBUTTON;
}
else if (__buttonState.isCloseButtonHover)
{
return HTCLOSE;
}
else if (__buttonState.isMinimizeButtonHover)
{
return HTMINBUTTON;
}
else
{
return HTCLIENT;
}
break;
}
case WM_NCLBUTTONUP:
{
if (__buttonState.isCloseButtonHover)
{
SendMessageA(hWnd, WM_CLOSE, NULL, NULL);
}
else if (__buttonState.isMaximizeButtonHover)
{
if (Function::GetWindowMaximizedStatus(hWnd))
{
ShowWindow(hWnd, SW_NORMAL);
}
else
{
ShowWindow(hWnd, SW_MAXIMIZE);
}
}
else if (__buttonState.isMinimizeButtonHover)
{
ShowWindow(hWnd, SW_MINIMIZE);
}
else if (__buttonState.isSettingButtonHover)
{
}
break;
}
case WM_KILLFOCUS:
{
// Repainting the whole window.
__RePaintWindow();
break;
}
case WM_SETFOCUS:
{
// Repainting the whole window.
__RePaintWindow();
break;
}
case WM_EXITSIZEMOVE:
{
// Resizing the window.
RECT windowRect;
GetWindowRect(hWnd, &windowRect);
__width = windowRect.right - windowRect.left;
__height = windowRect.bottom - windowRect.top;
__xPosition = windowRect.left;
__yPosition = windowRect.top;
Function::WriteDataToConfigurationFile("Width", std::to_string(__width));
Function::WriteDataToConfigurationFile("Height", std::to_string(__height));
Function::WriteDataToConfigurationFile("XPosition", std::to_string(__xPosition));
Function::WriteDataToConfigurationFile("YPosition", std::to_string(__yPosition));
// Setting the pixels to transparent.
SetLayeredWindowAttributes(hWnd, __theme.transparentColor, 255, LWA_COLORKEY);
break;
}
case WM_ENTERSIZEMOVE:
{
// Setting pixels to visible in order to get rid of fluckkerings.
SetLayeredWindowAttributes(hWnd, 0, 255, LWA_ALPHA);
break;
}
case WM_NCLBUTTONDOWN:
{
// Checking for the button hover state.
if ((__buttonState.isCloseButtonHover) || (__buttonState.isMaximizeButtonHover) || (__buttonState.isMinimizeButtonHover) || (__buttonState.isSettingButtonHover))
{
return 0;
}
break;
}
case WM_MOUSEMOVE:
{
// Checking for Enter and Leave events.
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.dwFlags = TME_HOVER | TME_LEAVE;
tme.dwHoverTime = 1;
tme.hwndTrack = hWnd;
TrackMouseEvent(&tme);
if (__buttonState.isSettingButtonHover)
{
POINT cursorPoint;
GetCursorPos(&cursorPoint);
ScreenToClient(hWnd, &cursorPoint);
RECT windowRect;
GetWindowRect(hWnd, &windowRect);
// Difference in the paint and move getting.
windowRect.right += 1;
windowRect.top += 1;
HDC hDC = GetDC(hWnd);
__buttonState.isSettingButtonHover = false;
__DrawSettingButton(hDC, windowRect, 42, __titleBarHeight);
ReleaseDC(hWnd, hDC);
}
break;
}
case WM_DESTROY:
{
// Destroying the window.
PostQuitMessage(0);
return 0;
break;
}
case WM_CLOSE:
{
// Closing the window.
DestroyWindow(hWnd);
// Checking if the window is in full screen mode.
if (__isFullScreen)
{
HWND taskBar = FindWindowA("Shell_TrayWnd", NULL);
HWND startButton = FindWindowA("Button", NULL);
ShowWindow(taskBar, SW_SHOW);
ShowWindow(startButton, SW_SHOW);
}
break;
}
case WM_NCMOUSELEAVE:
{
// Checking for the unhovering of the button.
if ((__buttonState.isCloseButtonHover) || (__buttonState.isMaximizeButtonHover) || (__buttonState.isMinimizeButtonHover) || (__buttonState.isSettingButtonHover))
{
__RePaintWindow();
}
break;
}
case WM_KEYDOWN:
{
// Key down event.
if (wParam == VK_F11)
{
HWND taskBar = FindWindowA("Shell_TrayWnd", NULL);
HWND startButton = FindWindowA("Button", NULL);
if (__isFullScreen)
{
// Setting the window to normal.
ShowWindow(taskBar, SW_SHOW);
ShowWindow(startButton, SW_SHOW);
SetWindowPos(hWnd, NULL, __previousXPosition, __previousYPosition, __previousWidth, __previousHeight, SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
SetFocus(hWnd);
SetWindowBorderRadius(__previouseBorderRadius);
__isFullScreen = false;
}
else
{
// Setting the window to full screen.
ShowWindow(taskBar, SW_HIDE);
ShowWindow(startButton, SW_HIDE);
__previousWidth = __width;
__previousHeight = __height;
__previousXPosition = __xPosition;
__previousYPosition = __yPosition;
__previouseBorderRadius = __theme.windowBorderRadius;
// Getting the screen size.
MONITORINFO monitorInformation;
monitorInformation.cbSize = sizeof(monitorInformation);
GetMonitorInfo(MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST),
&monitorInformation);
RECT monitorSizeRect = monitorInformation.rcMonitor;
SetWindowPos(hWnd, NULL, monitorSizeRect.left - 1, monitorSizeRect.top - 1, monitorSizeRect.right - monitorSizeRect.left + 2, monitorSizeRect.bottom - monitorSizeRect.top + 2, SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
SetWindowBorderRadius(0);
__isFullScreen = true;
}
}
break;
}
case WM_CREATE:
{
// Extending the client area.
RECT sizeRect;
GetWindowRect(hWnd, &sizeRect);
SetWindowPos(hWnd, NULL, 0, 0, sizeRect.right - sizeRect.left, sizeRect.bottom - sizeRect.top, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);
break;
}
case WM_ERASEBKGND:
{
// Removing the background.
return 1;
}
case WM_NCCALCSIZE:
{
// Removing the border.
return 0;
break;
}
case WM_SIZE:
{
// Saving the state of the window.
if (wParam == SIZE_MAXIMIZED)
{
Function::WriteDataToConfigurationFile("WindowStatus", "Maximized");
}
else if (wParam == SIZE_MINIMIZED)
{
Function::WriteDataToConfigurationFile("WindowStatus", "Minimized");
}
else if (wParam == SIZE_RESTORED)
{
Function::WriteDataToConfigurationFile("WindowStatus", "Normal");
}
break;
}
default:
{
break;
}
}
return DefWindowProcA(hWnd, message, wParam, lParam);
}
void Window::__RePaintWindow()
{
// Repainting the window.
if (__windowHandle != NULL)
{
SendMessageA(__windowHandle, WM_SIZE, NULL, NULL);
InvalidateRect(__windowHandle, NULL, TRUE);
UpdateWindow(__windowHandle);
}
}
void Window::__DrawCloseButton(HDC hDC, RECT windowRect, int buttonWidth, int buttonHeight)
{
// Drawing the close button.
bool isFocused = !!GetFocus();
// Checking if the button is hovered or not.
HBRUSH backgroundBrush;
HPEN backgroundPen;
if (__buttonState.isCloseButtonHover)
{
// Filling the button rectangle.
backgroundBrush = CreateSolidBrush(__theme.windowCloseButtonBackgroundHoverColor);
backgroundPen = CreatePen(PS_SOLID, 1, __theme.windowCloseButtonBackgroundHoverColor);
}
else
{
// Unfilling the button rectangle.
backgroundBrush = CreateSolidBrush(__theme.windowTitleBarBackgroundColor);
backgroundPen = CreatePen(PS_SOLID, 1, __theme.windowTitleBarBackgroundColor);
}
HPEN borderPen;
if (isFocused)
{
borderPen = CreatePen(PS_SOLID, 1, __theme.windowBorderFocusColor);
}
else