-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMainWindow.xaml.cs
794 lines (622 loc) · 31.4 KB
/
MainWindow.xaml.cs
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
using Handheld_Control_Panel.Classes.Controller_Management;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ControlzEx.Theming;
using MahApps.Metro.Controls;
using Handheld_Control_Panel.Classes.Global_Variables;
using Handheld_Control_Panel.Classes;
using System.Runtime.InteropServices;
using MahApps.Metro.IconPacks;
using System.Windows.Threading;
using System.Management;
using System.Net.NetworkInformation;
using Handheld_Control_Panel.UserControls;
using ControlzEx.Standard;
using System.Reflection;
using System.Windows.Interop;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.IO;
using Handheld_Control_Panel.Classes.Fan_Management;
using Notification.Wpf;
using Notification.Wpf.Classes;
using System.Threading;
using System.Printing;
using System.Windows.Forms;
using Notification.Wpf.Controls;
using System.Collections.ObjectModel;
using Handheld_Control_Panel.Classes.Task_Scheduler;
using System.Globalization;
using Handheld_Control_Panel.Classes.Update_Software;
namespace Handheld_Control_Panel
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
///
public partial class MainWindow : MetroWindow
{
private string window = "MainWindow";
private string page = "";
public DispatcherTimer updateTimer = new DispatcherTimer(DispatcherPriority.Background);
public bool disable_B_ToClose = false;
public OSK osk;
private System.Windows.Forms.NotifyIcon m_notifyIcon;
public MainWindow()
{
InitializeComponent();
Global_Variables.mainWindow = this;
//check if RTSS should be started at startup, place here to put on main thread so that there isn't an issue calling rtsshooks64.dll
RTSS.checkAutoStartRTSS();
//start mouse mode, required because controller management makes call to mousemode
Global_Variables.mousemodes = new MouseMode_Management();
//start controller management, do this when the window opens to prevent accidental hotkey presses
Controller_Management.start_Controller_Management();
//check controller usb device info GUID instance ID
Controller_Management.getDefaultControllerDeviceInformation();
//now check for hidhide configured DONT RUN THIS YET WAIT FOR GYOR AND VIGEM INSTALL
//Controller_Management.HIDHideConfiguredAsync();
MouseKeyHook.Subscribe();
//subscribe to controller events
Controller_Management.buttonEvents.controllerInput += handleControllerInputs;
//set selected item of hamburger nav menu
navigation.SelectedIndex = 0;
//set theme
ThemeManager.Current.ChangeTheme(this, Properties.Settings.Default.SystemTheme + "." + Properties.Settings.Default.systemAccent);
updateStatusBar();
//run timer to update time, wifi and battery status and other stuff
startTimer();
//notifyicon stuff
m_notifyIcon = new System.Windows.Forms.NotifyIcon();
m_notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(AppDomain.CurrentDomain.BaseDirectory + "\\Handheld Control Panel.exe");
m_notifyIcon.MouseClick += M_notifyIcon_Click;
m_notifyIcon.MouseDoubleClick += M_notifyIcon_DoubleClick;
//show notify icon if auto start
if (String.Equals("C:\\Windows\\System32", Directory.GetCurrentDirectory(), StringComparison.OrdinalIgnoreCase))
{
m_notifyIcon.Visible = true;
}
//check for updates first
Update_Software.checkForUpdates(true);
}
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr SetForegroundWindow(IntPtr hwnd);
private void M_notifyIcon_Click(object? sender, EventArgs e)
{
System.Windows.Forms.MouseEventArgs mouseEventArgs = (System.Windows.Forms.MouseEventArgs)e;
if (mouseEventArgs.Button == MouseButtons.Left)
{
toggleWindow();
}
if (mouseEventArgs.Button == MouseButtons.Right)
{
var contextMenu = new ContextMenu();
var menuItem = new MenuItem();
menuItem.Header = "Close";
var menuItemOpen = new MenuItem();
menuItemOpen.Header = "Open";
menuItem.Click += MenuItem_Click;
menuItemOpen.Click += MenuItemOpen_Click;
contextMenu.Items.Add(menuItemOpen);
contextMenu.Items.Add(menuItem);
contextMenu.IsOpen = true;
// Get context menu handle and bring it to the foreground
if (PresentationSource.FromVisual(contextMenu) is HwndSource hwndSource)
{
_ = SetForegroundWindow(hwndSource.Handle);
}
}
}
private void MenuItemOpen_Click(object sender, RoutedEventArgs e)
{
toggleWindow();
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
public void toggleOSK()
{
if (osk == null)
{
osk = new OSK();
osk.Show();
}
else
{
osk.Close();
osk = null;
System.Windows.Threading.Dispatcher
.CurrentDispatcher
.InvokeShutdown();
}
}
private void M_notifyIcon_DoubleClick(object? sender, EventArgs e)
{
toggleWindow();
}
#region timer
private void startTimer()
{
updateTimer.Interval = new TimeSpan(0, 0, 3);
updateTimer.Tick += UpdateTimer_Tick;
updateTimer.Start();
}
private void UpdateTimer_Tick(object? sender, EventArgs e)
{
//timespan changes when a game launches to prevent the auto profile applicator from cycling between default and launched game profile, gives it time to launch
//this just resets it back to 3 seconds after given time to launch
if (updateTimer.Interval.TotalSeconds > 3)
{
updateTimer.Interval = new TimeSpan(0, 0, 3);
}
if (this.Visibility == Visibility.Visible)
{
updateStatusBar();
}
ParallelTaskUpdate_Management.UpdateTaskAlternate();
AutoProfile_Management.checkAutoProfileApplicator();
}
#endregion
#region update status bar
private async void updateStatusBar()
{
await Task.Run(() =>
{
checkNetworkInterface();
checkPowerStatus();
});
Time.Text = DateTime.Now.ToString(CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern);
}
private void checkNetworkInterface()
{
this.Dispatcher.BeginInvoke(() => {
InternetStatus.Text = "\uF384";
//Gets internet status to display on overlay
NetworkInterface[] networkCards = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
bool connectedDevice = false;
foreach (NetworkInterface networkCard in networkCards)
{
if (networkCard.OperationalStatus == OperationalStatus.Up)
{
if (networkCard.NetworkInterfaceType == NetworkInterfaceType.Ethernet) { InternetStatus.Text = "\uE839"; }
if (networkCard.NetworkInterfaceType == NetworkInterfaceType.Wireless80211) { InternetStatus.Text = "\uE701"; }
}
}
});
}
private void checkPowerStatus()
{
int batterylevel = -1;
ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_Battery");
string powerStatus = "AC";
foreach (ManagementObject mo in mos.Get())
{
powerStatus = mo["EstimatedChargeRemaining"].ToString();
}
if (powerStatus != "AC")
{
batterylevel = Int16.Parse(powerStatus);
System.Windows.PowerLineStatus Power = SystemParameters.PowerLineStatus;
powerStatus = Power.ToString();
}
else { powerStatus = "AC"; }
this.Dispatcher.BeginInvoke(() => {
switch (powerStatus)
{
case "Online":
if (batterylevel < 10 && batterylevel >= 0) { BatteryStatus.Text = "\uE85A"; }
if (batterylevel < 20 && batterylevel >= 10) { BatteryStatus.Text = "\uE85B"; }
if (batterylevel < 30 && batterylevel >= 20) { BatteryStatus.Text = "\uE85C"; }
if (batterylevel < 40 && batterylevel >= 30) { BatteryStatus.Text = "\uE85D"; }
if (batterylevel < 50 && batterylevel >= 40) { BatteryStatus.Text = "\uE85E"; }
if (batterylevel < 60 && batterylevel >= 50) { BatteryStatus.Text = "\uE85F"; }
if (batterylevel < 70 && batterylevel >= 60) { BatteryStatus.Text = "\uE860"; }
if (batterylevel < 80 && batterylevel >= 70) { BatteryStatus.Text = "\uE861"; }
if (batterylevel < 90 && batterylevel >= 80) { BatteryStatus.Text = "\uE862"; }
if (batterylevel <= 100 && batterylevel >= 90) { BatteryStatus.Text = "\uE83E"; }
BatteryPercentage.Text = batterylevel.ToString() + "%";
break;
case "Offline":
if (batterylevel < 10 && batterylevel >= 0) { BatteryStatus.Text = "\uE850"; }
if (batterylevel < 20 && batterylevel >= 10) { BatteryStatus.Text = "\uE851"; }
if (batterylevel < 30 && batterylevel >= 20) { BatteryStatus.Text = "\uE852"; }
if (batterylevel < 40 && batterylevel >= 30) { BatteryStatus.Text = "\uE853"; }
if (batterylevel < 50 && batterylevel >= 40) { BatteryStatus.Text = "\uE854"; }
if (batterylevel < 60 && batterylevel >= 50) { BatteryStatus.Text = "\uE855"; }
if (batterylevel < 70 && batterylevel >= 60) { BatteryStatus.Text = "\uE856"; }
if (batterylevel < 80 && batterylevel >= 70) { BatteryStatus.Text = "\uE857"; }
if (batterylevel < 90 && batterylevel >= 80) { BatteryStatus.Text = "\uE858"; }
if (batterylevel < 100 && batterylevel >= 90) { BatteryStatus.Text = "\uE859"; }
BatteryPercentage.Text = batterylevel.ToString() + "%";
break;
default:
BatteryPercentage.Text = "";
BatteryStatus.Text = "";
break;
}
});
}
#endregion
private void handleControllerInputs(object sender, EventArgs e)
{
//get action from custom event args for controller
Handheld_Control_Panel.Classes.Controller_Management.controllerInputEventArgs args = (Handheld_Control_Panel.Classes.Controller_Management.controllerInputEventArgs)e;
var mainWindowHandle = new WindowInteropHelper(this).Handle;
if (this.Visibility == Visibility.Visible)
{
switch (args.Action)
{
case "LT":
navigateListBox(true);
break;
case "RT":
navigateListBox(false);
break;
case "B":
if (disable_B_ToClose)
{
Controller_Window_Page_UserControl_Events.raisePageControllerInputEvent(args.Action, window + page);
}
else
{
switch (page)
{
case "OtherSoftwarePage":
navigateFrame("InformationPage");
break;
case "DonatePage":
navigateFrame("InformationPage");
break;
case "TutorialVideosPage":
navigateFrame("InformationPage");
break;
case "CustomizeHomePage":
navigateFrame("HomePage");
break;
case "AutoFanPage":
navigateFrame("SettingsPage");
break;
case "ActionEditPage":
Global_Variables.hotKeys.editingHotkey.LoadProfile(Global_Variables.hotKeys.editingHotkey.ID);
navigateFrame("ActionPage");
break;
case "MouseModeEditPage":
Global_Variables.mousemodes.editingMouseMode.LoadProfile(Global_Variables.mousemodes.editingMouseMode.ID);
navigateFrame("MouseModePage");
break;
case "ProfileEditPage":
Global_Variables.profiles.editingProfile.LoadProfile(Global_Variables.profiles.editingProfile.ID);
navigateFrame("ProfilesPage");
break;
default:
toggleWindow();
break;
}
}
break;
default:
Controller_Window_Page_UserControl_Events.raisePageControllerInputEvent(args.Action, window + page);
break;
}
}
}
public void toggleWindow()
{
if (this.Visibility == Visibility.Hidden || this.WindowState == WindowState.Minimized)
{
//update status bar because time takes forever to load
updateStatusBar();
if (this.WindowState != WindowState.Normal)
{
this.WindowState = WindowState.Normal;
}
//run position check to make sure its located correctly, fixes issue where app moves all over
setWindowSizePosition();
if (navigation.SelectedIndex != -1)
{
//ListBoxItem lbi = navigation.SelectedItem as ListBoxItem;
// frame.Navigate(new Uri("Pages\\" + lbi.Tag.ToString() + "Page.xaml", UriKind.RelativeOrAbsolute));
}
this.Visibility = Visibility.Visible;
m_notifyIcon.Visible = false;
}
else
{
//check resume process, do this always in case they ran the toggle window with suspend process mode
FullScreen_Management.checkResumeProcess();
// dont use this yet Controller_Management.unhideController();
this.Visibility= Visibility.Hidden;
m_notifyIcon.Visible = true;
}
}
#region navigation
private void navigateListBox(bool left)
{
if (left)
{
if (navigation.SelectedIndex > 0) { navigation.SelectedIndex = navigation.SelectedIndex -1; } else { navigation.SelectedIndex = navigation.Items.Count-1; }
}
else
{
if (navigation.SelectedIndex < (navigation.Items.Count - 1)) { navigation.SelectedIndex=navigation.SelectedIndex + 1; } else { navigation.SelectedIndex = 0; }
}
}
private void navigation_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (navigation.SelectedItem != null )
{
ListBoxItem lbi = navigation.SelectedItem as ListBoxItem;
frame.Navigate(new Uri("Pages\\" + lbi.Tag.ToString() + "Page.xaml", UriKind.RelativeOrAbsolute));
page = lbi.Tag.ToString() + "Page";
}
}
public void navigateFrame(string pageName)
{
//logic is if launching from game launcher or
if (pageName == "ProfilesPage" && navigation.SelectedItem !=null)
{
ListBoxItem lbi = navigation.SelectedItem as ListBoxItem;
if (lbi.Tag.ToString() == "AppLauncher")
{
frame.Navigate(new Uri("Pages\\AppLauncherPage.xaml", UriKind.RelativeOrAbsolute));
page = "AppLauncherPage";
}
else
{
frame.Navigate(new Uri("Pages\\" + pageName + ".xaml", UriKind.RelativeOrAbsolute));
page = pageName;
}
}
else
{
frame.Navigate(new Uri("Pages\\" + pageName + ".xaml", UriKind.RelativeOrAbsolute));
page = pageName;
}
}
public void reinitializeProfiles()
{
this.BeginInvoke(new Action(() =>
{
Global_Variables.profiles = new Profiles_Management();
}));
}
public void ShowNotificationInWindowYESNO(string title, NotificationType notificationType, string action)
{
var notificationManager = new NotificationManager();
NotificationContent content = new NotificationContent
{
Title = title,
Type = notificationType,
TrimType = NotificationTextTrimType.NoTrim, // will show attach button on message
RowsCount = 3, //Will show 3 rows and trim after
LeftButtonAction = () => Controller_Management.buttonEvents.raiseControllerInput(action), //Action on left button click, button will not show if it null
RightButtonAction = () => Controller_Management.buttonEvents.raiseControllerInput(""), //Action on left button click, button will not show if it null
//RightButtonAction = () => , //Action on right button click, button will not show if it null
LeftButtonContent = "YES", // Left button content (string or what u want
RightButtonContent = "NO", // Right button content (string or what u want
CloseOnClick = true, // Set true if u want close message when left mouse button click on message (base = true)
Background = new SolidColorBrush(Colors.DarkGray),
Foreground = new SolidColorBrush(Colors.White)
};
notificationManager.Show(content,"WindowArea",new TimeSpan(0,0,15));
}
public void ShowNotificationInWindow(string title, NotificationType notificationType)
{
this.BeginInvoke(new Action(() =>
{
var notificationManager = new NotificationManager();
var content = new NotificationContent
{
Title = title,
Type = notificationType,
TrimType = NotificationTextTrimType.NoTrim, // will show attach button on message
RowsCount = 3, //Will show 3 rows and trim after
CloseOnClick = true, // Set true if u want close message when left mouse button click on message (base = true)
Background = new SolidColorBrush(Colors.DarkGray),
Foreground = new SolidColorBrush(Colors.White)
};
notificationManager.Show(content);
}));
}
private void frame_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
//page = frame.Source.ToString().Replace("Pages/","").Replace(".xaml","");
//if (!page.Contains("Profile")) { Global_Variables.profiles.editingProfile = null; }
}
#endregion
#region windows events
public void setWindowSizePosition(bool forceRun = false)
{
if (this.IsLoaded || forceRun)
{
getDPIScaling();
//this relies on getting dpi to scale correctly to the display. This NEEDS to be done after loaded or during loading right after getting DPI. Otherwise
//scaling might not be correct. Added if check for loaded or forceRun
//this is used to set the side which the control panel sits on and can be used to fix position after resolution changes
//icon needs to be rotated for which side it is on
WindowInteropHelper _windowInteropHelper = new WindowInteropHelper(this);
Screen screen = Screen.FromHandle(_windowInteropHelper.Handle);
double scaling;
if (Double.TryParse(Global_Variables.Scaling, out scaling))
{
scaling = scaling / 100;
this.Top = Math.Round(screen.Bounds.Height / scaling * 0.03, 0);
this.Height = Math.Round(screen.Bounds.Height / scaling * 0.91, 0);
if (Properties.Settings.Default.dockWindowRight)
{
//if dockWindowRight is true, move to right side of screen
this.Left = Math.Round((screen.Bounds.Width / scaling) - this.Width, 0);
//packIconFontAwesome.RotationAngle = 0;
borderCorner1.CornerRadius = new System.Windows.CornerRadius(11, 0, 0, 11);
borderCorner2.CornerRadius = new System.Windows.CornerRadius(11, 0, 0, 11);
borderCorner3.CornerRadius = new System.Windows.CornerRadius(0, 0, 0, 11);
}
if (!Properties.Settings.Default.dockWindowRight)
{
borderCorner1.CornerRadius = new System.Windows.CornerRadius(0, 11, 11, 0);
borderCorner2.CornerRadius = new System.Windows.CornerRadius(0, 11, 11, 0);
borderCorner3.CornerRadius = new System.Windows.CornerRadius(0, 0, 11, 0);
this.Left = 0;
//packIconFontAwesome.RotationAngle = 180;
}
}
else
{
this.Top = Math.Round(screen.Bounds.Height * 0.03, 0);
this.Height = Math.Round(screen.Bounds.Height * 0.91, 0);
if (Properties.Settings.Default.dockWindowRight)
{
//if dockWindowRight is true, move to right side of screen
this.Left = screen.Bounds.Width - this.Width;
//packIconFontAwesome.RotationAngle = 0;
borderCorner1.CornerRadius = new System.Windows.CornerRadius(11, 0, 0, 11);
borderCorner2.CornerRadius = new System.Windows.CornerRadius(11, 0, 0, 11);
borderCorner3.CornerRadius = new System.Windows.CornerRadius(0, 0, 0, 11);
}
if (!Properties.Settings.Default.dockWindowRight)
{
borderCorner1.CornerRadius = new System.Windows.CornerRadius(0, 11, 11, 0);
borderCorner2.CornerRadius = new System.Windows.CornerRadius(0, 11, 11, 0);
borderCorner3.CornerRadius = new System.Windows.CornerRadius(0, 0, 11, 0);
this.Left = 0;
//packIconFontAwesome.RotationAngle = 180;
}
}
}
}
private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//dispose of notify icon so it doesn't linger in task tray
if (m_notifyIcon != null)
{
m_notifyIcon.Dispose();
}
//stop timers
updateTimer.Stop();
//set the variable startSafeMode to false. This indicates the application shut down properly.
Properties.Settings.Default.startSafeMode = false;
Properties.Settings.Default.Save();
}
private void MetroWindow_LocationChanged(object sender, EventArgs e)
{
//setWindowSizePosition();
}
#endregion
public void changeUserInstruction(string newInstructionUserControl)
{
this.Dispatcher.BeginInvoke(() => {
disable_B_ToClose = false;
instructionStackPanel.Children.Clear();
switch (newInstructionUserControl)
{
case "SelectBack_Instruction":
instructionStackPanel.Children.Add(new SelectBack_Instruction());
break;
case "SelectClose_Instruction":
instructionStackPanel.Children.Add(new SelectClose_Instruction());
break;
case "AutoFanPage_Instruction":
instructionStackPanel.Children.Add(new AutoFanPage_Instruction());
break;
case "AppLauncherPage_Instruction":
instructionStackPanel.Children.Add(new AppLauncherPage_Instruction());
break;
case "HomePage_Instruction":
instructionStackPanel.Children.Add(new HomePage_Instruction());
break;
case "CustomizeHomePage_Instruction":
instructionStackPanel.Children.Add(new CustomizeHomePage_Instruction());
break;
case "ActionPage_Instruction":
instructionStackPanel.Children.Add(new ActionPage_Instruction());
break;
case "ProfilePage_Instruction":
instructionStackPanel.Children.Add(new ProfilePage_Instruction());
break;
case "ProfileEditPage_Instruction":
instructionStackPanel.Children.Add(new ProfileEditPage_Instruction());
break;
case "ActionEditPage_Instruction":
instructionStackPanel.Children.Add(new ActionEditPage_Instruction());
break;
case "SelectedListBox_Instruction":
disable_B_ToClose= true;
instructionStackPanel.Children.Add(new SelectedListBox_Instruction());
break;
case "MouseModePage_Instruction":
instructionStackPanel.Children.Add(new MouseModePage_Instruction());
break;
case "MouseModeEditPage_Instruction":
disable_B_ToClose = true;
instructionStackPanel.Children.Add(new MouseModeEditPage_Instruction());
break;
default: break;
}
});
}
private void MetroWindow_StateChanged(object sender, EventArgs e)
{
//currently not using this to see if i can get away from capturing state change events
}
private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
{
//added a DPI call to the setWindowSizePosition routine, set parameter to true to force run it
setWindowSizePosition(true);
//check if multiple instances are running, if yes message and close the program to prevent errors from two instances running
if (Start_Up.checkMultipleProgramsRunning()) { System.Windows.MessageBox.Show("More than one instance of this program running. Closing this to prevent errors."); this.Close(); }
}
private void getDPIScaling()
{
//used to get absolute resolution (not scaled resolution). IT NEEDS TO RUN ON MAINWINDOW to use the visual tree helper
Global_Variables.Scaling = (VisualTreeHelper.GetDpi(this).DpiScaleX * 100).ToString();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
toggleWindow();
}
private void MetroWindow_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (this.Visibility == Visibility.Hidden)
{
this.ShowInTaskbar = false;
//navigation.SelectedIndex = 0;
//frame.Source = null;
//change interval to 15 seconds
updateTimer.Interval = new TimeSpan(0, 0, 6);
//change controller timer interval to 100 ms to hot key recognition when not open
Controller_Management.timerController.Interval = TimeSpan.FromMilliseconds(Controller_Management.passiveTimerTickInterval);
}
if (this.Visibility == Visibility.Visible)
{
this.ShowInTaskbar = true;
//navigation.SelectedIndex = 0;
updateTimer.Interval = new TimeSpan(0, 0, 3);
//change controller timer interval to 20 ms for active use
Controller_Management.timerController.Interval = TimeSpan.FromMilliseconds(Controller_Management.activeTimerTickInterval);
setWindowSizePosition();
}
}
}
public static class CheckForegroundWindowQAM
{
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
public static bool IsActive(IntPtr handle)
{
IntPtr activeHandle = GetForegroundWindow();
return (activeHandle == handle);
}
}
}