-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathToggleControl.au3
More file actions
482 lines (437 loc) · 31.4 KB
/
ToggleControl.au3
File metadata and controls
482 lines (437 loc) · 31.4 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
#include-once
#include <GDIPlus.au3>
; ============================================================================================================================================================================================================
; Title: Toggle Control UDF
; AutoIt Version : 3.3.16.1
; Description: Toggle control.
; Author: Andreik
; Dependencies: GDI+
; Call _GDIPlus_Startup() before using any other function from this UDF and _GDIPlus_Shutdown() after you properly deleted all controls created with this UDF
; and there is no further need of any function from this UDF.
; ============================================================================================================================================================================================================
; #CONSTANTS# ================================================================================================================================================================================================
Global Enum $TOGGLE_HORIZONTAL, $TOGGLE_VERTICAL
; ============================================================================================================================================================================================================
; #CURRENT# ==================================================================================================================================================================================================
; GUICtrlCreateToggle
; GUICtrlDeleteToggle
; ToggleState
; GUICtrlToggle_State
; GUICtrlToggle_CtrlID
; GUICtrlToggle_BackgroundColor
; GUICtrlToggle_SwitchColor
; GUICtrlToggle_RingColor
; GUICtrlToggle_SwitchSize
; GUICtrlToggle_RingSize
; GUICtrlToggle_Position
; GUICtrlToggle_CreateTheme
; GUICtrlToggle_SetTheme
; ============================================================================================================================================================================================================
; #FUNCTION# =================================================================================================================================================================================================
; Name: GUICtrlCreateToggle
; Description: Creates a toggle control.
; Syntax: GUICtrlCreateToggle($hGUI, $iX, $iY, $iW, $iH, [, $iStyle = Default [, $iBkColor = Default]])
; Parameters: $hGUI - The handle of the parent window.
; $iX - Position of the left side of the control.
; $iY - Position of the top side of the control.
; $iW - The width of the control.
; $iH - The height of the control.
; $iStyle - [Optional] - Defines the style of the control. Available styles: $TOGGLE_HORIZONTAL, $TOGGLE_VERTICAL. Default value is $TOGGLE_HORIZONTAL.
; $iBkColor - [Optional] - Background color of the parent window in AARRGGBB format. If this parameter is not provided then COLOR_3DFACE will be used as background color.
; Return value: Success - Returns a map with all information about the toggle control.
; Failure - Returns Null.
; @error = 1 - The width of the control must be greater than the height of the control when the control has $TOGGLE_HORIZONTAL style.
; @error = 2 - The height of the control must be greater than the width of the control when the control has $TOGGLE_VERTICAL style.
; Author: Andreik
; Remarks: This function returns a map with different properties of the control but it's highly recommended to avoid any direct modification of these properties. Instead you can
; use the specialized functions of this UDF to get/set some of these properties.
; ============================================================================================================================================================================================================
Func GUICtrlCreateToggle($hGUI, $iX, $iY, $iW, $iH, $iStyle = Default, $iBkColor = Default)
Local $mToggleCtrl[]
Local Const $COLOR_3DFACE = 15
; Set default values
If $iStyle = Default Then $iStyle = $TOGGLE_HORIZONTAL
If $iBkColor = Default Then
Local $aCall = DllCall('user32.dll', 'dword', 'GetSysColor', 'int', $COLOR_3DFACE)
If @error Then ; If the color cannot be retrieved using GetSysColor then use a default value
$mToggleCtrl['GUIBackground'] = 0xFFF0F0F0
Else
$mToggleCtrl['GUIBackground'] = BitOR($aCall[0], 0xFF000000)
EndIf
EndIf
$mToggleCtrl['GUI'] = $hGUI
$mToggleCtrl['Style'] = $iStyle
$mToggleCtrl['State'] = False
$mToggleCtrl['SwitchSize'] = 5
$mToggleCtrl['RingSize'] = 2
$mToggleCtrl['BackgroundColor'] = 0xFF212529
$mToggleCtrl['SwitchColor'] = 0xFFCED4DA
$mToggleCtrl['RingColor'] = 0xFF6C757D
$mToggleCtrl['Top'] = $iX
$mToggleCtrl['Left'] = $iY
$mToggleCtrl['Width'] = $iW
$mToggleCtrl['Height'] = $iH
; Check W/H ratio with respect to style
If $mToggleCtrl['Style'] = $TOGGLE_HORIZONTAL And $iW < $iH Then Return SetError(1, 0, Null)
If $mToggleCtrl['Style'] = $TOGGLE_VERTICAL And $iH < $iW Then Return SetError(2, 0, Null)
; Create the control
$mToggleCtrl['ID'] = GUICtrlCreatePic('', $iX, $iY, $iW, $iH)
$mToggleCtrl['Bitmap'] = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
__DrawToggle($mToggleCtrl)
GUICtrlSetCursor($mToggleCtrl['ID'], 0)
; Return the control as a map
Return $mToggleCtrl
EndFunc
; #FUNCTION# =================================================================================================================================================================================================
; Name: GUICtrlDeleteToggle
; Description: Deletes a toggle control.
; Syntax: GUICtrlDeleteToggle($mToggleCtrl)
; Parameters: $mToggleCtrl - A map that represent the toggle control returned by GUICtrlCreateToggle().
; Return value: Success - True
; Failure - False
; @error = 1 - $mToggleCtrl is not a valid toggle control.
; Author: Andreik
; Remarks: Even if the visible control can be technically deleted with GUICtrlDelete($mToggleCtrl['ID']) this should be avoided as there is
; a bitmap associated with the control that will produce a memory leak.
; ============================================================================================================================================================================================================
Func GUICtrlDeleteToggle(ByRef $mToggleCtrl)
; Check if the control is actually a map
If Not IsMap($mToggleCtrl) Then Return SetError(1, 0, False)
; Dispose the bitmap associated with the control and delete the control
_GDIPlus_BitmapDispose($mToggleCtrl['Bitmap'])
GUICtrlDelete($mToggleCtrl['ID'])
$mToggleCtrl = Null
Return True
EndFunc
; #FUNCTION# =================================================================================================================================================================================================
; Name: ToggleState
; Description: Toggles the current state of the toggle control.
; Syntax: ToggleState($mToggleCtrl)
; Parameters: $mToggleCtrl - A map that represent the toggle control returned by GUICtrlCreateToggle().
; Return value: Success - True
; Failure - False
; @error = 1 - $mToggleCtrl is not a valid toggle control.
; Author: Andreik
; Remarks: This function should be called each time when the toggle control is clicked. In order to set a specific status of the toggle control use GUICtrlToggle_State().
; ============================================================================================================================================================================================================
Func ToggleState(ByRef $mToggleCtrl)
; Check if the control is actually a map
If Not IsMap($mToggleCtrl) Then Return SetError(1, 0, False)
; Change toggle state and redraw control
$mToggleCtrl['State'] = Not $mToggleCtrl['State']
__DrawToggle($mToggleCtrl, True)
Return True
EndFunc
; #FUNCTION# =================================================================================================================================================================================================
; Name: GUICtrlToggle_State
; Description: Get or set the current state of the toggle control.
; Syntax: GUICtrlToggle_State($mToggleCtrl [, $iState = Null])
; Parameters: $mToggleCtrl - A map that represent the toggle control returned by GUICtrlCreateToggle().
; $iState - [Optional] - A new state of the toggle control. Available states: True (or 1) and False (or 0).
; Return value: Success - True - if the function is used to set the state of the toggle control.
; - A boolean value that represent the current state of the toggle control - if the function is used to get the state of the toggle control.
; Failure - False
; @error = 1 - $mToggleCtrl is not a valid toggle control.
; @error = 2 - $iState is not a valid state.
; Author: Andreik
; Remarks: This function can be used to get the current state of the control but also to set a new state if the $iState parameter is provided.
; ============================================================================================================================================================================================================
Func GUICtrlToggle_State(ByRef $mToggleCtrl, $iState = Null)
; Check if the control is actually a map
If Not IsMap($mToggleCtrl) Then Return SetError(1, 0, False)
; Check if get or set is requested
If @NumParams = 1 Then Return $mToggleCtrl['State']
; Check the provided state
If $iState <> 0 And $iState <> 1 Then Return SetError(2, 0, False)
; Set toggle state and redraw the control
$mToggleCtrl['State'] = $iState
__DrawToggle($mToggleCtrl, True)
Return True
EndFunc
; #FUNCTION# =================================================================================================================================================================================================
; Name: GUICtrlToggle_CtrlID
; Description: Returns the control ID of the picture control where the toggle control is drawn. This control ID can be used with native AutoIt functions.
; Syntax: GUICtrlToggle_CtrlID($mToggleCtrl)
; Parameters: $mToggleCtrl - A map that represent the toggle control returned by GUICtrlCreateToggle().
; Return value: Success - Returns the control ID of the picture control where the toggle control is drawn.
; Failure - False
; @error = 1 - $mToggleCtrl is not a valid toggle control.
; Author: Andreik
; Remarks: Technically this function is equivalent with $mToggleCtrl['ID'] but there is a validation to ensure that
; GUICtrlCreateToggle() returned a valid map that represent the toggle control.
; ============================================================================================================================================================================================================
Func GUICtrlToggle_CtrlID($mToggleCtrl)
; Check if the control is actually a map
If Not IsMap($mToggleCtrl) Then Return SetError(1, 0, False)
Return $mToggleCtrl['ID']
EndFunc
; #FUNCTION# =================================================================================================================================================================================================
; Name: GUICtrlToggle_BackgroundColor
; Description: Get or set the background color of the toggle control.
; Syntax: GUICtrlToggle_BackgroundColor($mToggleCtrl [, $iBackgroundColor = Null])
; Parameters: $mToggleCtrl - A map that represent the toggle control returned by GUICtrlCreateToggle().
; $iBackgroundColor - [Optional] - Background color of the toggle control in AARRGGBB format.
; Return value: Success - True - if the function is used to set the background color of the toggle control.
; - The background color of the toggle control in AARRGGBB format - if the function is used to get the background color.
; Failure - False
; @error = 1 - $mToggleCtrl is not a valid toggle control.
; Author: Andreik
; Remarks: This function can be used to get the background color of the control but also to set a new background color if the $iBackgroundColor parameter is provided.
; ============================================================================================================================================================================================================
Func GUICtrlToggle_BackgroundColor(ByRef $mToggleCtrl, $iBackgroundColor = Null)
; Check if the control is actually a map
If Not IsMap($mToggleCtrl) Then Return SetError(1, 0, False)
; Check if get or set is requested
If @NumParams = 1 Then Return '0x' & Hex($mToggleCtrl['BackgroundColor'], 8)
; Set background color and redraw the control
$mToggleCtrl['BackgroundColor'] = $iBackgroundColor
__DrawToggle($mToggleCtrl)
Return True
EndFunc
; #FUNCTION# =================================================================================================================================================================================================
; Name: GUICtrlToggle_SwitchColor
; Description: Get or set the color of the switch.
; Syntax: GUICtrlToggle_SwitchColor($mToggleCtrl [, $iSwitchColor = Null])
; Parameters: $mToggleCtrl - A map that represent the toggle control returned by GUICtrlCreateToggle().
; $iSwitchColor - [Optional] - The color of the switch in AARRGGBB format.
; Return value: Success - True - if the function is used to set a new color for the switch.
; - The color of the switch in AARRGGBB format - if the function is used to get the color of the switch.
; Failure - False
; @error = 1 - $mToggleCtrl is not a valid toggle control.
; Author: Andreik
; Remarks: This function can be used to get the color of the switch but also to set a new color for the switch if the $iSwitchColor parameter is provided.
; ============================================================================================================================================================================================================
Func GUICtrlToggle_SwitchColor(ByRef $mToggleCtrl, $iSwitchColor = Null)
; Check if the control is actually a map
If Not IsMap($mToggleCtrl) Then Return SetError(1, 0, False)
; Check if get or set is requested
If @NumParams = 1 Then Return '0x' & Hex($mToggleCtrl['SwitchColor'], 8)
; Set switch color and redraw the control
$mToggleCtrl['SwitchColor'] = $iSwitchColor
__DrawToggle($mToggleCtrl)
Return True
EndFunc
; #FUNCTION# =================================================================================================================================================================================================
; Name: GUICtrlToggle_RingColor
; Description: Get or set the color of the ring that is around the switch.
; Syntax: GUICtrlToggle_RingColor($mToggleCtrl [, $iRingColor = Null])
; Parameters: $mToggleCtrl - A map that represent the toggle control returned by GUICtrlCreateToggle().
; $iRingColor - [Optional] - The color of the ring in AARRGGBB format.
; Return value: Success - True - if the function is used to set a new color for the ring.
; - The color of the ring in AARRGGBB format - if the function is used to get the color of the ring.
; Failure - False
; @error = 1 - $mToggleCtrl is not a valid toggle control.
; Author: Andreik
; Remarks: This function can be used to get the color of the ring but also to set a new color for the ring if the $iRingColor parameter is provided.
; ============================================================================================================================================================================================================
Func GUICtrlToggle_RingColor(ByRef $mToggleCtrl, $iRingColor = Null)
; Check if the control is actually a map
If Not IsMap($mToggleCtrl) Then Return SetError(1, 0, False)
; Check if get or set is requested
If @NumParams = 1 Then Return '0x' & Hex($mToggleCtrl['RingColor'], 8)
; Set ring color and redraw the control
$mToggleCtrl['RingColor'] = $iRingColor
__DrawToggle($mToggleCtrl)
Return True
EndFunc
; #FUNCTION# =================================================================================================================================================================================================
; Name: GUICtrlToggle_SwitchSize
; Description: Get or set the size of the switch.
; Syntax: GUICtrlToggle_SwitchSize($mToggleCtrl [, $iSwitchSize = Null])
; Parameters: $mToggleCtrl - A map that represent the toggle control returned by GUICtrlCreateToggle().
; $iSwitchSize - [Optional] - The size of the switch. The size can be any value between 2 and 10.
; Return value: Success - True - if the function is used to set the size of the switch.
; - An integer between 2 and 10 - if the function is used to get the size of the switch.
; Failure - False
; @error = 1 - $mToggleCtrl is not a valid toggle control.
; Author: Andreik
; Remarks: This function can be used to get the size of the switch but also to set a new size for the switch if the $iSwitchSize parameter is provided.
; ============================================================================================================================================================================================================
Func GUICtrlToggle_SwitchSize(ByRef $mToggleCtrl, $iSwitchSize = Null)
; Check if the control is actually a map
If Not IsMap($mToggleCtrl) Then Return SetError(1, 0, False)
; Check if get or set is requested
If @NumParams = 1 Then Return $mToggleCtrl['SwitchSize']
; Check the min/max switch size
If $iSwitchSize < 2 Then $iSwitchSize = 2
If $iSwitchSize > 10 Then $iSwitchSize = 10
; Set switch size and redraw the control
$mToggleCtrl['SwitchSize'] = $iSwitchSize
__DrawToggle($mToggleCtrl)
Return True
EndFunc
; #FUNCTION# =================================================================================================================================================================================================
; Name: GUICtrlToggle_RingSize
; Description: Get or set the size of the ring.
; Syntax: GUICtrlToggle_RingSize($mToggleCtrl [, $iRingSize = Null])
; Parameters: $mToggleCtrl - A map that represent the toggle control returned by GUICtrlCreateToggle().
; $iRingSize - [Optional] - The size of the ring The size can be any value between 0 and 10.
; Return value: Success - True - if the function is used to set the size of the ring.
; - An integer between 0 and 10 - if the function is used to get the size of the ring.
; Failure - False
; @error = 1 - $mToggleCtrl is not a valid toggle control.
; Author: Andreik
; Remarks: This function can be used to get the size of the ring but also to set a new size for the ring if the $iRingSize parameter is provided.
; ============================================================================================================================================================================================================
Func GUICtrlToggle_RingSize(ByRef $mToggleCtrl, $iRingSize = Null)
; Check if the control is actually a map
If Not IsMap($mToggleCtrl) Then Return SetError(1, 0, False)
; Check if get or set is requested
If @NumParams = 1 Then Return $mToggleCtrl['RingSize']
; Check the min/max ring size
If $iRingSize < 0 Then $iRingSize = 0
If $iRingSize > 10 Then $iRingSize = 10
; Set ring size and redraw the control
$mToggleCtrl['RingSize'] = $iRingSize
__DrawToggle($mToggleCtrl)
Return True
EndFunc
; #FUNCTION# =================================================================================================================================================================================================
; Name: GUICtrlToggle_Position
; Description: Get or set the position and size of the toggle control.
; Syntax: GUICtrlToggle_Position($mToggleCtrl [, $iX = Null [,$iY = Null [,$iW = Null [,$iH = Null]]]])
; Parameters: $mToggleCtrl - A map that represent the toggle control returned by GUICtrlCreateToggle().
; $iX - [Optional] - Position of the left side of the control.
; $iY - [Optional] - Position of the top side of the control.
; $iW - [Optional] - The width of the control.
; $iH - [Optional] - The height of the control.
; Return value: Success - True - if the function is used to set a new position and size.
; - Returns a four-element array containing the Top, Left, Width and Height of the control - if the function is used to get the position and size of the control.
; Failure - False
; @error = 1 - $mToggleCtrl is not a valid toggle control.
; @error = 2 - Some parameters are missing. If the function is used to set a new position and size then all parameters are required.
; @error = 3 - The size provided is not compatible with the control style. If the control has the style $TOGGLE_HORIZONTAL then width cannot be less than height.
; @error = 4 - The size provided is not compatible with the control style. If the control has the style $TOGGLE_VERTICAL then height cannot be less than width.
; Author: Andreik
; Remarks: This function can be used to get the position and size of the toggle control
; but also to set a new position and size for the toggle control if the $iX, $iY, $iW and $iH parameters are provided.
; ============================================================================================================================================================================================================
Func GUICtrlToggle_Position(ByRef $mToggleCtrl, $iX = Null, $iY = Null, $iW = Null, $iH = Null)
; Check if the control is actually a map
If Not IsMap($mToggleCtrl) Then Return SetError(1, 0, False)
; Check if get or set is requested
If @NumParams = 1 Then
Local $aPos[4] = [$mToggleCtrl['Top'], $mToggleCtrl['Left'], $mToggleCtrl['Width'], $mToggleCtrl['Height']]
Return $aPos
EndIf
If @NumParams <> 5 Then Return SetError(2, 0, False)
; Check W/H ratio with respect to style
If $mToggleCtrl['Style'] = $TOGGLE_HORIZONTAL And $iW < $iH Then Return SetError(3, 0, False)
If $mToggleCtrl['Style'] = $TOGGLE_VERTICAL And $iH < $iW Then Return SetError(4, 0, False)
; Set position and redraw the control
$mToggleCtrl['Top'] = $iX
$mToggleCtrl['Left'] = $iY
$mToggleCtrl['Width'] = $iW
$mToggleCtrl['Height'] = $iH
__DrawToggle($mToggleCtrl)
Return True
EndFunc
; #FUNCTION# =================================================================================================================================================================================================
; Name: GUICtrlToggle_CreateTheme
; Description: Create a compatible theme for toggle controls.
; Syntax: GUICtrlToggle_CreateTheme($iBackgroundColor, $iSwitchColor, $iRingColor, $iSwitchSize, $iRingSize)
; Parameters: $iBackgroundColor - Background color of the toggle switch in AARRGGBB format.
; $iSwitchColor - The color of the switch in AARRGGBB format.
; $iRingColor - The color of the ring in AARRGGBB format.
; $iSwitchSize - The size of the switch. The size can be any value between 2 and 10.
; $iRingSize - The size of the ring The size can be any value between 0 and 10.
; Return value: Success - Returns a map that defines the theme.
; Author: Andreik
; ============================================================================================================================================================================================================
Func GUICtrlToggle_CreateTheme($iBackgroundColor, $iSwitchColor, $iRingColor, $iSwitchSize, $iRingSize)
If $iSwitchSize < 2 Then $iSwitchSize = 2
If $iSwitchSize > 10 Then $iSwitchSize = 10
If $iRingSize < 0 Then $iRingSize = 0
If $iRingSize > 10 Then $iRingSize = 10
Local $mTheme[]
$mTheme['BackgroundColor'] = $iBackgroundColor
$mTheme['SwitchColor'] = $iSwitchColor
$mTheme['RingColor'] = $iRingColor
$mTheme['SwitchSize'] = $iSwitchSize
$mTheme['RingSize'] = $iRingSize
Return $mTheme
EndFunc
; #FUNCTION# =================================================================================================================================================================================================
; Name: GUICtrlToggle_SetTheme
; Description: Set a theme to a toggle control.
; Syntax: GUICtrlToggle_SetTheme($mToggleCtrl, $mTheme)
; Parameters: $mToggleCtrl - A map that represent the toggle control returned by GUICtrlCreateToggle().
; $mTheme - A map that represent the theme returned by GUICtrlToggle_CreateTheme().
; Return value: Success - True
; Failure - False
; @error = 1 - $mToggleCtrl is not a valid toggle control.
; @error = 2 - $mTheme is not a valid theme.
; Author: Andreik
; ============================================================================================================================================================================================================
Func GUICtrlToggle_SetTheme(ByRef $mToggleCtrl, $mTheme)
; Check if the control is actually a map
If Not IsMap($mToggleCtrl) Then Return SetError(1, 0, False)
; Check if the theme is actually a map
If Not IsMap($mTheme) Then Return SetError(2, 0, False)
; Set the theme
GUICtrlToggle_BackgroundColor($mToggleCtrl, $mTheme['BackgroundColor'])
GUICtrlToggle_SwitchColor($mToggleCtrl, $mTheme['SwitchColor'])
GUICtrlToggle_RingColor($mToggleCtrl, $mTheme['RingColor'])
GUICtrlToggle_SwitchSize($mToggleCtrl, $mTheme['SwitchSize'])
GUICtrlToggle_RingSize($mToggleCtrl, $mTheme['RingSize'])
Return True
EndFunc
; #INTERNAL_USE_ONLY# ========================================================================================================================================================================================
; This function is for internal use only and it's used to draw the control. Don't call this function unless you understand how it works!!!
; ============================================================================================================================================================================================================
Func __DrawToggle(ByRef $mToggleCtrl, $bAnimate = False)
Local $hHBITMAP, $iStart, $iStop, $iStep, $hDC, $iOffsetX, $iOffsetY, $iStepAmp = 1
Local Const $STM_SETIMAGE = 0x0172, $IMAGE_BITMAP = 0, $GDIP_SmoothingMode_HighQuality = 2, $ANIMATION_UNIT = 150
Local $iSwitchSizePercent = ($mToggleCtrl['Style'] = $TOGGLE_HORIZONTAL ? $mToggleCtrl['Height'] / $mToggleCtrl['SwitchSize'] : $mToggleCtrl['Width'] / $mToggleCtrl['SwitchSize'])
Local $iDiameter = ($mToggleCtrl['Width'] < $mToggleCtrl['Height'] ? $mToggleCtrl['Width'] : $mToggleCtrl['Height'])
Local $iBitmapWidth = _GDIPlus_ImageGetWidth($mToggleCtrl['Bitmap'])
Local $iBitmapHeigt= _GDIPlus_ImageGetHeight($mToggleCtrl['Bitmap'])
If $iBitmapWidth <> $mToggleCtrl['Width'] Or $iBitmapHeigt <> $mToggleCtrl['Height'] Then
GUICtrlSetPos($mToggleCtrl['ID'], $mToggleCtrl['Top'], $mToggleCtrl['Left'], $mToggleCtrl['Width'], $mToggleCtrl['Height'])
_GDIPlus_BitmapDispose($mToggleCtrl['Bitmap'])
$mToggleCtrl['Bitmap'] = _GDIPlus_BitmapCreateFromScan0($mToggleCtrl['Width'], $mToggleCtrl['Height'])
EndIf
Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($mToggleCtrl['Bitmap'])
Local $hBrush = _GDIPlus_BrushCreateSolid($mToggleCtrl['BackgroundColor'])
Local $hPen = _GDIPlus_PenCreate($mToggleCtrl['RingColor'], $mToggleCtrl['RingSize'])
Local $hPath = _GDIPlus_PathCreate()
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SmoothingMode_HighQuality)
_GDIPlus_GraphicsSetCompositingQuality($hGraphics, $GDIP_COMPOSITINGQUALITY_HIGHQUALITY)
_GDIPlus_GraphicsSetPixelOffsetMode($hGraphics, 2)
_GDIPlus_PathReset($hPath)
_GDIPlus_PathAddArc($hPath, 0, 0, $iDiameter, $iDiameter, 180, 90)
_GDIPlus_PathAddArc($hPath, $mToggleCtrl['Width'] - $iDiameter - 1, 0, $iDiameter, $iDiameter, 270, 90)
_GDIPlus_PathAddArc($hPath, $mToggleCtrl['Width'] - $iDiameter - 1, $mToggleCtrl['Height'] - $iDiameter - 1, $iDiameter, $iDiameter, 0, 90)
_GDIPlus_PathAddArc($hPath, 0, $mToggleCtrl['Height'] - $iDiameter - 1, $iDiameter, $iDiameter, 90, 90)
_GDIPlus_PathCloseFigure($hPath)
Local $iDelta = Abs($mToggleCtrl['Width'] - $mToggleCtrl['Height'])
If $bAnimate Then
$iStart = $mToggleCtrl['State'] ? 0 : $iDelta
$iStop = $mToggleCtrl['State'] ? $iDelta : 0
$iStepAmp = Int(($mToggleCtrl['Style'] = $TOGGLE_HORIZONTAL ? $mToggleCtrl['Width'] : $mToggleCtrl['Height']) / $ANIMATION_UNIT)
$iStepAmp = ($iStepAmp < 1 ? 1 : $iStepAmp)
$iStep = $mToggleCtrl['State'] ? ( $iStepAmp) : (-$iStepAmp)
Else
$iStart = $mToggleCtrl['State'] ? $iDelta : 0
$iStop = $iStart
$iStep = 1
EndIf
Local $iSwitchRadius = ($mToggleCtrl['Style'] = $TOGGLE_HORIZONTAL ? $mToggleCtrl['Height'] : $mToggleCtrl['Width']) - $iSwitchSizePercent * 2
For $iOffset = $iStart To $iStop Step $iStep
$iOffsetX = ($mToggleCtrl['Style'] = $TOGGLE_HORIZONTAL ? $iOffset : 0)
$iOffsetY = ($mToggleCtrl['Style'] = $TOGGLE_VERTICAL ? $iOffset : 0)
_GDIPlus_GraphicsClear($hGraphics, $mToggleCtrl['GUIBackground'])
_GDIPlus_BrushSetSolidColor($hBrush, $mToggleCtrl['BackgroundColor'])
_GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush)
_GDIPlus_BrushSetSolidColor($hBrush, $mToggleCtrl['SwitchColor'])
_GDIPlus_GraphicsFillEllipse($hGraphics, $iOffsetX + $iSwitchSizePercent, $iOffsetY + $iSwitchSizePercent, $iSwitchRadius, $iSwitchRadius, $hBrush)
_GDIPlus_GraphicsDrawEllipse($hGraphics, $iOffsetX + $iSwitchSizePercent, $iOffsetY + $iSwitchSizePercent, $iSwitchRadius, $iSwitchRadius, $hPen)
$hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($mToggleCtrl['Bitmap'])
_WinAPI_DeleteObject(GUICtrlSendMsg($mToggleCtrl['ID'], $STM_SETIMAGE, $IMAGE_BITMAP, $hHBITMAP))
_WinAPI_DeleteObject($hHBITMAP)
Next
_GDIPlus_PathDispose($hPath)
_GDIPlus_PenDispose($hPen)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphics)
EndFunc