-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExWindows.h
More file actions
2252 lines (1940 loc) · 55.1 KB
/
Copy pathExWindows.h
File metadata and controls
2252 lines (1940 loc) · 55.1 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
#pragma once
#include <string>
#include <sstream>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <wchar.h>
#include <typeinfo>
#include <Windows.h>
#include <Windowsx.h>
#ifdef USE_WONDER_CONTROLS
# pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
# pragma comment(lib, "comctl32.lib")
#endif
template<bool>
class WND_COMBO__;
template<bool>
class WND_LIST__;
template<bool>
class EX_WND__;
typedef WND_COMBO__<true> WND_COMBO;
typedef WND_LIST__<true> WND_LIST;
typedef EX_WND__<true> EX_WND;
template<bool>
class EX_WND__
{
static bool ___g;
class __HWND_TEXT
{
HWND hWnd;
public:
void get_stl_str(std::basic_string<WCHAR>& s)
{
int Length = GetWindowTextLengthW(hWnd);
s.resize(Length);
GetWindowTextW(hWnd, (LPWSTR)s.c_str(), Length + 1);
}
void get_stl_str(std::basic_string<CHAR>& s)
{
int Length = GetWindowTextLengthA(hWnd);
s.resize(Length);
GetWindowTextA(hWnd, (LPSTR)s.c_str(), Length + 1);
}
inline int get_str_len() { return GetWindowTextLength(hWnd) }
inline size_t get_str(char* Buffer, size_t Len) { return GetWindowTextA(hWnd, Buffer, Len); }
inline size_t get_str(wchar_t* Buffer, size_t Len) { return GetWindowTextW(hWnd, Buffer, Len); }
inline void set_str(char* Buffer) { SetWindowTextA(hWnd, Buffer); }
inline void set_str(wchar_t* Buffer) { SetWindowTextW(hWnd, Buffer); }
};
class __HWND_NAME_CLASS
{
HWND hWnd;
public:
void get_stl_str(std::basic_string<WCHAR>& Str)
{
size_t l, k = 0;
do
{
k = (k | 0xff) + 1;
Str.resize(k);
GetClassNameW(hWnd, (LPWSTR)Str.c_str(), k);
} while((l = wcslen(Str.c_str())) >= (k - 3));
Str.resize(l);
}
void get_stl_str(std::basic_string<CHAR>& Str)
{
size_t l, k = 0;
do
{
k = (k | 0xff) + 1;
Str.resize(k);
GetClassNameA(hWnd, (LPSTR)Str.c_str(), k);
} while((l = strlen(Str.c_str())) >= (k - 3));
Str.resize(l);
}
inline int get_str_len() { std::string k; get_stl_str(k); return k.length(); }
inline size_t get_str(char* Buffer, size_t Len) { return GetClassNameA(hWnd, Buffer, Len); }
inline size_t get_str(wchar_t* Buffer, size_t Len) { return GetClassNameW(hWnd, Buffer, Len); }
};
public:
template<class BaseType>
class __TEXT_PROPERTY_SET_GET
{
/*
BaseType must have this methods:
int BaseType::get_str_len(); - get element len
void BaseType::get_stl_str(std::basic_string<WCHAR>& ); - Get stl string wchar_t
void BaseType::get_stl_str(std::basic_string<CHAR>& ); - Get stl string char
size_t BaseType::get_str(char* Buffer, size_t Len); - Get c string from element
size_t BaseType::get_str(wchar_t* Buffer, size_t Len); - Get c string from element
void BaseType::set_str(char* Buffer); - Set c string to element
void BaseType::set_str(wchar_t* Buffer); - Set c string to element
*/
public:
class
{
friend __TEXT_PROPERTY_SET_GET;
BaseType v;
public:
inline operator int() { return v.get_str_len(); }
} Length;
operator std::basic_string<WCHAR>() { std::basic_string<WCHAR> s; Length.v.get_stl_str(s); return s; }
operator std::basic_string<CHAR>() { std::basic_string<CHAR> s; Length.v.get_stl_str(s); return s; }
operator int() { char s[40] = {0}; Length.v.get_str(s, 39); return atoi(s); }
operator unsigned() { char s[40] = {0}; Length.v.get_str(s, 39); unsigned r = 0; sscanf(s, "%u", &r); return r; }
inline size_t operator()(LPWSTR Buffer, size_t Len = 0x0fffffff) { return Length.v.get_str(Buffer, Len); }
inline size_t operator()(LPSTR Buffer, size_t Len = 0x0fffffff) { return Length.v.get_str(Buffer, Len); }
inline std::basic_string<WCHAR> & operator=(const std::basic_string<WCHAR> & Str) { Length.v.set_str((LPWSTR)Str.c_str()); return (std::basic_string<WCHAR>&)Str; }
inline std::basic_string<CHAR> & operator=(const std::basic_string<CHAR> & Str) { Length.v.set_str((LPSTR)Str.c_str()); return (std::basic_string<CHAR>&)Str; }
inline LPSTR operator=(LPCSTR Str) { Length.v.set_str((LPSTR)Str); return (LPSTR)Str; }
inline LPWSTR operator=(LPCWSTR Str) { Length.v.set_str((LPWSTR)Str); return (LPWSTR)Str; }
int operator=(int Val) { char s[40]; itoa(Val, s, 10); operator=(s); return Val; }
unsigned operator=(unsigned Val) { char s[40]; sprintf(s, "%u", Val); operator=(s); return Val; }
inline bool operator==(const std::basic_string<WCHAR> & Str2) { return operator std::basic_string<WCHAR>() == Str2; }
inline bool operator==(const std::basic_string<CHAR> & Str2) { return operator std::basic_string<CHAR>() == Str2; }
inline bool operator==(LPCWSTR Str2) { return operator std::basic_string<WCHAR>() == Str2; }
inline bool operator==(LPCSTR Str2) { return operator std::basic_string<CHAR>() == Str2; }
template<class T>
inline bool operator!=(T Val) { return !operator==(Val); }
inline bool operator>(unsigned Val) { return (unsigned)*this > Val; }
inline bool operator<(unsigned Val) { return operator unsigned() < Val; }
inline bool operator>=(unsigned Val) { return operator unsigned() > Val; }
inline bool operator<=(unsigned Val) { return operator unsigned() < Val; }
inline bool operator>(int Val) { return operator int() > Val; }
inline bool operator<(int Val) { return operator int() < Val; }
inline bool operator>=(int Val) { return operator int() > Val; }
inline bool operator<=(int Val) { return operator int() < Val; }
inline bool operator==(int Val) { return operator int() == Val; }
inline bool operator==(unsigned Val) { return operator int() == Val; }
};
template<class BaseType>
class __TEXT_PROPERTY_GET
{
/*
BaseType must have this methods:
int BaseType::get_str_len(); - get element len
void BaseType::get_stl_str(std::basic_string<WCHAR>& ); - Get stl string wchar_t
void BaseType::get_stl_str(std::basic_string<CHAR>& ); - Get stl string char
size_t BaseType::get_str(char* Buffer, size_t Len); - Get c string from element
size_t BaseType::get_str(wchar_t* Buffer, size_t Len); - Get c string from element
*/
public:
class
{
friend __TEXT_PROPERTY_GET;
BaseType v;
public:
inline operator int() { return v.get_str_len(); }
} Length;
operator std::basic_string<WCHAR>() { std::basic_string<WCHAR> s; Length.v.get_stl_str(s); return s; }
operator std::basic_string<CHAR>() { std::basic_string<CHAR> s; Length.v.get_stl_str(s); return s; }
operator int() { char s[40] = {0}; Length.v.get_str(s, 39); return atoi(s); }
operator unsigned() { char s[40] = {0}; Length.v.get_str(s, 39); unsigned r = 0; sscanf(s, "%u", &r); return r; }
inline size_t operator()(LPWSTR Buffer, size_t Len = 0x0fffffff) { return Length.v.get_str(Buffer, Len); }
inline size_t operator()(LPSTR Buffer, size_t Len = 0x0fffffff) { return Length.v.get_str(Buffer, Len); }
inline bool operator==(const std::basic_string<WCHAR> & Str2) { return operator std::basic_string<WCHAR>() == Str2; }
inline bool operator==(const std::basic_string<CHAR> & Str2) { return operator std::basic_string<CHAR>() == Str2; }
inline bool operator==(LPCWSTR Str2) { return operator std::basic_string<WCHAR>() == Str2; }
inline bool operator==(LPCSTR Str2) { return operator std::basic_string<CHAR>() == Str2; }
template<class T>
inline bool operator!=(T Val) { return !operator==(Val); }
inline bool operator>(unsigned Val) { return (unsigned)*this > Val; }
inline bool operator<(unsigned Val) { return operator unsigned() < Val; }
inline bool operator>=(unsigned Val) { return operator unsigned() > Val; }
inline bool operator<=(unsigned Val) { return operator unsigned() < Val; }
inline bool operator>(int Val) { return operator int() > Val; }
inline bool operator<(int Val) { return operator int() < Val; }
inline bool operator>=(int Val) { return operator int() > Val; }
inline bool operator<=(int Val) { return operator int() < Val; }
inline bool operator==(int Val) { return operator int() == Val; }
inline bool operator==(unsigned Val) { return operator int() == Val; }
};
union
{
HWND hWnd;
/*
*std::string, LPCWSTR, LPSTR, int; Set, Get;
*Changes the text of the specified window's title bar.
*/
__TEXT_PROPERTY_SET_GET<__HWND_TEXT> Text;
/*
*int; Set, Get;
*Sets a new identifier of the child window. The window cannot be a top-level window.
*/
class
{
HWND hWnd;
public:
inline operator int() const { return ::GetDlgCtrlID(hWnd); }
int operator=(int NewId) { return (int)SetWindowLongPtr(hWnd, GWLP_ID, (LONG_PTR)NewId); }
} Id;
/*
*BOOL; Set, Get;
*Enables or disables mouse and keyboard input to the specified window or control.
*/
class
{
HWND hWnd;
public:
operator BOOL() const { return ::IsWindowEnabled(hWnd); }
BOOL operator=(BOOL isEnable)
{
::EnableWindow(hWnd, isEnable);
return isEnable;
}
} IsEnable;
/*
*WNDPROC; Set, Get;
*Sets a new address for the window procedure.
*/
class
{
HWND hWnd;
public:
inline operator WNDPROC() const { return (WNDPROC)GetWindowLongPtrW(hWnd, GWLP_WNDPROC); }
inline WNDPROC operator=(WNDPROC NewProc) { return (WNDPROC)SetWindowLongPtrW(hWnd, GWLP_WNDPROC, (LONG_PTR)NewProc); }
inline LRESULT CALLBACK operator()(UINT Msg, WPARAM wParam, LPARAM lParam) { return ::SendMessageW(hWnd, Msg, wParam, lParam); }
} WndProcW;
/*
*WNDPROC; Set, Get;
*Sets a new address for the window procedure.
*/
class
{
HWND hWnd;
public:
inline operator WNDPROC() const { return (WNDPROC)GetWindowLongPtrA(hWnd, GWLP_WNDPROC); }
inline WNDPROC operator=(WNDPROC NewProc) { return (WNDPROC)SetWindowLongPtrA(hWnd, GWLP_WNDPROC, (LONG_PTR)NewProc); }
inline LRESULT CALLBACK operator()(UINT Msg, WPARAM wParam, LPARAM lParam) { return ::SendMessageA(hWnd, Msg, wParam, lParam); }
} WndProcA;
/*
*<variant 4 or 8 bytes>; Set, Get;
*Sets the user data associated with the window.
*/
class
{
HWND hWnd;
public:
template<class T>
inline operator T() const { return (T)GetWindowLongPtr(hWnd, GWLP_USERDATA); }
template<class T>
inline T operator=(T NewData)
{
return (T)SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)NewData);
}
} UserData;
/*
*LONG_PTR; Set, Get;
*Sets a new extended window style.
*WS_EX_ ...
*/
class
{
HWND hWnd;
public:
inline operator LONG_PTR() const { return GetWindowLongPtr(hWnd, GWL_EXSTYLE); }
inline LONG_PTR operator=(LONG_PTR NewStyle) { return SetWindowLongPtr(hWnd, GWL_EXSTYLE, NewStyle); }
inline LONG_PTR operator |= (LONG_PTR AddStyle)
{
LONG_PTR lp = operator LONG_PTR() | AddStyle;
operator=(lp);
return lp;
}
inline LONG_PTR operator &= (LONG_PTR FilterStyle)
{
LONG_PTR lp = operator LONG_PTR() & FilterStyle;
operator=(lp);
return lp;
}
} ExStyle;
/*
*LONG_PTR; Set, Get;
*Sets a new window style.
* WS_ ...
*/
class
{
HWND hWnd;
public:
inline operator LONG_PTR() const { return GetWindowLongPtr(hWnd, GWL_STYLE); }
inline LONG_PTR operator=(LONG_PTR NewStyle) { return SetWindowLongPtr(hWnd, GWL_STYLE, NewStyle); }
inline LONG_PTR operator |= (LONG_PTR AddStyle)
{
LONG_PTR lp = operator LONG_PTR() | AddStyle;
operator=(lp);
return lp;
}
inline LONG_PTR operator &= (LONG_PTR FilterStyle)
{
LONG_PTR lp = operator LONG_PTR() & FilterStyle;
operator=(lp);
return lp;
}
} Style;
/*
*HINSTANCE; Set, Get;
*Sets a new application instance handle.
*/
class
{
HWND hWnd;
public:
inline operator HINSTANCE() const { return (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); }
inline HINSTANCE operator=(HINSTANCE NewInst) { return (HINSTANCE)SetWindowLongPtr(hWnd, GWLP_HINSTANCE, (LONG_PTR)NewInst); }
} Instance;
/*
*std::string, LPWSTR, LPSTR; Get;
*Retrieves the name of the class to which the specified window belongs.
*/
__TEXT_PROPERTY_GET<__HWND_NAME_CLASS> NameClass;
/*
*WNDCLASS, WNDCLASSEX; Get;
*Retrieves information about a window class, including a handle to the small icon associated with the window class.
*/
class
{
HWND hWnd;
public:
inline operator WNDCLASSW()
{
std::basic_string<WCHAR> Name = ((EX_WND*)this)->NameClass;
WNDCLASSW WndClass = {0};
GetClassInfoW(((EX_WND*)this)->Instance, Name.c_str(), &WndClass);
WndClass.lpszClassName = nullptr;
return WndClass;
}
inline operator WNDCLASSA()
{
std::basic_string<CHAR> Name = ((EX_WND*)this)->NameClass;
WNDCLASSA WndClass = {0};
GetClassInfoA(((EX_WND*)this)->Instance, Name.c_str(), &WndClass);
WndClass.lpszClassName = nullptr;
return WndClass;
}
inline operator WNDCLASSEXW()
{
std::basic_string<WCHAR> Name = ((EX_WND*)this)->NameClass;
WNDCLASSEXW WndClass = {0};
WndClass.cbSize = sizeof(WndClass);
GetClassInfoExW(((EX_WND*)this)->Instance, Name.c_str(), &WndClass);
WndClass.lpszClassName = nullptr;
return WndClass;
}
inline operator WNDCLASSEXA()
{
std::basic_string<CHAR> Name = ((EX_WND*)this)->NameClass;
WNDCLASSEXA WndClass = {0};
WndClass.cbSize = sizeof(WndClass);
GetClassInfoExA(((EX_WND*)this)->Instance, Name.c_str(), &WndClass);
WndClass.lpszClassName = nullptr;
return WndClass;
}
inline bool operator()(LPWNDCLASSW lpWndClass)
{
std::basic_string<WCHAR> Name = ((EX_WND*)this)->NameClass;
bool r = GetClassInfoW(((EX_WND*)this)->Instance, Name.c_str(), lpWndClass) != 0;
lpWndClass->lpszClassName = nullptr;
return r;
}
inline bool operator()(LPWNDCLASSA lpWndClass)
{
std::basic_string<CHAR> Name = ((EX_WND*)this)->NameClass;
bool r = GetClassInfoA(((EX_WND*)this)->Instance, Name.c_str(), lpWndClass) != 0;
lpWndClass->lpszClassName = nullptr;
return r;
}
inline bool operator()(LPWNDCLASSEXW lpWndClass)
{
std::basic_string<WCHAR> Name = ((EX_WND*)this)->NameClass;
bool r = GetClassInfoExW(((EX_WND*)this)->Instance, Name.c_str(), lpWndClass) != 0;
lpWndClass->lpszClassName = nullptr;
return r;
}
inline bool operator()(LPWNDCLASSEXA lpWndClass)
{
std::basic_string<CHAR> Name = ((EX_WND*)this)->NameClass;
bool r = GetClassInfoExA(((EX_WND*)this)->Instance, Name.c_str(), lpWndClass) != 0;
lpWndClass->lpszClassName = nullptr;
return r;
}
} Class;
/*
*HDC; Get;
*Retrieves a handle to a device context (DC) for the client area of a specified window or for the entire screen.
*/
class
{
HWND hWnd;
public:
inline operator HDC() const { return ::GetDC(hWnd); }
} Dc;
/*
*EX_WND__, HWND; Get, Set;
*Changes the parent window of the specified child window.
*/
class
{
HWND hWnd;
public:
inline operator EX_WND__() const { return ::GetParent(hWnd); }
inline operator HWND() const { return ::GetParent(hWnd); }
inline EX_WND__ operator=(EX_WND__ NewParent) { return ::SetParent(hWnd, NewParent); }
inline HWND operator=(HWND NewParent) { return ::SetParent(hWnd, NewParent); }
inline EX_WND__ operator()() { return ::GetParent(hWnd); }
} Parent;
/*
*bool; Get;
*Determines whether the specified window handle identifies an existing window.
*/
class
{
HWND hWnd;
public:
inline operator bool() const { return ::IsWindow(hWnd) != 0; }
} IsWindow;
/*
*bool; Get;
*Determines the visibility state of the specified window.
*/
class
{
HWND hWnd;
public:
inline operator bool() const { return ::IsWindowVisible(hWnd); }
} IsVisible;
/*
*bool; Get;
*Determines whether the specified window is a native Unicode window.
*/
class
{
HWND hWnd;
public:
inline operator bool() const { return ::IsWindowUnicode(hWnd); }
} IsUnicode;
/*
*bool; Get;
*Determines whether the specified window is minimized (iconic).
*/
class
{
HWND hWnd;
public:
inline operator bool() const { return ::IsIconic(hWnd); }
} IsIconic;
/*
*WND_COMBO__, HWND, EX_WND__; Get;
*Represet window as ComboBox.
*/
//WND_COMBO__ AsCombo;
class
{
HWND hWnd;
public:
inline operator LONG() const
{
RECT Rect;
::GetClientRect(hWnd, &Rect);
return Rect.right - Rect.left;
}
} ClientWidth;
class
{
HWND hWnd;
public:
inline operator LONG() const
{
RECT Rect;
::GetClientRect(hWnd, &Rect);
return Rect.bottom - Rect.top;
}
} ClientHeight;
/*
*long; Get, Set;
*Set or get window width.
*/
class
{
HWND hWnd;
public:
operator long() const
{
RECT Rect;
::GetWindowRect(hWnd, &Rect);
return Rect.right - Rect.left;
}
inline long operator=(long Val)
{
::SetWindowPos(hWnd, NULL, 0, 0, Val, EX_WND(hWnd).Height, SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER);
return Val;
}
} Width;
/*
*long; Get, Set;
*Set or get window height.
*/
class
{
HWND hWnd;
public:
inline operator long() const
{
RECT Rect;
::GetWindowRect(hWnd, &Rect);
return Rect.bottom - Rect.top;
}
inline long operator=(long Val)
{
::SetWindowPos(hWnd, NULL, 0, 0, EX_WND(hWnd).Width, Val, SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER);
return Val;
}
} Height;
class
{
HWND hWnd;
public:
operator LONG() const
{
RECT Rect;
::GetWindowRect(hWnd, &Rect);
MapWindowPoints(HWND_DESKTOP, ::GetParent(hWnd), (LPPOINT)&Rect, 1);
return Rect.left;
}
inline LONG operator= (LONG New)
{
SetWindowPos(hWnd, NULL, New, EX_WND(hWnd).Top, 0, 0, SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
return New;
}
} Left;
class
{
HWND hWnd;
public:
operator LONG() const
{
RECT Rect;
::GetWindowRect(hWnd, &Rect);
MapWindowPoints(HWND_DESKTOP, ::GetParent(hWnd), (LPPOINT)&Rect, 1);
return Rect.top;
}
inline LONG operator= (LONG New)
{
SetWindowPos(hWnd, NULL, EX_WND(hWnd).Left, New, 0, 0, SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
return New;
}
} Top;
class
{
HWND hWnd;
public:
inline operator LONG() const
{
RECT Rect;
::GetWindowRect(hWnd, &Rect);
MapWindowPoints(HWND_DESKTOP, ::GetParent(hWnd), ((LPPOINT)&Rect) + 1, 1);
return Rect.right;
}
inline LONG operator= (LONG New)
{
RECT Rect;
::GetWindowRect(hWnd, &Rect);
MapWindowPoints(HWND_DESKTOP, ::GetParent(hWnd), (LPPOINT)&Rect, 2);
SetWindowPos(hWnd, NULL, 0, 0, New - Rect.left, Rect.bottom - Rect.top, SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER);
return New;
}
} Right;
class
{
HWND hWnd;
public:
inline operator LONG() const
{
RECT Rect;
::GetWindowRect(hWnd, &Rect);
MapWindowPoints(HWND_DESKTOP, ::GetParent(hWnd), ((LPPOINT)&Rect) + 1, 1);
return Rect.bottom;
}
inline LONG operator= (LONG New)
{
RECT Rect;
::GetWindowRect(hWnd, &Rect);
MapWindowPoints(HWND_DESKTOP, ::GetParent(hWnd), (LPPOINT)&Rect, 2);
SetWindowPos(hWnd, NULL, 0, 0, Rect.right - Rect.left, New - Rect.top, SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER);
return New;
}
} Bottom;
class
{
HWND hWnd;
public:
inline operator RECT() const
{
RECT Rect;
::GetWindowRect(hWnd, &Rect);
MapWindowPoints(HWND_DESKTOP, ::GetParent(hWnd), (LPPOINT)&Rect, 2);
return Rect;
}
inline RECT& operator= (RECT& New)
{
SetWindowPos(hWnd, NULL, New.left, New.top, New.right - New.left, New.bottom - New.top, SWP_NOOWNERZORDER | SWP_NOZORDER);
return New;
}
bool operator ==(const RECT& Val) const
{
RECT Rect = operator RECT();
return (Rect.bottom == Val.bottom) && (Rect.left == Val.left) && (Rect.right == Val.right) && (Rect.top == Val.top);
}
inline bool operator !=(const RECT& Val) const { return !operator ==(Val); }
bool Contains(const RECT& Another)
{
RECT Rect = operator RECT();
return (Another.bottom < Rect.bottom) && (Another.top > Rect.top) && (Another.left > Rect.left) && (Another.right < Rect.right);
}
bool Contains(const POINT& Another)
{
RECT Rect = operator RECT();
return (Another.x < Rect.right) && (Another.x > Rect.left) && (Another.y < Rect.bottom) && (Another.y > Rect.top);
}
bool Contains(LONG x, LONG y)
{
RECT Rect = operator RECT();
return (x < Rect.right) && (x > Rect.left) && (y < Rect.bottom) && (y > Rect.top);
}
} Rectangle;
class
{
HWND hWnd;
public:
inline operator RECT() const
{
RECT Rect;
::GetWindowRect(hWnd, &Rect);
return Rect;
}
inline RECT& operator= (RECT& New)
{
RECT Rect = New;
MapWindowPoints(HWND_DESKTOP, ::GetParent(hWnd), (LPPOINT)&Rect, 2);
SetWindowPos(hWnd, NULL, Rect.left, Rect.top, Rect.right - Rect.left, Rect.bottom - Rect.top, SWP_NOOWNERZORDER | SWP_NOZORDER);
return New;
}
bool operator ==(const RECT& Val) const
{
RECT Rect = operator RECT();
return (Rect.bottom == Val.bottom) && (Rect.left == Val.left) && (Rect.right == Val.right) && (Rect.top == Val.top);
}
inline bool operator !=(const RECT& Val) const { return !operator ==(Val); }
bool Contains(const RECT& Another)
{
RECT Rect = operator RECT();
return (Another.bottom < Rect.bottom) && (Another.top > Rect.top) && (Another.left > Rect.left) && (Another.right < Rect.right);
}
bool Contains(const POINT& Another)
{
RECT Rect = operator RECT();
return (Another.x < Rect.right) && (Another.x > Rect.left) && (Another.y < Rect.bottom) && (Another.y > Rect.top);
}
bool Contains(LONG x, LONG y)
{
RECT Rect = operator RECT();
return (x < Rect.right) && (x > Rect.left) && (y < Rect.bottom) && (y > Rect.top);
}
} RectangleRelScreen;
class
{
HWND hWnd;
public:
inline operator RECT() const
{
RECT Rect;
::GetClientRect(hWnd, &Rect);
MapWindowPoints(HWND_DESKTOP, ::GetParent(hWnd), (LPPOINT)&Rect, 2);
return Rect;
}
bool operator ==(const RECT& Val) const
{
RECT Rect = operator RECT();
return (Rect.bottom == Val.bottom) && (Rect.left == Val.left) && (Rect.right == Val.right) && (Rect.top == Val.top);
}
inline bool operator !=(const RECT& Val) const { return !operator ==(Val); }
bool Contains(const RECT& Another)
{
RECT Rect = operator RECT();
return (Another.bottom < Rect.bottom) && (Another.top > Rect.top) && (Another.left > Rect.left) && (Another.right < Rect.right);
}
bool Contains(const POINT& Another)
{
RECT Rect = operator RECT();
return (Another.x < Rect.right) && (Another.x > Rect.left) && (Another.y < Rect.bottom) && (Another.y > Rect.top);
}
bool Contains(LONG x, LONG y)
{
RECT Rect = operator RECT();
return (x < Rect.right) && (x > Rect.left) && (y < Rect.bottom) && (y > Rect.top);
}
} ClientRectangle;
/*
*HFONT; Get, Set;
*Set or get current font of window.
*/
class
{
HWND hWnd;
public:
/*
Use CreateFont for set new font.
Example:
CreateFont (14, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_SWISS, L"Times New Roman");
*/
inline operator HFONT() const
{
//GetCharABCWidths
return (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0);
}
inline HFONT operator=(HFONT NewFont)
{
SendMessage(hWnd, WM_SETFONT, (WPARAM)NewFont, TRUE);
return NewFont;
}
} Font;
/*
*HMENU; Get, Set;
*Set or get current menu of window.
*/
class
{
HWND hWnd;
public:
inline operator HMENU() const
{
//use CreateMenu
return GetMenu(hWnd);
}
inline HMENU operator=(HMENU NewMenu)
{
SetMenu(hWnd, NewMenu);
return NewMenu;
}
} Menu;
/*
*HRGN; Get, Set;
*Set or get current menu of window.
*/
class
{
HWND hWnd;
public:
/*
@RgnDest - region for copy. use CreateRectRgn
@return
NULLREGION
SIMPLEREGION
COMPLEXREGION
ERROR
*/
inline int operator()(HRGN RgnDest) { return GetWindowRgn(hWnd, RgnDest); }
inline HRGN operator=(HRGN New)
{
SetWindowRgn(hWnd, New, TRUE);
return New;
}
} Region;
};
inline operator HWND() const { return hWnd; }
inline EX_WND__() { hWnd = NULL; }
inline EX_WND__(HWND nhWnd) { hWnd = nhWnd; }
inline operator bool() { return hWnd != NULL; }
inline operator EX_WND__*() { return this; }
inline bool operator !() { return hWnd == NULL; }
private:
class _FOR_GET_ADDRESS
{
HWND hWnd;
public:
inline operator HWND*() { return &hWnd; }
inline operator EX_WND__*() { return (EX_WND__*)&hWnd; }
};
public:
inline _FOR_GET_ADDRESS & operator &() { return *(_FOR_GET_ADDRESS*)this; }
inline bool operator==(HWND Wnd) const { return Wnd == hWnd; }
inline bool operator!=(HWND Wnd) const { return Wnd != hWnd; }
inline bool operator==(EX_WND__ Wnd) const { return Wnd.hWnd == hWnd; }
inline bool operator!=(EX_WND__ Wnd) const { return Wnd.hWnd != hWnd; }
inline EX_WND__ operator[](int nIDDlgItem) { return GetDlgItem(hWnd, nIDDlgItem); }
inline bool BringToTop() { return BringWindowToTop(hWnd) != FALSE; }
inline bool Show(int nCmdShow = SW_SHOW) { return ShowWindow(hWnd, nCmdShow) != FALSE; }
inline bool Update() { return UpdateWindow(hWnd) != FALSE; }
inline bool Invalidate() { return InvalidateRect(hWnd, NULL, FALSE) != FALSE; }
inline bool Invalidate(const RECT *lpRect) { return InvalidateRect(hWnd, lpRect, FALSE) != FALSE; }
inline bool Validate(RECT * lpRect) { return ::ValidateRect(hWnd, lpRect) != FALSE; }
inline bool Validate() { return ::ValidateRect(hWnd, NULL) != FALSE; }
inline EX_WND__ Focus() { return (EX_WND__)::SetFocus(hWnd); }
static inline EX_WND__ GetFocus() { return (EX_WND__)::GetFocus(); }
static inline EX_WND CreateDlg(int IdRes, DLGPROC WindowProc, HINSTANCE ProcessHandler = NULL, HWND ParentWindowHandler = NULL)
{
return CreateDialog(ProcessHandler, MAKEINTRESOURCE(IdRes), ParentWindowHandler, WindowProc);
}
static inline EX_WND CreateDlg(LPCSTR Name, DLGPROC WindowProc, HINSTANCE ProcessHandler = NULL, HWND ParentWindowHandler = NULL)
{
return CreateDialogA(ProcessHandler, Name, ParentWindowHandler, WindowProc);
}
static inline EX_WND CreateDlg(LPCWSTR Name, DLGPROC WindowProc, HINSTANCE ProcessHandler = NULL, HWND ParentWindowHandler = NULL)
{
return CreateDialogW(ProcessHandler, Name, ParentWindowHandler, WindowProc);
}
static void EnterMainLoop()
{
for(MSG msg; GetMessage(&msg, NULL, NULL, NULL);)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
static void EnterMainLoop(DLGPROC ProcForInterceptKeys)
{
for(MSG msg; GetMessage(&msg, NULL, NULL, NULL);)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if((msg.message == WM_KEYDOWN) || (msg.message == WM_KEYUP))
ProcForInterceptKeys(msg.hwnd, msg.message, msg.wParam, msg.lParam);
}
}
/////////
inline bool ShowContextMenu(HMENU hMenu, UINT Flags = TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY)
{
//Use CreatePopupMenu for creating menu
POINT Poi;
GetCursorPos(&Poi);
return TrackPopupMenu(hMenu, Flags, Poi.x, Poi.y, 0, hWnd, NULL) != FALSE;
}
inline bool ShowContextMenu(HMENU hMenu, UINT Flags, int x, int y) { return TrackPopupMenu(hMenu, Flags, x, y, 0, hWnd, NULL) != FALSE; }
static inline EX_WND__ ByPoint(LPPOINT Point) { return (EX_WND__)::WindowFromPoint(*Point); }
inline bool IsChild(HWND Wnd) const { return ::IsChild(hWnd, Wnd) == TRUE; }
////
/*Close window.*/
inline bool Close() { return ::CloseWindow(hWnd) != FALSE; }
/*Destroys window. */
inline bool Destroy() { return ::DestroyWindow(hWnd) != FALSE; }
/*The CreateCompatibleDC function creates a memory device context (DC) compatible with the window.*/
inline HDC CreateCompatibleDC() { return ::CreateCompatibleDC(::GetDC(hWnd)); }
/*The BeginPaint function prepares the specified window for painting and fills
a PAINTSTRUCT structure with information about the painting.*/
inline HDC BeginPaint(LPPAINTSTRUCT ps) { return ::BeginPaint(hWnd, ps); }
/*The EndPaint function marks the end of painting in the specified window.*/
inline bool EndPaint(LPPAINTSTRUCT ps) { return ::EndPaint(hWnd, ps) != FALSE; }
/*Destroys a modal dialog box, causing the system to end any processing for the dialog box.*/
inline bool EndDialog(INT_PTR Result = 0) { return ::EndDialog(hWnd, Result) != FALSE; }
/*Creates a timer with the specified time-out value.*/
inline UINT_PTR SetTimer(UINT Time, UINT_PTR nIDEvent = NULL, TIMERPROC tp = NULL) { return ::SetTimer(hWnd, nIDEvent, Time, tp); }
/*Destroys the specified timer.*/