-
Notifications
You must be signed in to change notification settings - Fork 71
/
SBAR.ahk
2204 lines (1989 loc) · 70.4 KB
/
SBAR.ahk
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
/*
Title: SBAR Library v0.0.1 (Preview)
Group: Introduction
The status bar was first introduced as a standard OS control as part of the
Windows 95 common control library. A few features have been added over the
years but the functionality hasn't changed much. This library was created
to help exploit the capabilities of the status bar control.
Group: AutoHotkey Compatibility
This library is designed to run on all versions of AutoHotkey v1.1+: ANSI,
Unicode, and Unicode 64-bit.
Group: Common Parameters
Common function parameters of note.
*hSB*
This input parameter should contain the handle to the status bar.
hSB is the de facto first parameter for most of the library functions. It
is critical to the success of the library. So much so, that it's value is
never tested. If the hSB parameter contains an invalid value, most of the
library functions will fail. Most status bar messages that use an invalid
hSB value will set ErrorLevel to FAIL.
*p_PartNumber*
This input parameter should contain the 1-based index of the status bar
part. For most (but not all) functions, the default value for this
parameter is 1.
Group: Issues and Considerations
Miscellaneous issues and considerations.
Topic: Documentation vs. Observation
Some of the information in the document is based on the information
gleaned from the AutoHotkey and Microsoft documentation. Unfortunately,
the Microsoft documentation on this topic is limited and some of it is
outdated. As a result, some of the information in this document is
based on observation and testing. If any of this information is
incorrect, please make a noise!
Topic: DPI-Aware
The functions in this library are not DPI-aware. Specified position and
size values are used as-is and the values returned from library
functions are not adjusted to reflect a non-standard screen DPI.
Starting with AutoHotkey v1.1.11, a "DPIScale" option was added for
AutoHotkey GUIs which makes most "gui" commands DPI-aware. Although the
AutoHotkey "gui" commands will not interfere with with any of the
library commands (and vice versa), the size and position used by each
may be incompatible when used on a computer that is using a non-standard
DPI. The DPIScale feature is enabled by default so if necessary, it
must be manually disabled for each GUI by adding a "gui -DPIScale"
command.
The native <SB_SetParts at
https://autohotkey.com/docs/commands/GuiControls.htm#SB_SetParts> and
<SB_SetIcon at
https://autohotkey.com/docs/commands/GuiControls.htm#SB_SetIcon>
functions are DPI-aware. However, only the SB_SetParts function
responds correctly to changes to the DPIScale option. The SB_SetIcon
function effectively ignores the DPIScale option.
Topic: Font
When the AutoHotkey "gui Add,StatusBar" command is used to create the
status bar (the default method), AutoHotkey sets the status bar font to
last font defined before the command is performed. If no specific font
was set, the default GUI font is used. To use a unique font for the
text in the status bar, set the font immediately before performing the
"gui Add,StatusBar" command. For example:
(start code)
gui Font,s10,Arial
gui Add,StatusBar,hWndhSB
gui Font ;-- Reset to the default GUI font
(end)
Changing the font after the status bar has been created can be done by
sending the WM_SETFONT message. See <SBAR_SetFont> for more
information.
See the example scripts for an example on how to use the Fnt library to
set the system non-client font for the status bar.
Topic: Height
In general, the height of the status bar is considered static. The
Microsoft documentation states that the height of the status bar is
determined by the font but in reality, there are other factors.
If the status bar is created with visual styles enabled (the default for
most computers), a fixed-height status bar is created. The status bar
font does not change anything but the screen DPI is taken into
consideration. If visual styles are disabled or are disabled after the
status bar has been created, changes to the font will automatically
increase or decrease the height of the status bar.
<SBAR_SetMinHeight> can be used to force the status bar to accommodate
the status bar font and/or the height of the desired entity -- animation
clip, icon, image (Ex: bitmap), whatever -- but there is always the
danger that increasing the status bar height will take up too much
screen real estate or will make the status bar look clunky.
Topic: Icons
When used with <SBAR_ExtractIcon>, the <SBAR_SetIcon> and
<SBAR_SetSimpleIcon> functions duplicate much of the functionality of
the native <SB_SetIcon at
https://autohotkey.com/docs/commands/GuiControls.htm#SB_SetIcon>
function. The difference is that the SBAR_ExtractIcon function requires
a specific icon size rather than letting the program determine the icon
size. Although it can introduce some additional code, it allows the
developers to choose the optimal icon size rather than taking the chance
that the icon might be scaled to fit. Although scaled icons are
acceptable in many cases, they never look as good as icons shown at
their optimal size.
Topic: Remote Status Bars
This library is designed to be used on status bars that are created in
the same process that the script is running. Yes, some of the messages
will work on a remote status bar in certain conditions but most will
not. The exception is the <SBAR_SetTextEx> add-on. See the function
documentation for more information.
Topic: Simple Mode
Preface: Unfortunately, the simple mode status bar is a hodgepodge
feature that was implemented without clear forethought and planning. It
certainly can provide value but any use of the simple mode status bar
requires a clear understanding of the limitations and the extra
programming that may be necessary to accomodate for it's use.
The status bar offers two modes: Simple and nonsimple (the default). The
simple mode is a single-part status bar and the nonsimple mode is a
multi-part status bar with up to 255 parts. Microsoft uses part 255
(256 for a 1-based index) to contain the text for the simple mode. This
design ensures that changes to the status bar text that are made while
in simple mode do not interfere with the text set in the nonsimple mode.
Use <SBAR_SetSimple> to toggle between simple and nonsimple mode.
Many status bar messages work regardless of the current status bar mode.
For example, the SB_SETTEXT message always works. This is useful
because it allows threads that are updating the status bar in the
background to continue to operate regardless of the status bar mode.
Some library functions only work correctly if the status bar is in
simple mode. For example, <SBAR_GetSimpleText> and
<SBAR_GetSimpleTextStyle> only work if the status bar is in simple mode.
Some status bar messages only work correctly if the status bar is in
nonsimple mode. For example, the SB_GETRECT message only works if the
status bar is in nonsimple mode. This can be a problem if this message
is used in combination with the SB_SETTEXT message.
Although not recommended for all situations, one possible workaround to
messages or library functions that only work in a particular mode is to
to 1) temporarily change the status bar to desired mode, i.e. simple or
nonsimple, 2) call the previously-incompatible function, and then 3)
revert back to previous mode. Observation: There does not appear to be
any flickering when this is done.
Simple and nonsimple message idiosyncrasies have been documented in the
affected functions. Unfortunately, there are quite a few functions with
these type of restrictions so be sure to check each function before
using.
Topic: Visual Styles
Some status bar features don't work if visual styles are enabled. For
Windows themes that utilize a visual style, messages that change the
visual characteristics of the status bar are effectively ignored. The
only way to get these messages to work as intended is to disable the
visual styles. Messages of note include SB_SETTEXT (when setting some
text styles) and SB_SETBKCOLOR.
For the WM_SETFONT message, the status bar responds differently
depending or whether or not visual styles are enabled. See
<SBAR_SetFont> for more information.
If needed, use the gui "-Theme" option when creating the status bar (Ex :
"gui Add,StatusBar,-Theme") to set the status bar to the default visual
style, i.e. the Windows Classic theme. Alternatively,
<SBAR_VisualStyles> can be used to disable the visual styles of the
status bar as needed.
Hint: Most computer users use a theme that employs visual styles by
default. Although visual styles can be disabled in some cases, the look
and operation of the status bar is changed from what has become the
norm. In most cases, it's best to design an application with the
assumption that visual styles will be used.
Group: Links
Status Bar Reference at MSDN :
* <https://msdn.microsoft.com/en-us/library/windows/desktop/ff486038(v=vs.85).aspx>
Group: Functions
*/
;------------------------------
;
; Function: SBAR_ColorName2RGB
;
; Description:
;
; Convert a color name to it's 6-digit hexadecimal RGB value.
;
; Type:
;
; Internal function. Subject to change. Do not use.
;
; Parameters:
;
; p_ColorName - A color name (Ex: "Fuchsia"). See the function's static
; variables for a list of supported names.
;
; Returns:
;
; A 6-digit hexadecimal RGB value. Ex: 0xFF00FF. If an invalid/unsupported
; color name is specified, the original p_ColorName value is is returned.
;
; Remarks:
;
; Only the 16 primary HTML color names are supported at this time.
;
;-------------------------------------------------------------------------------
SBAR_ColorName2RGB(p_ColorName)
{
Static Dummy27829226
;-- Supported color names
,Color_Aqua :=0x00FFFF
,Color_Black :=0x000000
,Color_Blue :=0x0000FF
,Color_Fuchsia:=0xFF00FF
,Color_Gray :=0x808080
,Color_Green :=0x008000
,Color_Lime :=0x00FF00
,Color_Maroon :=0x800000
,Color_Navy :=0x000080
,Color_Olive :=0x808000
,Color_Purple :=0x800080
,Color_Red :=0xFF0000
,Color_Silver :=0xC0C0C0
,Color_Teal :=0x008080
,Color_White :=0xFFFFFF
,Color_Yellow :=0xFFFF00
;-- Convert if supported color name (not case sensitive)
l_Color:=p_ColorName
if Color_%p_ColorName% is not Space
l_Color:=Color_%p_ColorName%
Return l_Color
}
;------------------------------
;
; Function: SBAR_DisableVisualStyles
;
; Description:
;
; Disable (remove) the visual styles for a status bar control.
;
; Calls To Other Functions:
;
; * <SBAR_VisualStyles>
;
;-------------------------------------------------------------------------------
SBAR_DisableVisualStyles(hSB)
{
SBAR_VisualStyles(hSB,False)
}
;------------------------------
;
; Function: SBAR_EnableVisualStyles
;
; Description:
;
; Enable visual styles for a status bar control.
;
; Calls To Other Functions:
;
; * <SBAR_VisualStyles>
;
;-------------------------------------------------------------------------------
SBAR_EnableVisualStyles(hSB)
{
SBAR_VisualStyles(hSB,True)
}
;------------------------------
;
; Function: SBAR_ExtractIcon
;
; Description:
;
; Extract an icon or other image from a file.
;
; Parameters:
;
; p_File - The file that has one or more images. See the *Remarks* section
; for more information.
;
; p_IconIndex - The 1-based icon index of the icon to extract. Set to 1 to
; extract the first icon, 2 for the second icon, and so on. If there is
; only one icon, set to 1.
;
; xIcon, yIcon - The size of the icons to extract, in pixels. If the yIcon
; parameter is not specified, it is set to the value of xIcon.
;
; Returns:
;
; The handle of the extracted icon or FALSE if there was a problem.
;
; Calls To Other Functions:
;
; * <SBAR_SystemMessage>
;
; Credit:
;
; Some code for this function extracted from the MI_ExtractIcon function.
; Author: lexikos
;
; Remarks:
;
; This function extracts images from executable (.exe), DLL (.dll), icon
; (.ico), cursor (.cur), animated cursor (.ani), and bitmap (.bmp) files.
; Extractions from Windows 3.x 16-bit executables (.exe or .dll) are also
; supported.
;
; The PrivateExtractIcons system function will search the path for the file so
; specifying the full path is only necessary if the file is not in the path.
; So, setting p_File to "shell32.dll" is the same as setting it to
; "C:\Windows\System32\shell32.dll" or whatever the full path for this file
; is.
;
; All icons extracted by this function should be destroyed by calling the
; DestroyIcon system function.
;
;-------------------------------------------------------------------------------
SBAR_ExtractIcon(p_File,p_IconIndex,xIcon,yIcon:="")
{
Static LR_DEFAULTCOLOR:=0x0
;-- Parameters
if not yIcon ;-- null/blank or 0
yIcon:=xIcon
;-- Extract icon
; Note: The return type is set to Int because -1 is one of the possible
; return values.
RC:=DllCall("PrivateExtractIcons"
,"Str",p_File ;-- lpszFile
,"Int",p_IconIndex-1 ;-- nIconIndex
,"Int",xIcon ;-- cxIcon
,"Int",yIcon ;-- cyIcon
,"Ptr*",hIcon ;-- *phicon
,"Ptr*",0 ;-- *piconid
,"UInt",1 ;-- nIcons
,"UInt",LR_DEFAULTCOLOR ;-- flags
,"Int") ;-- Return type
if (RC=-1) or ErrorLevel
{
l_Message:=""
if (RC=-1)
l_Message.="Return=" . RC
if ErrorLevel
l_Message.=(StrLen(l_Message) ? ", ":"")
. "ErrorLevel=" . ErrorLevel
if A_LastError
l_Message.=", "
. "A_LastError=" . A_LastError . " - "
. SBAR_SystemMessage(A_LastError)
outputdebug,
(ltrim join`s
Function: %A_ThisFunc% - PrivateExtractIcons failure. %l_Message%
)
Return False
}
;-- Return the handle to the icon
Return hIcon
}
;------------------------------
;
; Function: SBAR_GetBorders
;
; Description:
;
; Get the current widths of the horizontal and vertical borders of the status
; bar.
;
; Parameters:
;
; r_HorzW - [Output, Optional] Variable that contains the width of the
; horizontal border.
;
; r_VertW - [Output, Optional] Variable that contains the width of the
; vertical border.
;
; r_RectW - [Output, Optional] Variable that contains the width of the
; border between rectangles.
;
; Returns:
;
; If successful, the output variables are updated with their respective border
; values and TRUE is returned. If not successful, all of the output variables
; are set to 0 and FALSE is returned.
;
;-------------------------------------------------------------------------------
SBAR_GetBorders(hSB,ByRef r_HorzW:="",ByRef r_VertW:="",ByRef r_RectW:="")
{
Static SB_GETBORDERS:=0x407 ;-- WM_USER + 7
;-- Initialize
VarSetCapacity(l_BorderArray,12,0)
;-- Enough space for 3 integers
;-- Get borders
SendMessage SB_GETBORDERS,0,&l_BorderArray,,ahk_id %hSB%
if not ErrorLevel
{
r_HorzW:=r_VertW:=r_RectW:=0
Return False
}
;-- Update the output variables
r_HorzW:=NumGet(l_BorderArray,0,"Int")
r_VertW:=NumGet(l_BorderArray,4,"Int")
r_RectW:=NumGet(l_BorderArray,8,"Int")
Return True
}
;------------------------------
;
; Function: SBAR_GetFont
;
; Description:
;
; Get the font with which the status bar is currently drawing its text.
;
; Returns:
;
; The handle to the font used by the status bar or 0 if the using the system
; font.
;
;-------------------------------------------------------------------------------
SBAR_GetFont(hSB)
{
Static WM_GETFONT:=0x31
SendMessage WM_GETFONT,0,0,,ahk_id %hSB%
Return ErrorLevel
}
;------------------------------
;
; Function: SBAR_GetIcon
;
; Description:
;
; Get the icon for a status bar part.
;
; Parameters:
;
; See <Common Parameters> for more information.
;
; Returns:
;
; The handle to the icon (tests as TRUE) if successful, otherwise 0 (FALSE).
;
; Remarks:
;
; Use <SBAR_GetSimpleIcon> to get the icon for a simple mode status bar.
;
;-------------------------------------------------------------------------------
SBAR_GetIcon(hSB,p_PartNumber:=1)
{
Static SB_GETICON:=0x414 ;-- WM_USER + 20
SendMessage SB_GETICON,p_PartNumber-1,0,,ahk_id %hSB%
Return ErrorLevel
}
;------------------------------
;
; Function: SBAR_GetIconSize
;
; Description:
;
; Get the icon size from the specified part of a status bar.
;
; Parameters:
;
; See <Common Parameters> for more information.
;
; r_Width, r_Height - [Output, Optional] If defined, these variables are set
; to the width and height of the status bar icon. If the status bar does
; not have an icon or if there was an error, these variables are set to 0.
;
; Returns:
;
; The address to a SIZE structure (tests as TRUE) if successful, otherwise
; FALSE.
;
; Calls To Other Functions:
;
; * <SBAR_GetIcon>
;
;-------------------------------------------------------------------------------
SBAR_GetIconSize(hSB,p_PartNumber:=1,ByRef r_Width:="",ByRef r_Height:="")
{
Static SIZE
;-- Initialize
VarSetCapacity(SIZE,8,0)
r_Width:=r_Height:=0
;-- Get the handle to the icon. Bounce if there is no icon.
if not hIcon:=SBAR_GetIcon(hSB,p_PartNumber)
Return False
;-- Get icon info. Bounce if the icon is not found.
VarSetCapacity(ICONINFO,A_PtrSize=8 ? 32:24,0)
if not DllCall("GetIconInfo","Ptr",hIcon,"Ptr",&ICONINFO)
Return False
hbmMask :=NumGet(ICONINFO,A_PtrSize=8 ? 16:12,"Ptr")
hbmColor:=NumGet(ICONINFO,A_PtrSize=8 ? 24:16,"Ptr")
;-- Get bitmap info
VarSetCapacity(BITMAP,A_PtrSize=8 ? 32:24,0)
RC:=DllCall("GetObject","Ptr",hbmMask,"Int",A_PtrSize=8 ? 32:24,"Ptr",&BITMAP)
DllCall("DeleteObject","Ptr",hbmColor)
DllCall("DeleteObject","Ptr",hbmMask)
if not RC
Return False
;-- Update the output variables
r_Width :=NumGet(BITMAP,4,"Int") ;-- bmWidth
bmHeight:=NumGet(BITMAP,8,"Int") ;-- bmHeight
r_Height:=hbmColor ? bmHeight:bmHeight/2
;-- Populate the SIZE structure and return
NumPut(r_Width, SIZE,0,"Int") ;-- cx
NumPut(r_Height,SIZE,4,"Int") ;-- cy
Return &SIZE
}
;------------------------------
;
; Function: SBAR_GetMaxTextWidth
;
; Description:
;
; Returns the maximum width of a status bar part, in pixels, that can be
; used to display text.
;
; Type:
;
; Preview/Experimental. Subject to change.
;
; Parameters:
;
; See <Common Parameters> for more information.
;
; Calls To Other Functions:
;
; * <SBAR_GetBorders>
; * <SBAR_GetIconSize>
; * <SBAR_GetPartWidth>
;
; Remarks:
;
; This function only works correctly when the status bar is in nonsimple (i.e.
; standard) mode. If used while in simple mode, invalid values may be
; returned. If necessary, use <SBAR_IsSimple> to check the status bar mode
; before calling this function.
;
; Any change to the status bar part can change the amount of space that is
; available for text. This includes changing the part size, adding an icon,
; changing the icon (if a different icon size), or removing the icon.
;
; Experimental:
;
; At this writing, the function is returning what appears to be the correct
; width in all cases. Unfortunately, the function is using system values
; (Ex: vertical border width and rectangle border width) that have nothing to
; do with the spacing gaps that are found when text is displayed in a status
; bar part. These system values just happen to match the gaps but there is
; absolutely no documentation on what values Microsoft uses when setting the
; status bar text. Effectively, the function is using a best-guest
; calculation. This function will be marked as "Experimental" until this
; information can be found or until this function has been tested by a number
; of developers on a number of different environments.
;
;-------------------------------------------------------------------------------
SBAR_GetMaxTextWidth(hSB,p_PartNumber:=1)
{
SBAR_GetBorders(hSB,,l_VertBorderW,l_RectBorderW)
l_MaxTextW:=SBAR_GetPartWidth(hSB,p_PartNumber)
l_MaxTextW-=l_VertBorderW+l_RectBorderW
;-- Experimental
l_MaxTextW+=1
;-- Adjust if the part has an icon
if SBAR_GetIconSize(hSB,p_PartNumber,l_IconW)
l_MaxTextW-=l_IconW+l_VertBorderW+l_RectBorderW
Return l_MaxTextW
}
;------------------------------
;
; Function: SBAR_GetPartHeight
;
; Description:
;
; Get the height of a status bar part.
;
; Parameters:
;
; See <Common Parameters> for more information.
;
; Returns:
;
; The height of the bounding rectangle of the requested part. Note: This is
; not the same as the height of the status bar control.
;
; Remarks:
;
; This function only works correctly when the status bar is in nonsimple (i.e.
; standard) mode. If used while in simple mode, the SB_GETRECT message fails
; (returns FALSE (0)). If necessary, use <SBAR_IsSimple> to check the status
; bar mode before calling this function.
;
;-------------------------------------------------------------------------------
SBAR_GetPartHeight(hSB,p_PartNumber:=1)
{
Static SB_GETRECT:=0x40A ;-- WM_USER + 10
VarSetCapacity(RECT,16,0)
SendMessage SB_GETRECT,p_PartNumber-1,&RECT,,ahk_id %hSB%
Return ErrorLevel ? NumGet(RECT,12,"Int")-NumGet(RECT,4,"Int"):0
;-- Right - Left
}
;------------------------------
;
; Function: SBAR_GetPartRect
;
; Description:
;
; Get the bounding rectangle of a status bar part.
;
; Parameters:
;
; See <Common Parameters> for more information.
;
; r_Left..r_Bottom - [Output, Optional]
;
; Returns:
;
; The address to a RECT structure (tests as TRUE) is returned in all cases.
; If successful, the RECT structure contains the bounding rectangle of the
; specified status bar part. In addition, the output variables
; (r_Left...r_Bottom) are updated with the associated values. If not
; successful, all members of the RECT structure are set to 0 and all output
; variables are set to 0.
;
; Remarks:
;
; This function only works correctly when the status bar is in nonsimple (i.e.
; standard) mode. If used while in simple mode, the SB_GETRECT message fails
; (returns FALSE (0)). If necessary, use <SBAR_IsSimple> to check the status
; bar mode before calling this function.
;
;-------------------------------------------------------------------------------
SBAR_GetPartRect(hSB,p_PartNumber:=1,ByRef r_Left:="",ByRef r_Top:="",ByRef r_Right:="",ByRef r_Bottom:="")
{
Static Dummy71709663
,RECT
;-- Messages
,SB_GETRECT:=0x40A ;-- WM_USER + 10
;-- Get the bounding rectangle of a part
VarSetCapacity(RECT,16,0)
SendMessage SB_GETRECT,p_PartNumber-1,&RECT,,ahk_id %hSB%
if not ErrorLevel
{
r_Left:=r_Top:=r_Right:=r_Bottom:=0
Return &RECT
}
;-- Populate the output variables
r_Left :=NumGet(RECT,0,"Int")
r_Top :=NumGet(RECT,4,"Int")
r_Right :=NumGet(RECT,8,"Int")
r_Bottom:=NumGet(RECT,12,"Int")
Return &RECT
}
;------------------------------
;
; Function: SBAR_GetPartWidth
;
; Description:
;
; Get the width of a status bar part.
;
; Parameters:
;
; See <Common Parameters> for more information.
;
; Returns:
;
; The width of the bounding rectangle of the requested part if successful,
; otherwise FALSE (0).
;
; Remarks:
;
; This function only works correctly when the status bar is in nonsimple (i.e.
; standard) mode. If used while in simple mode, the SB_GETRECT message fails
; (returns FALSE (0)). If necessary, use <SBAR_IsSimple> to check the status
; bar mode before calling this function.
;
;-------------------------------------------------------------------------------
SBAR_GetPartWidth(hSB,p_PartNumber:=1)
{
Static SB_GETRECT:=0x40A ;-- WM_USER + 10
VarSetCapacity(RECT,16,0)
SendMessage SB_GETRECT,p_PartNumber-1,&RECT,,ahk_id %hSB%
Return ErrorLevel ? NumGet(RECT,8,"Int")-NumGet(RECT,0,"Int"):0
;-- Right - Left
}
;------------------------------
;
; Function: SBAR_GetParts
;
; Description:
;
; Get the coordinate of the right edge of the status bar parts.
;
; Parameters:
;
; r_Parts - [Output] Variable that contains a simple linear array that has the
; same number of elements as the number of status bar parts. Each element
; in the array contains the client coordinate of the right edge of the
; corresponding part. If an element is set to -1, the position of the
; right edge for that part extends to the right edge of the status bar.
;
; Returns:
;
; The number of parts in the status bar.
;
;-------------------------------------------------------------------------------
SBAR_GetParts(hSB,byRef r_Parts)
{
Static SB_GETPARTS:=0x406 ;-- WM_USER+6
;-- Initialize
r_Parts:=[]
;-- Get the number of status bar parts
SendMessage SB_GETPARTS,0,0,,ahk_id %hSB%
if (ErrorLevel="FAIL") ;-- Invalid hSB
Return 0
l_NumberOfParts:=ErrorLevel
;-- Collect part coordinates
VarSetCapacity(l_PartsArray,4*l_NumberOfParts,0)
SendMessage SB_GETPARTS,l_NumberOfParts,&l_PartsArray,,ahk_id %hSB%
;-- Load data from integer array to the output AutoHotkey array
Loop %l_NumberOfParts%
r_Parts.Push(NumGet(&l_PartsArray,(A_Index-1)*4,"Int"))
Return l_NumberOfParts
}
;------------------------------
;
; Function: SBAR_GetPartsCount
;
; Description:
;
; Returns the number of parts in the status bar.
;
; Remarks:
;
; The SB_GETPARTS message returns the number of parts for the nonsimple status
; bar even if the status bar is currently in simple mode.
;
; Programming Notes:
;
; This is one of the few functions that checks for the return code of "FAIL"
; which indicates that the hSB parameter is invalid. This allows the function
; to always return an integer value and allows the return value to be tested
; as TRUE for FALSE since all status bars have at least 1 part.
;
;-------------------------------------------------------------------------------
SBAR_GetPartsCount(hSB)
{
Static SB_GETPARTS:=0x406 ;-- WM_USER+6
SendMessage SB_GETPARTS,0,0,,ahk_id %hSB%
Return (ErrorLevel="FAIL" ? 0:ErrorLevel)
}
;------------------------------
;
; Function: SBAR_GetPos
;
; Description:
;
; Get the position and size of the status bar control. See the *Remarks*
; section for more information.
;
; Parameters:
;
; X, Y, W, H - [Output, Optional] If defined, these variables contain the
; coordinates of the status bar relative to the client-area of the parent
; window (X and Y), and the width and height of the status bar (W and H).
;
; Remarks:
;
; This function returns values similar to the AutoHotkey
; *GUIControlGet,OutputVar,Pos* command. The coordinates values (i.e. X and
; Y) are relative to the parent window's client area. However, this function
; is not DPI-aware and so the returned values are actual values, not
; calculated values based on the current screen DPI. This function will
; return the same values as the *GUIControlGet,OutputVar,Pos* command if the
; "-DPIScale" option was specified when the GUI was created or if the computer
; is currently using the default DPI setting, i.e. 96 DPI. This function
; works on all status bars whereas the <GUIControlGet at
; https://autohotkey.com/docs/commands/GuiControlGet.htm> command only works
; on status bars created using the AutoHotkey "gui Add" command.
;
; If the status bar was created using the AutoHotkey "gui Add" command and the
; "-DPIScale" option is specified, the *GUIControlGet* command can be used
; instead. The <ControlGetPos at
; https://autohotkey.com/docs/commands/ControlGetPos.htm> and <WinGetPos at
; https://autohotkey.com/docs/commands/WinGetPos.htm> commands are not
; DPI-aware and so if only interested in the width and/or height values, these
; commands can be used on all status bar controls. Hint: The native
; AutoHotkey commands are more efficient and should be used whenever possible.
;
;-------------------------------------------------------------------------------
SBAR_GetPos(hSB,ByRef X:="",ByRef Y:="",ByRef W:="",ByRef H:="")
{
;-- Initialize
VarSetCapacity(RECT,16,0)
;-- Get the dimensions of the bounding rectangle of the status bar
DllCall("GetWindowRect","Ptr",hSB,"Ptr",&RECT)
W:=NumGet(RECT,8,"Int")-NumGet(RECT,0,"Int") ;-- W=right-left
H:=NumGet(RECT,12,"Int")-NumGet(RECT,4,"Int") ;-- H=bottom-top
;-- Convert the screen coordinates of the status bar to client-area
; coordinates. Note: The API reads and updates the first 8-bytes of the
; RECT structure.
DllCall("ScreenToClient"
,"Ptr",DllCall("GetParent","Ptr",hSB,"Ptr")
,"Ptr",&RECT)
X:=NumGet(RECT,0,"Int") ;-- left
Y:=NumGet(RECT,4,"Int") ;-- top
}
;------------------------------
;
; Function: SBAR_GetHeight
;
; Description:
;
; Get the height of a status bar.
;
;-------------------------------------------------------------------------------
SBAR_GetHeight(hSB)
{
ControlGetPos,,,,l_SBH,,ahk_id %hSB%
Return l_SBH
}
;------------------------------
;
; Function: SBAR_GetSimpleIcon
;
; Description:
;
; Get the icon from the simple mode status bar.
;
; Returns:
;
; The handle to the icon (tests as TRUE) if successful, otherwise 0 (FALSE).
;
;-------------------------------------------------------------------------------
SBAR_GetSimpleIcon(hSB)
{
Static SB_GETICON:=0x414 ;-- WM_USER + 20
SendMessage SB_GETICON,-1,0,,ahk_id %hSB%
Return ErrorLevel
}
;------------------------------
;
; Function: SBAR_GetSimpleIconSize
;
; Description:
;
; Get the icon size of the simple mode status bar icon.
;
; Parameters:
;
; See <Common Parameters> for more information.
;
; r_Width, r_Height - [Output, Optional] If defined, these variables contain
; the width and height of the simple mode status bar icon. These
; variables will be set to zero if there is no icon or if there was an
; error.
;
; Returns:
;
; The address to a SIZE structure (tests as TRUE) if successful, otherwise
; FALSE.
;
; Calls To Other Functions:
;
; * <SBAR_GetIconSize>
;
;-------------------------------------------------------------------------------
SBAR_GetSimpleIconSize(hSB,ByRef r_Width:="",ByRef r_Height:="")
{
Return SBAR_GetIconSize(hSB,0,r_Width,r_Height)
}
;------------------------------
;
; Function: SBAR_GetSimpleText
;
; Description:
;
; Returns the text from a simple mode status bar.
;
; Remarks:
;
; This function only works correctly if the status bar is in simple mode. If
; used while in nonsimple mode, invalid information is returned. Use
; <SBAR_IsSimple> to check the status bar mode before calling this function.
;
; Programming Notes:
;
; While the status bar is in simple mode, SB_GETTEXTLENGTH or SB_GETTEXT
; messages only return information for the simple mode status bar. Oddly, the
; wParam parameter must contain a valid zero-index part number (it is set to
; 0) but it is otherwise ignored. This idiosyncrasy is not documented.
;
;-------------------------------------------------------------------------------
SBAR_GetSimpleText(hSB)
{
Static Dummy41938447
;-- Messages
,SB_GETTEXTA :=0x402 ;-- WM_USER + 2
,SB_GETTEXTW :=0x40D ;-- WM_USER + 13
,SB_GETTEXTLENGTHA:=0x403 ;-- WM_USER + 3
,SB_GETTEXTLENGTHW:=0x40C ;-- WM_USER + 12
;-- Get text length
SendMessage
,A_IsUnicode ? SB_GETTEXTLENGTHW:SB_GETTEXTLENGTHA
,0 ;-- wParam
,0 ;-- lParam
,,ahk_id %hSB%
if not l_TextLength:=ErrorLevel&0xFFFF
Return "" ;-- Null
;-- Get text
VarSetCapacity(l_Text,l_TextLength*(A_IsUnicode ? 2:1),0)
SendMessage
,A_IsUnicode ? SB_GETTEXTW:SB_GETTEXTA
,0 ;-- wParam