Example #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            _oneInstanceMutex = new Mutex(false, "AwesomeWallpaperOneInstanceMutex", out var createNew);
            if (!createNew)
            {
                Shutdown();
                return;
            }

            _manager = new ViewManager();
            var isSettingsLoaded = _manager.LoadSettings();

            if (isSettingsLoaded)
            {
                if (_manager.Settings.WallpaperType == Settings.WallpaperType.Window &&
                    _manager.Settings.WindowUseAfterRestart &&
                    !string.IsNullOrEmpty(_manager.Settings.WindowProcessName))
                {
                    EnumWindows(new EnumWindowsProc((hWnd, lParam) =>
                    {
                        var processName     = WindowUtils.GetProcessName(hWnd);
                        var windowText      = WindowUtils.GetWmGetText(hWnd);
                        var windowClassName = WindowUtils.GetClassName(hWnd);
                        if (string.Compare(windowText, _manager.Settings.WindowText, StringComparison.CurrentCultureIgnoreCase) == 0 &&
                            string.Compare(windowClassName, _manager.Settings.WindowClassName, StringComparison.CurrentCultureIgnoreCase) == 0 &&
                            string.Compare(processName, _manager.Settings.WindowProcessName, StringComparison.CurrentCultureIgnoreCase) == 0)
                        {
                            _manager.Settings.WindowHandle = hWnd == IntPtr.Zero ? null : (long?)hWnd.ToInt64();
                            _manager.Settings.WindowExTool = WindowUtils.IsExToolWindow(hWnd);
                            _manager.Settings.WindowStatus = "Selected";
                            return(false);
                        }
                        return(true);
                    }), IntPtr.Zero);
                }
                _manager.CreateViews();
                _manager.InitTray();

                _timerSystemTray = new DispatcherTimer()
                {
                    Interval = TimeSpan.FromSeconds(1),
                };
                _timerSystemTray.Tick += TimerTick;
                _timerSystemTray.Start();
            }
        }
Example #2
0
        private void ShowListerForm()
        {
            var fileName = (string)null;

            try
            {
                fileName = WindowUtils.GetSelectedFileFromDesktopOrExplorer();
            }
            catch (Exception e)
            {
                MessageBox.Show("Failed to get selected file. " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Environment.CurrentDirectory = AssemblyUtils.AssemblyDirectory;

            if (_listerForm != null && _listerForm.IsHandleCreated)
            {
                _listerForm.Close();
            }

            if (_listerForm == null || _listerForm.IsDisposed)
            {
                _listerForm = new ListerForm(_settings, _plugins, fileName);
            }

            if (_listerForm.IsDisposed)
            {
                _listerForm = null;
            }
            else
            {
                var hwnd      = NativeMethods.GetForegroundWindow();
                var className = WindowUtils.GetClassName(hwnd);
                if (className == "WorkerW" || className == "Progman")
                {
                    _listerForm.Show();
                }
                else
                {
                    _listerForm.Show(new Win32WindowWrapper(hwnd));
                }
                _listerForm.Activate();
            }
        }
Example #3
0
 private void TargetButton_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
 {
     if (_isButtonTargetMouseDown)
     {
         try
         {
             SetCursor(Properties.Resources.Target32.Handle);
             var cursorPosition   = System.Windows.Forms.Cursor.Position;
             var handle           = WindowFromPoint(new System.Drawing.Point(cursorPosition.X, cursorPosition.Y));
             var parentHandle     = WindowUtils.GetParentWindow(handle);
             var className        = WindowUtils.GetClassName(handle);
             var parentClassName  = WindowUtils.GetClassName(parentHandle);
             var thisWindowHandle = new WindowInteropHelper(this).Handle;
             var viewModel        = (SettingsViewModel)DataContext;
             var classNames       = new List <string>
             {
                 "Shell_TrayWnd",
                 "TrayNotifyWnd",
                 "SysPager",
                 "ToolbarWindow32",
                 "ReBarWindow32",
                 "MSTaskSwWClass",
                 "MSTaskListWClass",
                 "Progman",
                 "WorkerW",
                 "SHELLDLL_DefView",
                 "SysListView32",
                 "Start",
                 "Shell_SecondaryTrayWnd"
             };
             if (thisWindowHandle == parentHandle || classNames.Contains(className) || classNames.Contains(parentClassName))
             {
                 viewModel.WindowHandle             = IntPtr.Zero;
                 viewModel.WindowExTool             = false;
                 viewModel.WindowStatus             = "Not Selected";
                 viewModel.WindowText               = "";
                 viewModel.WindowDelimiterRowHeight = 12;
                 viewModel.WindowRowHeight          = 25;
                 viewModel.WindowImageRowHeight     = 0;
                 WindowImage.Source = new BitmapImage(new Uri("pack://application:,,,/Images/1x1.png"));
             }
             else
             {
                 viewModel.WindowHandle             = parentHandle;
                 viewModel.WindowExTool             = WindowUtils.IsExToolWindow(parentHandle);
                 viewModel.WindowClassName          = WindowUtils.GetClassName(parentHandle);
                 viewModel.WindowStatus             = "Selected";
                 viewModel.WindowText               = WindowUtils.GetWmGetText(parentHandle);
                 viewModel.WindowProcessName        = WindowUtils.GetProcessName(parentHandle);
                 WindowImage.Source                 = WindowUtils.PrintWindow(parentHandle).ConvertToBitmapSource();
                 viewModel.WindowDelimiterRowHeight = 0;
                 viewModel.WindowRowHeight          = 0;
                 viewModel.WindowImageRowHeight     = 155;
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
 }
Example #4
0
 public string GetClassName() => WindowUtils.GetClassName(Handle);