-
Notifications
You must be signed in to change notification settings - Fork 41
/
events.au3
914 lines (812 loc) · 36.1 KB
/
events.au3
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
#Region license
; -----------------------------------------------------------------------------
; This file is part of Simple IP Config.
;
; Simple IP Config is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; Simple IP Config is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with Simple IP Config. If not, see <http://www.gnu.org/licenses/>.
; -----------------------------------------------------------------------------
#EndRegion license
;==============================================================================
; Filename: events.au3
; Description: - functions called in response to events (button clicks, etc...)
; - 'onFunctionName' naming convention
; - also includes WM_COMMAND and WM_NOTIFY
;==============================================================================
;------------------------------------------------------------------------------
; Title........: _onExit
; Description..: Clean up and exit the program
; Events.......: GUI_EVENT_CLOSE, tray item 'Exit', File menu 'Exit'
;------------------------------------------------------------------------------
Func _onExit()
$sMinToTray = $options.MinToTray
If $sMinToTray = 1 Or $sMinToTray = "true" Then
_SendToTray()
Else
_Exit()
EndIf
EndFunc ;==>_onExit
;------------------------------------------------------------------------------
; Title........: _onMenuExit
; Description..: Clean up and exit the program
; Events.......: GUI_EVENT_CLOSE, tray item 'Exit', File menu 'Exit'
;------------------------------------------------------------------------------
Func _onMenuExit()
_Exit()
EndFunc ;==>_onMenuExit
;------------------------------------------------------------------------------
; Title........: _Exit
; Description..: Clean up and exit the program
; Events.......: GUI_EVENT_CLOSE, tray item 'Exit', File menu 'Exit'
;------------------------------------------------------------------------------
Func _Exit()
_GDIPlus_Shutdown()
; save window position in ini file
If BitAND(WinGetState($hgui), $WIN_STATE_MAXIMIZED) Then
ConsoleWrite("maximized" & @CRLF)
$options.PositionW = -1
$options.PositionH = -1
IniWriteSection($sProfileName, "options", $options.getSection, 0)
ElseIf Not BitAND(WinGetState($hgui), $WIN_STATE_MINIMIZED) Then
ConsoleWrite("not minimized" & @CRLF)
$currentWinPos = WinGetPos($hgui)
$options.PositionX = $currentWinPos[0]
$options.PositionY = $currentWinPos[1]
$currentWinPos = WinGetClientSize($hgui)
Local $captionH = _WinAPI_GetSystemMetrics($SM_CYCAPTION)
Local $borderW = _WinAPI_GetSystemMetrics($SM_CXBORDER)
Local $borderH = _WinAPI_GetSystemMetrics($SM_CYBORDER)
$options.PositionW = $currentWinPos[0]
$options.PositionH = $currentWinPos[1] + $captionH - 2 * $borderH - 1
IniWriteSection($sProfileName, "options", $options.getSection, 0)
EndIf
Exit
EndFunc ;==>_Exit
Func _onCreateLink()
_CreateLink()
EndFunc ;==>_onCreateLink
;------------------------------------------------------------------------------
; Title........: _onExitChild
; Description..: Close any child window
; Events.......: child window GUI_EVENT_CLOSE, OK/Cancel button
;------------------------------------------------------------------------------
Func _onExitChild()
_ExitChild(@GUI_WinHandle)
If @GUI_WinHandle = $statusChild Then
$statusChild = 0
EndIf
EndFunc ;==>_onExitChild
;------------------------------------------------------------------------------
; Title........: _OnTrayClick
; Description..: Restore or hide program to system tray
; Events.......: single left-click on tray icon
;------------------------------------------------------------------------------
Func _OnTrayClick()
If TrayItemGetText($RestoreItem) = $oLangStrings.traymenu.restore Then
_maximize()
Else
_SendToTray()
EndIf
EndFunc ;==>_OnTrayClick
;------------------------------------------------------------------------------
; Title........: _OnRestore
; Description..: Restore or hide program to system tray
; Events.......: 'Restore' item in tray right-click menu
;------------------------------------------------------------------------------
Func _OnRestore()
If TrayItemGetText($RestoreItem) = $oLangStrings.traymenu.restore Then
_maximize()
Else
_SendToTray()
EndIf
EndFunc ;==>_OnRestore
;------------------------------------------------------------------------------
; Title........: _onBlacklist
; Description..: Create the 'Hide adapters' child window
; Events.......: 'Hide adapters' item in the 'View' menu
;------------------------------------------------------------------------------
Func _onBlacklist()
_form_blacklist()
EndFunc ;==>_onBlacklist
;------------------------------------------------------------------------------
; Title........: _onRadio
; Description..: Update radio button selections and states
; Events.......: Any radio button state changed
;------------------------------------------------------------------------------
Func _onRadio()
ConsoleWrite("click" & @CRLF)
_radios()
EndFunc ;==>_onRadio
;------------------------------------------------------------------------------
; Title........: _onRadioIpAuto
; Description..: Update radio button selections and states
; Events.......: radio button or text clicked
;------------------------------------------------------------------------------
Func _onRadioIpAuto()
GUICtrlSetState($radio_IpMan, $GUI_UNCHECKED)
GUICtrlSetState($radio_IpAuto, $GUI_CHECKED)
If GUICtrlRead($radio_DnsMan) = $GUI_CHECKED Then
GUICtrlSetState($radio_DnsAuto, $GUI_UNCHECKED)
EndIf
_radios()
EndFunc ;==>_onRadioIpAuto
;------------------------------------------------------------------------------
; Title........: _onRadioIpMan
; Description..: Update radio button selections and states
; Events.......: radio button or text clicked
;------------------------------------------------------------------------------
Func _onRadioIpMan()
GUICtrlSetState($radio_IpAuto, $GUI_UNCHECKED)
GUICtrlSetState($radio_IpMan, $GUI_CHECKED)
GUICtrlSetState($radio_DnsMan, $GUI_UNCHECKED)
GUICtrlSetState($radio_DnsAuto, $GUI_CHECKED)
_radios()
EndFunc ;==>_onRadioIpMan
;------------------------------------------------------------------------------
; Title........: _onRadioDnsAuto
; Description..: Update radio button selections and states
; Events.......: radio button or text clicked
;------------------------------------------------------------------------------
Func _onRadioDnsAuto()
GUICtrlSetState($radio_DnsMan, $GUI_UNCHECKED)
GUICtrlSetState($radio_DnsAuto, $GUI_CHECKED)
_radios()
EndFunc ;==>_onRadioDnsAuto
;------------------------------------------------------------------------------
; Title........: _onRadioDnsMan
; Description..: Update radio button selections and states
; Events.......: radio button or text clicked
;------------------------------------------------------------------------------
Func _onRadioDnsMan()
GUICtrlSetState($radio_DnsAuto, $GUI_UNCHECKED)
GUICtrlSetState($radio_DnsMan, $GUI_CHECKED)
_radios()
EndFunc ;==>_onRadioDnsMan
;------------------------------------------------------------------------------
; Title........: _onCheckboxRegDns
; Description..: Set checkbox state
; Events.......: click checkbox text
;------------------------------------------------------------------------------
Func _onCheckboxRegDns()
If GUICtrlRead($ck_dnsReg) = $GUI_CHECKED Then
GUICtrlSetState($ck_dnsReg, $GUI_UNCHECKED)
Else
GUICtrlSetState($ck_dnsReg, $GUI_CHECKED)
EndIf
EndFunc ;==>_onCheckboxRegDns
;------------------------------------------------------------------------------
; Title........: _onSelect
; Description..: Set IP address information from profile
; Events.......: Click on profile list item
;------------------------------------------------------------------------------
Func _onSelect()
_setProperties()
EndFunc ;==>_onSelect
;------------------------------------------------------------------------------
; Title........: _onApply
; Description..: Apply the selected profile
; Events.......: File menu 'Apply profile' button, toolbar 'Apply' button
;------------------------------------------------------------------------------
Func _onApply()
_apply_GUI()
EndFunc ;==>_onApply
;------------------------------------------------------------------------------
; Title........: _onArrangeAz
; Description..: Arrange profiles in alphabetical order
; Events.......: Profiles listview context menu item
;------------------------------------------------------------------------------
Func _onArrangeAz()
_arrange()
EndFunc ;==>_onArrangeAz
;------------------------------------------------------------------------------
; Title........: _onArrangeZa
; Description..: Arrange profiles in reverse alphabetical order
; Events.......: Profiles listview context menu item
;------------------------------------------------------------------------------
Func _onArrangeZa()
_arrange(1)
EndFunc ;==>_onArrangeZa
;------------------------------------------------------------------------------
; Title........: _onRename
; Description..: Start editing profile name for the selected listview item
; Events.......: Profiles listview context menu item, F2 accelerator,
; File menu 'Rename' item
;------------------------------------------------------------------------------
Func _onRename()
If Not _ctrlHasFocus($list_profiles) Then
Return
EndIf
$Index = _GUICtrlListView_GetSelectedIndices($list_profiles)
$lvEditHandle = _GUICtrlListView_EditLabel(ControlGetHandle($hgui, "", $list_profiles), $Index)
EndFunc ;==>_onRename
;------------------------------------------------------------------------------
; Title........: _onTabKey
; Description..: Cancel editing listview item - prevents system from tabbing
; through listview items while editing
; Events.......: TAB key (while editing)
;------------------------------------------------------------------------------
Func _onTabKey()
If IsHWnd(_GUICtrlListView_GetEditControl(ControlGetHandle($hgui, "", $list_profiles))) Then
$lvTabKey = True
Send("{ENTER}")
Else
GUISetAccelerators(0)
Send("{TAB}")
GUISetAccelerators($aAccelKeys)
EndIf
EndFunc ;==>_onTabKey
;------------------------------------------------------------------------------
; Title........: _onNewItem
; Description..: Create new listview item and start editing the name
; Events.......: Toolbar button, File menu 'New' item
;------------------------------------------------------------------------------
Func _onNewItem()
$newname = $oLangStrings.message.newItem
;Local $profileNames = _getNames()
Local $profileNames = $profiles.getNames()
Local $i = 1
While _ArraySearch($profileNames, $newname) <> -1
$newname = "New Item " & $i
$i = $i + 1
WEnd
GUISwitch($hgui)
ControlFocus($hgui, "", $list_profiles)
GUICtrlCreateListViewItem($newname, $list_profiles)
GUICtrlSetOnEvent(-1, "_onSelect")
$lv_newItem = 1
$Index = ControlListView($hgui, "", $list_profiles, "GetItemCount")
ControlListView($hgui, "", $list_profiles, "Select", $Index - 1)
_GUICtrlListView_EditLabel(ControlGetHandle($hgui, "", $list_profiles), $Index - 1)
EndFunc ;==>_onNewItem
;------------------------------------------------------------------------------
; Title........: _onSave
; Description..: Save the current settings to the selected profile
; Events.......: Toolbar button, File menu 'Save' item, Ctrl+s accelerator
;------------------------------------------------------------------------------
Func _onSave()
_save()
EndFunc ;==>_onSave
;------------------------------------------------------------------------------
; Title........: _onDelete
; Description..: Delete the selected profile
; Events.......: Toolbar button, Del accelerator
;------------------------------------------------------------------------------
Func _onDelete()
_delete()
EndFunc ;==>_onDelete
;------------------------------------------------------------------------------
; Title........: _onClear
; Description..: Clear the current address fields
; Events.......: Toolbar button, File menu 'Clear' item
;------------------------------------------------------------------------------
Func _onClear()
_clear()
EndFunc ;==>_onClear
;------------------------------------------------------------------------------
; Title........: _onRefresh
; Description..: Refresh the profiles list and current IP info
; Events.......: Toolbar button, View menu 'Refresh' item
;------------------------------------------------------------------------------
Func _onRefresh()
$showWarning = 0
$Index = ControlListView($hgui, "", $list_profiles, "GetSelected")
_refresh()
ControlListView($hgui, "", $list_profiles, "Select", $Index)
EndFunc ;==>_onRefresh
;------------------------------------------------------------------------------
; Title........: _onLvDel
; Description..: Delete the selected listview item
; Events.......: File menu Delete item, listview context menu Delete item
;------------------------------------------------------------------------------
Func _onLvDel()
If _ctrlHasFocus($list_profiles) Then
_delete()
Else
GUISetAccelerators(0)
Send("{DEL}")
GUISetAccelerators($aAccelKeys)
EndIf
EndFunc ;==>_onLvDel
;------------------------------------------------------------------------------
; Title........: _onLvUp
; Description..: Move listview selection up 1 index and get the profile info
; Events.......: UP key accelerator
;------------------------------------------------------------------------------
Func _onLvUp()
If _ctrlHasFocus($list_profiles) Then
$Index = ControlListView($hgui, "", $list_profiles, "GetSelected")
ControlListView($hgui, "", $list_profiles, "Select", $Index - 1)
_setProperties()
Else
GUISetAccelerators(0)
Send("{Up}")
GUISetAccelerators($aAccelKeys)
EndIf
EndFunc ;==>_onLvUp
;------------------------------------------------------------------------------
; Title........: _onLvDown
; Description..: Move listview selection down 1 index and get the profile info
; Events.......: DOWN key accelerator
;------------------------------------------------------------------------------
Func _onLvDown()
If _ctrlHasFocus($list_profiles) Then
$Index = ControlListView($hgui, "", $list_profiles, "GetSelected")
ControlListView($hgui, "", $list_profiles, "Select", $Index + 1)
_setProperties()
Else
GUISetAccelerators(0)
Send("{Down}")
GUISetAccelerators($aAccelKeys)
EndIf
EndFunc ;==>_onLvDown
;------------------------------------------------------------------------------
; Title........: _onLvEnter
; Description..: Apply the selected profile
; Events.......: Enter key on listview item
;------------------------------------------------------------------------------
Func _onLvEnter()
If _ctrlHasFocus($memo) Then
GUISetAccelerators(0)
Send("{ENTER}")
GUISetAccelerators($aAccelKeys)
Return
EndIf
If Not $lv_editing Then
_apply_GUI()
Else
GUISetAccelerators(0)
Send("{ENTER}")
GUISetAccelerators($aAccelKeys)
EndIf
EndFunc ;==>_onLvEnter
;------------------------------------------------------------------------------
; Title........: _onTray
; Description..: Hide or show main GUI window
; Events.......: Toolbar button, View menu "Send to tray" item
;------------------------------------------------------------------------------
Func _onTray()
_SendToTray()
EndFunc ;==>_onTray
;------------------------------------------------------------------------------
; Title........: _onLightMode
; Description..: Set light mode
; Events.......: View menu -> Appearance
;------------------------------------------------------------------------------
Func _onLightMode()
_setTheme(True)
GUICtrlSetState($lightmodeitem, $GUI_CHECKED)
GUICtrlSetState($darkmodeitem, $GUI_UNCHECKED)
$options.Theme = "Light"
IniWrite($sProfileName, "options", "Theme", "Light")
EndFunc ;==>_onLightMode
;------------------------------------------------------------------------------
; Title........: _onDarkMode
; Description..: Set dark mode
; Events.......: View menu -> Appearance
;------------------------------------------------------------------------------
Func _onDarkMode()
_setTheme(False)
GUICtrlSetState($lightmodeitem, $GUI_UNCHECKED)
GUICtrlSetState($darkmodeitem, $GUI_CHECKED)
$options.Theme = "Dark"
IniWrite($sProfileName, "options", "Theme", "Dark")
EndFunc ;==>_onDarkMode
;------------------------------------------------------------------------------
; Title........: _onPull
; Description..: Get current IP information from adapter
; Events.......: Tools menu "Pull from adapter" item
;------------------------------------------------------------------------------
Func _onPull()
_Pull()
EndFunc ;==>_onPull
;------------------------------------------------------------------------------
; Title........: _onDisable
; Description..: Disable / Enable the selected adapter
; Events.......: Tools menu "Disable adapter" item
;------------------------------------------------------------------------------
Func _onDisable()
_disable()
EndFunc ;==>_onDisable
;------------------------------------------------------------------------------
; Title........: _onRelease
; Description..: Release DHCP for the selected adapter
; Events.......: Tools menu "Release DHCP" item
;------------------------------------------------------------------------------
Func _onRelease()
_releaseDhcp()
EndFunc ;==>_onRelease
;------------------------------------------------------------------------------
; Title........: _onRenew
; Description..: Renew DHCP for the selected adapter
; Events.......: Tools menu "Renew DHCP" item
;------------------------------------------------------------------------------
Func _onRenew()
_renewDhcp()
EndFunc ;==>_onRenew
;------------------------------------------------------------------------------
; Title........: _onCycle
; Description..: Release DHCP followed by Renew DHCP for the selected adapter
; Events.......: Tools menu "Release/renew cycle" item
;------------------------------------------------------------------------------
Func _onCycle()
_cycleDhcp()
EndFunc ;==>_onCycle
;------------------------------------------------------------------------------
; Title........: _onSettings
; Description..: Create the settings child window
; Events.......: Tools menu "Settings" item
;------------------------------------------------------------------------------
Func _onSettings()
_formm_settings()
EndFunc ;==>_onSettings
;------------------------------------------------------------------------------
; Title........: _onHelp
; Description..: Navigate to documentation link <-- needs to be created!
; Events.......: Help menu "Online Documentation" item
;------------------------------------------------------------------------------
Func _onHelp()
ShellExecute('https://github.com/KurtisLiggett/Simple-IP-Config/wiki')
EndFunc ;==>_onHelp
Func _onUpdateCheckItem()
$suppressComError = 1
_checksSICUpdate(1)
$suppressComError = 0
EndFunc ;==>_onUpdateCheckItem
;------------------------------------------------------------------------------
; Title........: _onDebugItem
; Description..: Create debug child window
; Events.......: Help menu "Debug Information" item
;------------------------------------------------------------------------------
Func _onDebugItem()
_form_debug()
EndFunc ;==>_onDebugItem
;------------------------------------------------------------------------------
; Title........: _onChangelog
; Description..: Create change log child window
; Events.......: Help menu "Show Change Log" item
;------------------------------------------------------------------------------
Func _onChangelog()
_form_changelog()
EndFunc ;==>_onChangelog
;------------------------------------------------------------------------------
; Title........: _onAbout
; Description..: Create the About child window
; Events.......: Help menu "About Simple IP Config" item, tray right-click menu
;------------------------------------------------------------------------------
Func _onAbout()
_form_about()
EndFunc ;==>_onAbout
;------------------------------------------------------------------------------
; Title........: _onFilter
; Description..: Filter the profiles listview
; Events.......: Filter input text change
;------------------------------------------------------------------------------
Func _onFilter()
_filterProfiles()
EndFunc ;==>_onFilter
;------------------------------------------------------------------------------
; Title........: _OnCombo
; Description..: Update adapter information, save last used adapter to profiles.ini
; Events.......: Combobox selection change
;------------------------------------------------------------------------------
Func _OnCombo()
_updateCurrent()
$adap = GUICtrlRead($combo_adapters)
$iniAdap = iniNameEncode($adap)
$ret = IniWrite($sProfileName, "options", "StartupAdapter", $iniAdap)
If $ret = 0 Then
_setStatus("An error occurred while saving the selected adapter", 1)
Else
$options.StartupAdapter = $adap
EndIf
EndFunc ;==>_OnCombo
;------------------------------------------------------------------------------
; Title........: _iconLink
; Description..: Open browser and go to icon website
; Events.......: Click on link in About window
;------------------------------------------------------------------------------
Func _iconLink()
ShellExecute('http://www.aha-soft.com/')
GUICtrlSetColor(@GUI_CtrlId, 0x551A8B)
EndFunc ;==>_iconLink
;------------------------------------------------------------------------------
; Title........: _updateLink
; Description..: Open browser and go to latest version
; Events.......: Click on link in update window
;------------------------------------------------------------------------------
Func _updateLink()
$sURL = "https://github.com/KurtisLiggett/Simple-IP-Config/releases/latest"
ShellExecute($sURL)
GUICtrlSetColor(@GUI_CtrlId, 0x551A8B)
EndFunc ;==>_updateLink
;------------------------------------------------------------------------------
; Title........: _onOpenProfiles
; Description..: Open a custom profiles.ini file
; Events.......: File menu
;------------------------------------------------------------------------------
Func _onOpenProfiles()
$OpenFileFlag = 1
EndFunc ;==>_onOpenProfiles
;------------------------------------------------------------------------------
; Title........: _onImportProfiles
; Description..: Import profiles from a file
; Events.......: File menu
;------------------------------------------------------------------------------
Func _onImportProfiles()
$ImportFileFlag = 1
EndFunc ;==>_onImportProfiles
;------------------------------------------------------------------------------
; Title........: _onExportProfiles
; Description..: export profiles to a file
; Events.......: File menu
;------------------------------------------------------------------------------
Func _onExportProfiles()
$ExportFileFlag = 1
EndFunc ;==>_onExportProfiles
;------------------------------------------------------------------------------
; Title........: _onOpenProfLoc
; Description..: open folder containing profiles.ini file
; Events.......: Tools menu
;------------------------------------------------------------------------------
Func _onOpenProfLoc()
;~ Local $path = StringRegExp($sProfileName, "(.*)\\", $STR_REGEXPARRAYGLOBALMATCH)
Local $path = $sProfileName
Run("explorer.exe /n,/e,/select," & $path)
EndFunc ;==>_onOpenProfLoc
;------------------------------------------------------------------------------
; Title........: _onOpenNetConnections
; Description..: open the network connections dialog
; Events.......: Tools menu
;------------------------------------------------------------------------------
Func _onOpenNetConnections()
ShellExecute("ncpa.cpl")
EndFunc ;==>_onOpenNetConnections
;------------------------------------------------------------------------------
; Title........: _onCopyIp
; Description..: Copy the IP address into clipboard
; Events.......: button click
;------------------------------------------------------------------------------
Func _onCopyIp()
ClipPut(_GUICtrlIpAddress_Get($ip_Ip))
EndFunc ;==>_onCopyIp
;------------------------------------------------------------------------------
; Title........: _onPasteIp
; Description..: Paste the IP address from clipboard into the IP box
; Events.......: button click
;------------------------------------------------------------------------------
Func _onPasteIp()
$sIpString = _GUICtrlIpAddress_Set($ip_Ip, ClipGet())
EndFunc ;==>_onPasteIp
;------------------------------------------------------------------------------
; Title........: _onCopySubnet
; Description..: Copy the Subnet address into clipboard
; Events.......: button click
;------------------------------------------------------------------------------
Func _onCopySubnet()
ClipPut(_GUICtrlIpAddress_Get($ip_Subnet))
EndFunc ;==>_onCopySubnet
;------------------------------------------------------------------------------
; Title........: _onPasteSubnet
; Description..: Paste the Subnet address from clipboard into the IP box
; Events.......: button click
;------------------------------------------------------------------------------
Func _onPasteSubnet()
$sIpString = _GUICtrlIpAddress_Set($ip_Subnet, ClipGet())
EndFunc ;==>_onPasteSubnet
;------------------------------------------------------------------------------
; Title........: _onCopyGateway
; Description..: Copy the Gateway address into clipboard
; Events.......: button click
;------------------------------------------------------------------------------
Func _onCopyGateway()
ClipPut(_GUICtrlIpAddress_Get($ip_Gateway))
EndFunc ;==>_onCopyGateway
;------------------------------------------------------------------------------
; Title........: _onPasteGateway
; Description..: Paste the Gateway address from clipboard into the IP box
; Events.......: button click
;------------------------------------------------------------------------------
Func _onPasteGateway()
$sIpString = _GUICtrlIpAddress_Set($ip_Gateway, ClipGet())
EndFunc ;==>_onPasteGateway
;------------------------------------------------------------------------------
; Title........: _onCopyDnsPri
; Description..: Copy the Gateway address into clipboard
; Events.......: button click
;------------------------------------------------------------------------------
Func _onCopyDnsPri()
ClipPut(_GUICtrlIpAddress_Get($ip_DnsPri))
EndFunc ;==>_onCopyDnsPri
;------------------------------------------------------------------------------
; Title........: _onPasteDnsPri
; Description..: Paste the Gateway address from clipboard into the IP box
; Events.......: button click
;------------------------------------------------------------------------------
Func _onPasteDnsPri()
$sIpString = _GUICtrlIpAddress_Set($ip_DnsPri, ClipGet())
EndFunc ;==>_onPasteDnsPri
;------------------------------------------------------------------------------
; Title........: _onCopyDnsAlt
; Description..: Copy the Gateway address into clipboard
; Events.......: button click
;------------------------------------------------------------------------------
Func _onCopyDnsAlt()
ClipPut(_GUICtrlIpAddress_Get($ip_DnsAlt))
EndFunc ;==>_onCopyDnsAlt
;------------------------------------------------------------------------------
; Title........: _onPasteDnsAlt
; Description..: Paste the Gateway address from clipboard into the IP box
; Events.......: button click
;------------------------------------------------------------------------------
Func _onPasteDnsAlt()
$sIpString = _GUICtrlIpAddress_Set($ip_DnsAlt, ClipGet())
EndFunc ;==>_onPasteDnsAlt
;------------------------------------------------------------------------------
; Title........: WM_COMMAND
; Description..: Process WM_COMMAND messages
; - Toolbar buttons
; - Listview filter
; - Combobox selection changed
;------------------------------------------------------------------------------
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
Local $ID = BitAND($wParam, 0xFFFF)
Local $iIDFrom = BitAND($wParam, 0x0000FFFF) ; LoWord - this gives the control which sent the message
Local $iCode = BitShift($wParam, 16) ; HiWord - this gives the message that was sent
Local $tempstring, $iDot1Pos, $iDot2Pos, $iDot3Pos, $SplitString, $temp, $tip
Switch $hWnd
Case $hgui
If $iCode = $EN_CHANGE Then
Switch $iIDFrom
Case $input_filter
GUICtrlSendToDummy($filter_dummy)
EndSwitch
ElseIf $iCode = $CBN_CLOSEUP Then ; check if combo was closed
Switch $iIDFrom
Case $combo_adapters
GUICtrlSendToDummy($combo_dummy)
EndSwitch
EndIf
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
;------------------------------------------------------------------------------
; Title........: WM_NOTIFY
; Description..: Process WM_NOTIFY messages
; - Toolbar tooltips
; - Listview begin/end label edit
; - Detect moving from IP address to Subnet mask
;------------------------------------------------------------------------------
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
Local $tNMIA = DllStructCreate($tagNMITEMACTIVATE, $lParam)
Local $hTarget = DllStructGetData($tNMIA, 'hWndFrom')
Local $ID = DllStructGetData($tNMIA, 'Code')
$hWndListView = $list_profiles
If Not IsHWnd($hWndListView) Then $hWndListView = GUICtrlGetHandle($hWndListView)
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWnd
Case $hgui
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $LVN_BEGINLABELEDITA, $LVN_BEGINLABELEDITW ; Start of label editing for an item
$lv_editIndex = _GUICtrlListView_GetSelectedIndices($list_profiles)
$lv_oldName = ControlListView($hgui, "", $list_profiles, "GetText", $lv_editIndex)
$lv_editing = 1
$lv_startEditing = 0
$lv_aboutEditing = 0
Return False
Case $LVN_ENDLABELEDITA, $LVN_ENDLABELEDITW ; The end of label editing for an item
$lv_doneEditing = 1
$lv_editing = 0
$tInfo = DllStructCreate($tagNMLVDISPINFO, $lParam)
If _WinAPI_GetAsyncKeyState($VK_RETURN) == 1 Then ;enter key was pressed
Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", DllStructGetData($tInfo, "Text"))
If StringLen(DllStructGetData($tBuffer, "Text")) Then
Return True
Else
If $lv_newItem = 1 Then
_GUICtrlListView_DeleteItem(ControlGetHandle($hgui, "", $list_profiles), $lv_editIndex)
$lv_newItem = 0
EndIf
$lv_aboutEditing = 1
EndIf
Else
If $lv_newItem = 1 Then
_GUICtrlListView_DeleteItem(ControlGetHandle($hgui, "", $list_profiles), $lv_editIndex)
$lv_newItem = 0
EndIf
$lv_aboutEditing = 1
EndIf
EndSwitch
Case $ip_Ip
Switch $iCode
Case $IPN_FIELDCHANGED ; Sent when the user changes a field in the control or moves from one field to another
;~ $tInfo = DllStructCreate($tagNMIPADDRESS, $lParam)
;~ $movetosubnet = DllStructGetData($tInfo, "hWndFrom")
$movetosubnet = 1
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
;~ Global $resizing
;------------------------------------------------------------------------------
; Title........: WM_SIZE
; Description..: Process WM_SIZE messages
; - Reposition custom buttons
;------------------------------------------------------------------------------
Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
If $hWnd <> $hgui Then
Return $GUI_RUNDEFMSG
EndIf
Local $clientWidth = BitAND($lParam, 0xFFFF)
Local $clientHeight = BitShift($lParam, 16)
WinMove($ip_Ip, "", $clientWidth - $IpAddressOffset, Default)
WinMove($ip_Subnet, "", $clientWidth - $IpAddressOffset, Default)
WinMove($ip_Gateway, "", $clientWidth - $IpAddressOffset, Default)
WinMove($ip_DnsPri, "", $clientWidth - $IpAddressOffset, Default)
WinMove($ip_DnsAlt, "", $clientWidth - $IpAddressOffset, Default)
GuiFlatButton_SetPos($buttonCopyIp, $clientWidth - $buttonCopyOffset)
GuiFlatButton_SetPos($buttonCopySubnet, $clientWidth - $buttonCopyOffset)
GuiFlatButton_SetPos($buttonCopyGateway, $clientWidth - $buttonCopyOffset)
GuiFlatButton_SetPos($buttonCopyDnsPri, $clientWidth - $buttonCopyOffset)
GuiFlatButton_SetPos($buttonCopyDnsAlt, $clientWidth - $buttonCopyOffset)
GuiFlatButton_SetPos($buttonPasteIp, $clientWidth - $buttonPasteOffset)
GuiFlatButton_SetPos($buttonPasteSubnet, $clientWidth - $buttonPasteOffset)
GuiFlatButton_SetPos($buttonPasteGateway, $clientWidth - $buttonPasteOffset)
GuiFlatButton_SetPos($buttonPasteDnsPri, $clientWidth - $buttonPasteOffset)
GuiFlatButton_SetPos($buttonPasteDnsAlt, $clientWidth - $buttonPasteOffset)
GuiFlatButton_SetPos($buttonRefresh, $clientWidth - $buttonRefreshOffset)
GuiFlatButton_SetPos($tbButtonApply, $clientWidth - $buttonApplyOffset)
_GUICtrlListView_SetColumnWidth($list_profiles, 0, $clientWidth - $guiRightWidth - 24 * $dscale) ; sets column width
EndFunc ;==>WM_SIZE
Func _initSize()
Local $aClientSize = WinGetClientSize($hgui)
Local $clientWidth = $aClientSize[0]
Local $clientHeight = $aClientSize[1]
WinMove($ip_Ip, "", $clientWidth - $IpAddressOffset, Default)
WinMove($ip_Subnet, "", $clientWidth - $IpAddressOffset, Default)
WinMove($ip_Gateway, "", $clientWidth - $IpAddressOffset, Default)
WinMove($ip_DnsPri, "", $clientWidth - $IpAddressOffset, Default)
WinMove($ip_DnsAlt, "", $clientWidth - $IpAddressOffset, Default)
GuiFlatButton_SetPos($buttonCopyIp, $clientWidth - $buttonCopyOffset)
GuiFlatButton_SetPos($buttonCopySubnet, $clientWidth - $buttonCopyOffset)
GuiFlatButton_SetPos($buttonCopyGateway, $clientWidth - $buttonCopyOffset)
GuiFlatButton_SetPos($buttonCopyDnsPri, $clientWidth - $buttonCopyOffset)
GuiFlatButton_SetPos($buttonCopyDnsAlt, $clientWidth - $buttonCopyOffset)
GuiFlatButton_SetPos($buttonPasteIp, $clientWidth - $buttonPasteOffset)
GuiFlatButton_SetPos($buttonPasteSubnet, $clientWidth - $buttonPasteOffset)
GuiFlatButton_SetPos($buttonPasteGateway, $clientWidth - $buttonPasteOffset)
GuiFlatButton_SetPos($buttonPasteDnsPri, $clientWidth - $buttonPasteOffset)
GuiFlatButton_SetPos($buttonPasteDnsAlt, $clientWidth - $buttonPasteOffset)
GuiFlatButton_SetPos($buttonRefresh, $clientWidth - $buttonRefreshOffset)
GuiFlatButton_SetPos($tbButtonApply, $clientWidth - $buttonApplyOffset)
_GUICtrlListView_SetColumnWidth($list_profiles, 0, $clientWidth - $guiRightWidth - 24 * $dscale) ; sets column width
EndFunc
;------------------------------------------------------------------------
; Title........: WM_GETMINMAXINFO
; Description..: Process WM_GETMINMAXINFO messages
;------------------------------------------------------------------------------
Func WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam)
If $hWnd <> $hgui Then
Return $GUI_RUNDEFMSG
EndIf
$tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
DllStructSetData($tagMaxinfo, 7, $guiMinWidth) ; min X
DllStructSetData($tagMaxinfo, 8, $guiMinHeight) ; min Y
DllStructSetData($tagMaxinfo, 9, $guiMaxWidth) ; max X
DllStructSetData($tagMaxinfo, 10, $guiMaxHeight) ; max Y
Return 0
EndFunc ;==>WM_GETMINMAXINFO