-
Notifications
You must be signed in to change notification settings - Fork 71
/
Dlg2_v03.ahk
2826 lines (2520 loc) · 106 KB
/
Dlg2_v03.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
/*
v0.3 (or 0.2.1+) updates
* Fix: Dlg_ChooseFont updated to correctly return font weights other than
normal (400) or bold (700).
* Fix/work-around: Dlg_OnHelpMsg function was not sending the handle to the
dialog to the help handler when the Help button was pressed on the Open and
Save dialog. Problem occurs on Vista+. Fixed by sending the handle to the
active window if the handle to the dialog is not provided by the
FINDMSGSTRING message.
* Update: Dlg_GetScriptDebugWindow returns the value of A_ScriptHwnd if using
AutoHotkey v1.1.1+. *i*Note: The return value is the same. The function is
just a bit more efficient when running on AutoHotkey v1.1.1+.*i*
* Updated structures documentation.
*/
/*
Title: Dlg2 v0.2.1 (Preview)
Group: Overview
This is a library of functions to create and interact with many of the
Microsoft Windows common dialogs. Use of the common dialogs gives the user a
consistent experience across different programs.
*Components*
============
In addition to standard functions, this library may contain Internal and Helper
functions.
As the name implies, _internal_ functions are used internally by this library.
They are either called by other library functions or are triggered by system
messages or registered callbacks. Internal functions are subject to change and
should not be called directly.
_Helper_ functions are non-standard functions that are included to assist the
developer resolve unusual problems related to this library. These functions
may or may not provide value to the developer.
All functions that are not labeled as "Internal" or "Helper" are _standard_
functions and can be called directly.
*History and Credit*
====================
This library is a offshoot of the Dlg library which was released by *majkinetor*
in 2007 and was included as part of the Forms Framework in 2010. It has been
been rewritten to include new features, new dialogs, and to support x64. All of
the function names have been changed so that there is no confusion with the
original Dlg library. The library retains much of the core design of the
original library and would not exist without the research and hard work of
*majkinetor*.
*Requirements*
==============
The minimum supported operating system for this library is Windows 2000.
Exceptions, if any, are noted in the documentation written for each function.
This library can be used on all versions of AutoHotkey including AutoHotkey
Basic and AutoHotkey v1.1+ (ANSI and Unicode) (32 and 64 bit).
*Future Support*
================
Support for Print and Page Setup dialogs are not included in this version of the
library due to the lack of demand and the complex nature of these dialogs. They
_may_ be included in a future release.
*Future Requirements*
=====================
The Dlg2 library (all versions) will mark the end of support for Windows 2000/XP
and AutoHotkey Basic. Future iterations of the library (possibly identified as
Dlg3) will require Windows Vista+ and AutoHotkey v1.1+.
Group: Functions
*/
Dlg_ChooseColor(hOwner,ByRef r_Color,p_Flags=0,p_CustomColorsFile="",p_HelpHandler="") {
/*
;------------------------------
;
; Function: Dlg_ChooseColor
;
; Description:
;
; Creates a Color dialog box that enables the user to select a color.
; (see _Color.jpg)
;
; Parameters:
;
; hOwner - A handle to the window that owns the dialog box. This parameter
; can be any valid window handle or it can be set to 0 or null if the
; dialog box has no owner. Note: A valid window handle must be specified
; if the CC_SHOWHELP flag is included (explicitly or implicitly).
;
; r_Color - Color in RGB format. [Input/Output] On input, this variable should
; contain the default color, i.e. the color that is initially selected
; when the Color dialog is displayed. On output, this variable contains
; the color selected in a 6-digit hexadecimal RGB format. Ex: 0x00FF80.
; If the function returns FALSE, i.e. the Color dialog was cancelled, the
; value of this variable is not changed.
;
; p_Flags - Flags used to initialize the Color dialog. See the *Flags*
; section for the details.
;
; p_CustomColorsFile - Path to a file that contains the custom colors that
; will be used by the application. [Optional] See the *Remarks* section
; for more information.
;
; p_HelpHandler - Name of a developer-created function that is called when the
; the user presses the Help button on the dialog. [Optional] See the *Help
; Handler* section for the details. Note: The CC_SHOWHELP flag is
; automatically added if this parameter contains a valid function name.
;
; Flags:
;
; The p_Flags parameter contains flags that are used to initialize and/or
; determine the behavior of the dialog. If set to zero (the default) or null,
; the CC_FULLOPEN and CC_ANYCOLOR flags are used. If p_Flags contains an
; interger value, the parameter is assumed to contain bit flags. See the
; function's static variables for a list a valid bit flags. Otherwise, the
; following space-delimited text flags can be used.
;
; AnyColor - Causes the dialog box to display all available colors in the set
; of basic colors.
;
; FullOpen - Causes the dialog box to display the additional controls that
; allow the user to create custom colors. If this flag is not set, the
; user must click the Define Custom Colors button to display the custom
; color controls.
;
; PreventFullOpen - Disables the Define Custom Colors button.
;
; ShowHelp - Causes the dialog box to display the Help button.
;
; Returns:
;
; TRUE if a color was selected, otherwise FALSE which indicates that the
; dialog was canceled.
;
; Calls To Other Functions:
;
; * <Dlg_Convert2Hex>
;
; Credit:
;
; Some of the custom colors ideas and 64-bit mapping offsets were extracted
; from a function published by *rbrtryn*. Some custom color and file
; formatting ideas were extracted from a function published by *maestrith*.
; Thanks to these authors for publishing their work.
;
; Remarks:
;
; * On input, the color stored in the r_Color variable is expected to be in
; in RGB format. On output, the color selected by the user is stored in the
; r_Color variable in RGB format. To convert the color from BRG for input
; or to BRG after the function returns, the following statement can used.
;
; (start code)
; ;-- Convert from BRG to RGB or vise versa
; Color:=((Color&0xFF)<<16)+(Color&0xFF00)+((Color>>16)&0xFF)
; (end)
;
; * Although the output value of r_Color is a hexadecimal number, it has been
; formatted to always have 6 digits -- leading zero ("0") characters are
; prepended to the value when needed. Ex: 0x0000FF. To use this value with
; AutoHotkey commands that use a 6-digit RGB value, simply truncate the first
; 2 characters (i.e."0x") of variable. For example:
;
; (start code)
; if Dlg_ChooseColor(hWindow,Color)
; gui Font,% "c" . SubStr(Color,3)
; (end)
;
; * If a file name is specified in the p_CustomColorsFile parameter, custom
; colors are written to a standard windows configuration file, i.e. INI file,
; in the "CustomColors" section. Each custom color is stored is a sequential
; numerical key staring with "1". The first custom color is stored in key
; "1", the second in key "2", and so on until key "16". Each custom color is
; stored as an integer in the BGR format. For example:
;
; (start code)
; [CustomColors]
; 1=16764134
; 2=32768
; ...
; 16=250
; (end)
;
; * If the custom colors configuration file does not exist, it will be created
; when the custom colors are saved. If writing to an existing file, a
; "CustomColors" section will be created if needed.
;
; * If a custom color file is not specified (p_CustomColorsFile parameter), the
; function will still save additions and changes to the "Custom Colors"
; section of the Color dialog in static memory so that they will be available
; if the dialog is used multiple times. However, all custom colors are lost
; when the script ends.
;
; Help Handler:
;
; The "Help Handler" is an optional developer-created function that is called
; when the user presses the Help button on the dialog.
;
; The handler function must have at least 2 parameters. Additional parameters
; are allowed but must be optional (defined with a default value). The
; required parameters are defined/used as follows, and in the following order:
;
; hDialog - The handle to the dialog window.
;
; lpInitStructure - A pointer to the initialization structure for the
; common dialog box. For this handler, the pointer is to a CHOOSECOLOR
; structure.
;
; It's up to the developer to determine what commands are performed in this
; function but displaying some sort of help message/document is what is
; expected.
;
; Note: The handler is triggered via a message sent by the dialog. The API
; will not return until the message has been processed. The handler should
; either 1) finish quickly or 2) any dialogs displayed via the handler should
; be modal. See the scripts included with this project for an example.
;
;-------------------------------------------------------------------------------
*/
Static Dummy1243
,HELPMSGSTRING:="commdlg_help"
;-- Registered message string for the Help button on common
; dialogs
;-- ##### Need all(??) structures here and all buffers whose
; addresses are included in the static structures
,CHOOSECOLOR
;-- Static CHOOSECOLOR structure. Also used by the help
; message.
;-- NTS: In theory, static is not required because this function
; does not end until the callback function (if any) has
; completed
;
; NTS, Part 2: Static still may be desired because the
; callback function can trigger an independent thread which
; will allow the callback function to complete. Static
; variables will allow the addresses to remain valid until the
; next time this function is called.
,s_CustomColors
;-- Custom color array. Also used by the help message via the
; CHOOSECOLOR structure.
;-- ChooseColor flags
,CC_ANYCOLOR:=0x100
;-- Causes the dialog box to display all available colors in the
; set of basic colors.
;;;;; ,CC_ENABLEHOOK:=0x10
;;;;; ,CC_ENABLETEMPLATE:=0x20
;;;;; ,CC_ENABLETEMPLATEHANDLE:=0x40
,CC_FULLOPEN:=0x2
;-- Causes the dialog box to display the additional controls
; that allow the user to create custom colors. If this flag
; is not set, the user must click the Define Custom Color
; button to display the custom color controls.
,CC_PREVENTFULLOPEN:=0x4
;-- Disables the Define Custom Colors button.
,CC_RGBINIT:=0x1
;-- Causes the dialog box to use the color specified in the
; rgbResult member as the initial color selection. This flag
; is included by default.
,CC_SHOWHELP:=0x8
;-- Causes the dialog box to display the Help button. Note: The
; Help button is not operational unless the p_HelpHandler
; parameter contains a valid function name.
,CC_SOLIDCOLOR:=0x80
;-- Causes the dialog box to display only solid colors in the
; set of basic colors. Observation: This flags doesn't
; appear to do anything.
;[==============]
;[ Initialize ]
;[==============]
;-- Workaround for AutoHotkey Basic and x64
PtrType:=(A_PtrSize=8) ? "Ptr":"UInt"
;-- If needed, initialize custom colors array
if not VarSetCapacity(s_CustomColors)
VarSetCapacity(s_CustomColors,64,0)
;-- All values are set to Black (0x0)
;[==============]
;[ Parameters ]
;[==============]
;-- Color
l_Color:=r_Color ;-- Working copy of r_Color
if l_Color is not Integer
l_Color:=0x0 ;-- Black
else
;-- Convert color to BGR
l_Color:=((l_Color&0xFF)<<16)+(l_Color&0xFF00)+((l_Color>>16)&0xFF)
;-- Flags
l_Flags:=CC_RGBINIT
if not p_Flags ;-- Zero, blank, or null
l_Flags|=CC_FULLOPEN|CC_ANYCOLOR
else
;-- Bit flags
if p_Flags is Integer
l_Flags|=p_Flags
else
;-- Convert text flags into bit flags
Loop Parse,p_Flags,%A_Tab%%A_Space%,%A_Tab%%A_Space%
if A_LoopField is not Space
if CC_%A_LoopField% is Integer
l_Flags|=CC_%A_LoopField%
if IsFunc(p_HelpHandler)
l_Flags|=CC_SHOWHELP
;[==================]
;[ Pre-Processing ]
;[==================]
;-- If requested, load custom colors from the custom colors file
if StrLen(p_CustomColorsFile)
Loop 16
{
IniRead t_Color,%p_CustomColorsFile%,CustomColors,%A_Index%,0
NumPut(t_Color,s_CustomColors,(A_Index-1)*4,"UInt")
}
;-- Create and populate CHOOSECOLOR structure
lStructSize:=VarSetCapacity(CHOOSECOLOR,(A_PtrSize=8) ? 72:36,0)
NumPut(lStructSize,CHOOSECOLOR,0,"UInt") ;-- lStructSize
NumPut(hOwner,CHOOSECOLOR,(A_PtrSize=8) ? 8:4,PtrType)
;-- hwndOwner
NumPut(l_Color,CHOOSECOLOR,(A_PtrSize=8) ? 24:12,"UInt")
;-- rgbResult
NumPut(&s_CustomColors,CHOOSECOLOR,(A_PtrSize=8) ? 32:16,PtrType)
;-- lpCustColors
NumPut(l_Flags,CHOOSECOLOR,(A_PtrSize=8) ? 40:20,"UInt")
;-- Flags
;-- If requested and a handler has been specified, turn on help monitoring
if (l_FLags & CC_SHOWHELP) and IsFunc(p_HelpHandler)
{
;-- Register the Handler with the OnHelp function
Dlg_OnHelpMsg("Register",p_HelpHandler,"","")
;-- Monitor the help message triggered by Help button
OnMessage(l_HelpMsg:=DllCall("RegisterWindowMessage",PtrType,&HELPMSGSTRING),"Dlg_OnHelpMsg")
}
;[===============]
;[ Show dialog ]
;[===============]
;-- Show the Color dialog. API returns TRUE if a color is selected,
; otherwise FALSE is returned. Note: The custom color array is updated
; even if the Color dialog is canceled.
RC:=DllCall("comdlg32\ChooseColor" . (A_IsUnicode ? "W":"A"),PtrType,&CHOOSECOLOR)
;[===================]
;[ Post-Processing ]
;[===================]
;-- If requested, save custom colors
if StrLen(p_CustomColorsFile)
Loop 16
IniWrite
,% NumGet(s_CustomColors,(A_Index-1)*4,"UInt")
,%p_CustomColorsFile%
,CustomColors
,%A_Index%
;-- If needed, turn off monitoring of help message
if l_HelpMsg
OnMessage(l_HelpMsg,"")
;-- Cancelled? (user pressed the "Cancel" button or closed the dialog)
if (RC=0)
Return False
;-- Collect the selected color
l_Color:=NumGet(CHOOSECOLOR,(A_PtrSize=8) ? 24:12,"UInt")
;-- rgbResult
;-- Convert to RGB
l_Color:=((l_Color&0xFF)<<16)+(l_Color&0xFF00)+((l_Color>>16)&0xFF)
;-- Update r_Color with the selected color
r_Color:=Dlg_Convert2Hex(l_Color,6)
Return True
}
Dlg_ChooseFont(hOwner=0,ByRef r_Name="",ByRef r_Options="",p_Effects=True,p_Flags=0,p_HelpHandler="") {
/*
;------------------------------
;
; Function: Dlg_ChooseFont
;
; Description:
;
; Creates a Font dialog box that enables the user to choose attributes for a
; logical font.
; (see _Font.jpg)
;
; Parameters:
;
; hOwner - A handle to the window that owns the dialog box. This parameter
; can be any valid window handle or it can be set to 0 or null if the
; dialog box has no owner. Note: A valid window handle must be specified
; if the CF_SHOWHELP flag is included (explicitly or implicitly).
;
; r_Name - Typeface name. [Input/Output] On input, this variable can contain
; contain the default typeface name. On output, this variable will
; contain the selected typeface name.
;
; r_Options - Font options. [Input/Output] See the *Options* section for the
; details.
;
; p_Effects - If set to TRUE (the default), the dialog box will display the
; controls that allow the user to specify strikeout, underline, and
; text color options.
;
; p_Flags - [Advanced Feature] Additional ChooseFont bit flags. [Optional]
; The default is 0 (no additional flags). See the *Remarks* section for
; more information.
;
; p_HelpHandler - Name of a developer-created function that is called when the
; the user presses the Help button on the dialog. [Optional] See the *Help
; Handler* section for the details. Note: The CF_SHOWHELP flag is
; automatically added if this parameter contains a valid function name.
;
; Options:
;
; On input, the r_Options parameter contains the default font options. On
; output, r_Options will contain the selected font options. The following
; space-delimited options (in alphabetical order) are available:
;
; bold - On input, this option will pre-select the "bold" font style. On
; output, this option will be returned if a bold font was selected.
;
; c{color} - Text color. "{color}" is one of 16 supported color names (see
; See the function's static variables for a list of possible color names)
; or a 6-digit hex RGB color value. Example values: Blue or FF00FA. On
; input, this option will attempt to pre-select the text color. On
; output, this option is returned with the selected text color. Notes and
; exceptions: 1) The color Black (000000) is the default text color. On
; input, Black is pre-selected if this option is not defined. 2) Color
; names (Ex: "Blue") are only accepted on input. A 6-digit hex RGB color
; value is always set on output (Ex: 0000FF). 3) If p_Effects is FALSE,
; this option is ignored on input and is not returned.
; italic - On input, this option will pre-select the "italic" font style. On
; output, this option will be returned if an italic font was selected.
; Exception: If p_Effects is FALSE, this option is ignored on input and is
; not returned.
;
; s{size in points} - Font size (in points). For example: s12. On input,
; this option will load the font size and if on the font-size list, will
; pre-select the font size. On output, the font size that was
; entered/selected is returned.
;
; SizeMax{max point size} - [Input only] The maximum point size the user can
; enter/select. For example: SizeMax72. If this option is specified
; without also specifying the SizeMin option, the SizeMin value is
; automatically set to 1.
;
; SizeMin{min point size} - [Input only] The minimum point size the user can
; enter/select. For example: SizeMin10. If this option is specified
; without also specifying the SizeMax option, the SizeMax value is
; automatically set to 0xBFFF (49151).
;
; strike - On input, this option will check the "Strikeout" option. On
; output, this option will be returned if the "Strikeout" option was
; checked. Exception: If p_Effects is FALSE, this option is ignored on
; input and is not returned.
;
; underline - On input, this option will check the "Underline" option. On
; output, this option will be returned if the "Underline" option was
; checked. Exception: If p_Effects is FALSE, this option is ignored on
; input and is not returned.
;
; w{font weight} - Font weight (thickness or boldness), which is an integer
; between 1 and 1000. For example, 400 is Normal and 700 is Bold. On
; input, this option will preselect the font style that most closely
; matches the weight specified. If not specified, the default weight for
; the font is selected. On output, this option is only returned if the
; font weight is not Normal (400) and not Bold (700).
;
; To specify more than one option, include a space between each. For
; example: s12 cFF0000 bold. On output, the selected options are defined
; in the same format.
;
; Returns:
;
; TRUE if a font was selected, otherwise FALSE is returned if the dialog was
; canceled or if an error occurred.
;
; Calls To Other Functions:
;
; * <Dlg_Convert2Hex>
;
; Remarks:
;
; * Although the font weight can be any number between 1 and 1000, most fonts
; only support 400 (Normal/Regular) and 700 (Bold). A very small number of
; fonts support additional font weights. The ChooseFont dialog does not
; display the font weight as a number. Instead, the font weight is displayed
; as font styles like Regular, ExtraLight, Black, etc. See the <CreateFont
; at http://tinyurl.com/n2qe72w> documentation for a list of common font
; weight names and their associated font weight values.
;
; * The SizeMin and SizeMax options (r_Options parameter) not only affect the
; list of fonts sizes that are shown in the Font Size selection list box in
; the Font dialog box, they affect the font size that can be manually entered
; in the Font Size combo box. If a font size that is outside the boundaries
; set by the SizeMin and SizeMax options, an MsgBox dialog is shown and the'
; user is not allowed to continue until a valid font size is entered/selected.
; Warning: If the value of the SizeMin option is greater than the SizeMax
; option, the "ChooseFont" API function will generate a CFERR_MAXLESSTHANMIN
; error and will return without showing the Font dialog box.
;
; * Flexibility in the operation of the ChooseFont dialog box is available via a
; large number of ChooseFont flags. For this function, the flags are
; determined by constants, options in the r_Options parameter, and the value
; of the p_Effects parameter. Although the flags set by these conditions will
; handle the needs of the majority of developers, there are a few ChooseFont
; flags that could provide additional value. The p_Flags parameter is used to
; _add_ additional ChooseFont flags to control the operation of the Font
; dialog box. See the function's static variables for a list of possible flag
; values. Warning: This is an advanced feature. Including invalid or
; conflicting flags may produce unexpected results. Be sure to test
; throroughly.
;
; Help Handler:
;
; The "Help Handler" is an optional developer-created function that is called
; when the user presses the Help button on the dialog.
;
; The handler function must have at least 2 parameters. Additional parameters
; are allowed but must be optional (defined with a default value). The
; required parameters are defined/used as follows, and in the following order:
;
; hDialog - The handle to the dialog window.
;
; lpInitStructure - A pointer to the initialization structure for the
; common dialog box. For this handler, the pointer is to a CHOOSECOLOR
; structure.
;
; It's up to the developer to determine what commands are performed in this
; function but displaying some sort of help message/document is what is
; expected.
;
; Note: The handler is triggered via a message sent by the dialog. The API
; will not return until the message has been processed. The handler should
; either 1) finish quickly or 2) any dialogs displayed via the handler should
; be modal. See the scripts included with this project for an example.
;
;-------------------------------------------------------------------------------
*/
Static Dummy3155
,HELPMSGSTRING:="commdlg_help"
;-- Registered message string for the Help button on common
; dialogs
;-- ##### Need all(??) structures here and all buffers whose
; addresses are included in the static structures
;-- Static TBDTBDTBD structure. Also used by the help message.
,CHOOSEFONT
;-- Static CHOOSEFONT structure. Also used by the help message.
,LOGFONT
;-- Static LOGFONT structure. Also used by the help message via
; the CHOOSEFONT structure.
;-- ChooseFont flags
,CF_SCREENFONTS:=0x1
;-- List only the screen fonts supported by the system. This
; flag is automatically set.
,CF_SHOWHELP:=0x4
;-- Causes the dialog box to display the Help button.
,CF_INITTOLOGFONTSTRUCT:=0x40
;-- Use the structure pointed to by the lpLogFont member to
; initialize the dialog box controls. This flag is
; automatically set.
,CF_EFFECTS:=0x100
;-- Causes the dialog box to display the controls that allow
; the user to specify strikeout, underline, and text color
; options. This flag is automatically set if the p_Effects
; parameter is set to TRUE.
,CF_SCRIPTSONLY:=0x400
;-- Allow selection of fonts for all non-OEM and Symbol
; character sets, as well as the ANSI character set.
,CF_NOOEMFONTS:=0x800
;-- (Despite what the documentation states, this flag is used
; to) prevent the dialog box from displaying and selecting OEM
; fonts. Ex: Terminal
,CF_NOSIMULATIONS:=0x1000
;-- Prevent the dialog box from displaying or selecting font
; simulations.
,CF_LIMITSIZE:=0x2000
;-- Select only font sizes within the range specified by the
; nSizeMin and nSizeMax members. This flag is automatically
; added if the SizeMin and/or the SizeMax options (r_Options
; parameter) are used.
,CF_FIXEDPITCHONLY:=0x4000
;-- Show and allow selection of only fixed-pitch fonts.
,CF_FORCEFONTEXIST:=0x10000
;-- Display an error message if the user attempts to select a
; font or style that is not listed in the dialog box.
,CF_SCALABLEONLY:=0x20000
;-- Show and allow selection of only scalable fonts. Scalable
; fonts include vector fonts, scalable printer fonts, TrueType
; fonts, and fonts scaled by other technologies.
,CF_TTONLY:=0x40000
;-- Show and allow the selection of only TrueType fonts.
,CF_NOFACESEL:=0x80000
;-- Prevent the dialog box from displaying an initial selection
; for the font name combo box.
,CF_NOSTYLESEL:=0x100000
;-- Prevent the dialog box from displaying an initial selection
; for the Font Style combo box.
,CF_NOSIZESEL:=0x200000
;-- Prevent the dialog box from displaying an initial selection
; for the Font Size combo box.
,CF_NOSCRIPTSEL:=0x800000
;-- Disables the Script combo box.
,CF_NOVERTFONTS:=0x1000000
;-- Display only horizontally oriented fonts.
;-- Device constants
,LOGPIXELSY:=90
;-- Misc. font constants
,CFERR_MAXLESSTHANMIN:=0x2002
,FW_NORMAL :=400
,FW_BOLD :=700
,LF_FACESIZE :=32 ;-- In TCHARS
;-- 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
;[==============]
;[ Initialize ]
;[==============]
;-- Workarounds and shortcuts for AutoHotkey Basic, x64, and Unicode
PtrType :=(A_PtrSize=8) ? "Ptr":"UInt"
TCharSize:=A_IsUnicode ? 2:1
;-- Collect the number of pixels per logical inch along the screen height
hDC:=DllCall("CreateDC","Str","DISPLAY",PtrType,0,PtrType,0,PtrType,0)
l_LogPixelsY:=DllCall("GetDeviceCaps",PtrType,hDC,"Int",LOGPIXELSY)
DllCall("DeleteDC",PtrType,hDC)
;[==============]
;[ Parameters ]
;[==============]
r_Name=%r_Name% ;-- AutoTrim
;-- p_Flags
if p_Flags is not Integer
p_Flags:=0x0
p_Flags|=CF_SCREENFONTS|CF_INITTOLOGFONTSTRUCT
if p_Effects
p_Flags|=CF_EFFECTS
if IsFunc(p_HelpHandler)
p_Flags|=CF_SHOWHELP
;-----------
;-- Options
;-----------
;-- Initialize options
o_Color :=0x0 ;-- Black
o_Height :=13
o_Italic :=False
o_Size :="" ;-- Undefined
o_SizeMin :="" ;-- Undefined
o_SizeMax :="" ;-- Undefined
o_Strikeout:=False
o_Underline:=False
o_Weight :="" ;-- Undefined
;-- Extract options (if any) from r_Options
Loop Parse,r_Options,%A_Space%
{
if (InStr(A_LoopField,"bold")=1)
o_Weight:=FW_BOLD
else if (InStr(A_LoopField,"italic")=1)
o_Italic:=True
else if (InStr(A_LoopField,"sizemin")=1)
{
o_SizeMin:=SubStr(A_LoopField,8)
if o_SizeMin is not Integer
o_SizeMin:=1
}
else if (InStr(A_LoopField,"sizemax")=1)
{
o_SizeMax:=SubStr(A_LoopField,8)
if o_SizeMax is not Integer
o_SizeMax:=0xBFFF
}
else if (InStr(A_LoopField,"strike")=1)
o_Strikeout:=True
else if (InStr(A_LoopField,"underline")=1)
o_Underline:=True
else if (InStr(A_LoopField,"c")=1 and StrLen(A_Loopfield)>1)
{
o_Color:="0x" . SubStr(A_LoopField,2) ;-- Default assignment
if A_LoopField is Alpha ;-- Possible color name
{
t_ColorName:=SubStr(A_LoopField,2)
if Color_%t_ColorName% is not Space
o_Color:=Color_%t_ColorName%
}
}
else if (InStr(A_LoopField,"s")=1)
o_Size:=SubStr(A_LoopField,2)
else if (InStr(A_LoopField,"w")=1)
o_Weight:=SubStr(A_LoopField,2)
}
;-- If needed, reset Effects options to defaults
if not p_Flags & CF_EFFECTS
{
o_Color :=0x0 ;-- Black
o_Strikeout:=False
o_Underline:=False
}
;-- Convert or fix invalid or unspecified options
if o_Color is Space
o_Color:=0x0 ;-- Black
else
if o_Color is not xdigit
o_Color:=0x0 ;-- Black
else
;-- Convert to BRG
o_Color:=((o_Color&0xFF)<<16)+(o_Color&0xFF00)+((o_Color>>16)&0xFF)
if o_SizeMin is Integer
if o_SizeMax is Space
o_SizeMax:=0xBFFF
if o_SizeMax is Integer
if o_SizeMin is Space
o_SizeMin:=1
if o_Weight is not Integer
o_Weight:=FW_NORMAL
;-- If needed, convert point size to height, in logical units
if o_Size is Integer
o_Height:=Round(o_Size*l_LogPixelsY/72)*-1
;-- Update flags
if o_SizeMin or o_SizeMax
p_Flags|=CF_LIMITSIZE
;[==================]
;[ Pre-Processing ]
;[==================]
;-- Create, initialize, and populate LOGFONT structure
VarSetCapacity(LOGFONT,28+(TCharSize*LF_FACESIZE),0)
NumPut(o_Height, LOGFONT,0,"Int") ;-- lfHeight
NumPut(o_Weight, LOGFONT,16,"Int") ;-- lfWeight
NumPut(o_Italic, LOGFONT,20,"UChar") ;-- lfItalic
NumPut(o_Underline,LOGFONT,21,"UChar") ;-- lfUnderline
NumPut(o_Strikeout,LOGFONT,22,"UChar") ;-- lfStrikeOut
if StrLen(r_Name)
DllCall("lstrcpyn" . (A_IsUnicode ? "W":"A")
,PtrType,&LOGFONT+28 ;-- lpString1 [out]
,"Str",r_Name ;-- lpString2 [in]
,"Int",StrLen(r_Name)+1) ;-- iMaxLength [in]
;-- Create, initialize, and populate CHOOSEFONT structure
CFSize:=VarSetCapacity(CHOOSEFONT,(A_PtrSize=8) ? 104:60,0)
NumPut(CFSize,CHOOSEFONT,0,"UInt")
;-- lStructSize
NumPut(hOwner,CHOOSEFONT,(A_PtrSize=8) ? 8:4,PtrType)
;-- hwndOwner
NumPut(&LOGFONT,CHOOSEFONT,(A_PtrSize=8) ? 24:12,PtrType)
;-- lpLogFont
NumPut(p_Flags,CHOOSEFONT,(A_PtrSize=8) ? 36:20,"UInt")
;-- Flags
NumPut(o_Color,CHOOSEFONT,(A_PtrSize=8) ? 40:24,"UInt")
;-- rgbColors
if o_SizeMin
NumPut(o_SizeMin,CHOOSEFONT,(A_PtrSize=8) ? 92:52,"Int")
;-- nSizeMin
if o_SizeMax
NumPut(o_SizeMax,CHOOSEFONT,(A_PtrSize=8) ? 96:56,"Int")
;-- nSizeMax
;-- If requested and a handler has been specified, turn on help monitoring
if (p_Flags & CF_SHOWHELP) and IsFunc(p_HelpHandler)
{
;-- Register the Handler with the OnHelp function
Dlg_OnHelpMsg("Register",p_HelpHandler,"","")
;-- Monitor the message triggered by Help button
OnMessage(l_HelpMsg:=DllCall("RegisterWindowMessage",PtrType,&HELPMSGSTRING),"Dlg_OnHelpMsg")
}
;[===============]
;[ Show dialog ]
;[===============]
RC:=DllCall("comdlg32\ChooseFont" . (A_IsUnicode ? "W":"A"),PtrType,&CHOOSEFONT)
;[===================]
;[ Post-Processing ]
;[===================]
;-- If enabled, turn off help monitoring
if l_HelpMsg
OnMessage(l_HelpMsg,"") ;-- Turn off monitoring
;-- Any errors?
if (RC=0)
{
if CDERR:=DllCall("comdlg32\CommDlgExtendedError")
{
if (CDERR=CFERR_MAXLESSTHANMIN)
outputdebug,
(ltrim join`s
Function: %A_ThisFunc% Error -
The size specified in the SizeMax option is less than the
size specified in the SizeMin option.
)
else
outputdebug,
(ltrim join`s
Function: %A_ThisFunc% Error -
Unknown error returned from the "ChooseFont" API. Error
code: %CDERR%.
)
}
Return False
}
;------------------
;-- Rebuild output
;------------------
;-- Extract font typeface name to r_Name
VarSetCapacity(r_Name,TCharSize*LF_FACESIZE)
nSize:=DllCall("lstrlen" . (A_IsUnicode ? "W":"A"),PtrType,&LOGFONT+28)
;-- Length of string in characters. Size does NOT includes terminating
; null character.
DllCall("lstrcpyn" . (A_IsUnicode ? "W":"A")
,"Str",r_Name ;-- lpString1 [out]
,PtrType,&LOGFONT+28 ;-- lpString2 [in]
,"Int",nSize+1) ;-- iMaxLength [in]
VarSetCapacity(r_Name,-1)
;-- Populate r_Options
r_Options:=""
r_Options.="s"
. NumGet(CHOOSEFONT,(A_PtrSize=8) ? 32:16,"Int")//10
;-- iPointSize
. A_Space
if p_Flags & CF_EFFECTS
{
l_Color:=NumGet(CHOOSEFONT,(A_PtrSize=8) ? 40:24,"UInt")
;-- rgbColors
;-- Convert to RGB
l_Color:=((l_Color&0xFF)<<16)+(l_Color&0xFF00)+((l_Color>>16)&0xFF)
;-- Append to r_Options in 6-digit hex format
r_Options.="c" . SubStr(Dlg_Convert2Hex(l_Color,6),3) . A_Space
}
l_Weight:=NumGet(LOGFONT,16,"Int")
if (l_Weight<>FW_NORMAL)
if (l_Weight=FW_BOLD)
r_Options.="bold "
else
r_Options.="w" . l_Weight . A_Space
if NumGet(LOGFONT,20,"UChar")
r_Options.="italic "
if NumGet(LOGFONT,21,"UChar")
r_Options.="underline "
if NumGet(LOGFONT,22,"UChar")
r_Options.="strike "
;-- Remove extraneous trailing space
r_Options:=SubStr(r_Options,1,-1)
;-- Return to sender
Return True
}
Dlg_ChooseIcon(hOwner,ByRef r_IconPath,ByRef r_IconIndex) {
/*
;------------------------------
;
; Function: Dlg_ChooseIcon
;
; Description:
;
; Creates a dialog box that allows the user to choose an icon from the
; selection available embedded in a resource such as an executable or DLL
; file.
; (see _Icon.jpg)
;
; Parameters:
;
; hOwner - A handle to the window that owns the dialog box. This parameter
; can be any valid window handle or it can be set to 0 or null if the
; dialog box has no owner.
;
; r_IconPath - Path to the icon resource file. [Input/Output] On input, set
; this variable to desired icon resource file or set to null to use the
; default resource file (usually "SHELL32.dll"), On output, the full
; path of the selected icon resource file is stored in this variable. If
; the dialog is canceled, this variable is not updated.
;
; r_Index - 1-based index to the icon within the icon resource file.
; [Input/Output]. On input, this variable should contain the 1-based
; index to the icon within the icon resource specified in the r_IconPath
; parameter. If set to null or 0, the first icon will be selected.
; On output, the variable is set to 1-based index of the icon selected.
; If the dialog is canceled, this variable is not updated.
;
; Returns:
;
; TRUE if successful or FALSE if the user canceled the dialog or if an error
; occurred.
;
; Requirements:
;
; Officially, this function is only supported on Windows XP and Windows Vista.
; Unofficially, this function works on most versions of Windows from Windows
; XP on. Be sure to test thoroughly.
;
;-------------------------------------------------------------------------------
*/
Static Dummy9731
,CP_ACP :=0 ;-- The system default Windows ANSI code page.
,MAX_PATH:=260
;-- Workaround for AutoHotkey Basic
PtrType:=(A_PtrSize=8) ? "Ptr":"UInt"