TestComplete:How to identify my application icon in the system tray Notification area - testcomplete

I need to locate my application from the Notification Area in the system tray.How can i make it work using the shortcut key Win +B for Win7 and Win8?
Thanks

What do you want to do with the application? Launch it? The following sample right-clicks the icon in the system tray based on the app name:
//JScript
function RightClickTrayIcon(Name, ItemName)
{
var p, tray, show_button;
// Gets the tray
p = Sys.Process("Explorer");
tray = p.Window("Shell_TrayWnd").Window("TrayNotifyWnd");
show_button = tray.WaitWindow("Button", "");
show_button.Click();
aqUtils.Delay(1000);
// Right-clicks the application icon
tray.Window("SysPager").Window("ToolbarWindow32", "Notification Area").
ClickItemR(Name);
// Selects an item from the context menu
tray.PopupMenu.Click(ItemName);
}
function TestClickTray()
{
RightClickTrayIcon("Volume", "Open Volume Control");
}

Related

SwiftUI ColorPicker Fails In Background (Menubar) App

Context
I have an app that runs only from the macOS menubar. (The LSUIElement property in info.plist is set to YES).
Instead of a menu, this app shows an NSPopover when the menubar button is clicked. The popover holds an NSHostingView which has an extremely simple SwiftUI view:
struct PopoverContentView: View
{
#State private var color: CGColor = .white
var body: some View
{
ColorPicker(selection: $color) {
Text("Pick a Color:")
}
}
}
Problem
Clicking on the ColorPicker() does not open the macOS color picker window. The UI of the ColorPicker() button changes, to show the "selected" border state but the color-picker window never appears.
However, if I change LSUIElement to be NO and then make the app active by clicking its Dock icon (so that it takes over the menubar), THEN clicking on the ColorPicker() in the popover actually reveals the color-picker window.
Do you know of a way to force macOS to show the color-picker window for a background application?
The answer turned out to be simple. In the AppKit ViewController that opens the popover when the menubar button is clicked (PopoverController, for me), I simply did this:
extension PopoverController: NSPopoverDelegate
{
func popoverWillShow(_ notification: Notification)
{
NSApp.activate(ignoringOtherApps: true)
}
}
The ColorPicker now correctly shows the standard macOS system color panel on click.

SwiftUI option key alternate menu items on macOS

In many macOS apps, if you open a menu from the main menubar, you can press the option key to change some of the items.
For example in Safari, I can open the File menu, and there is a "Close Tab" item. Pressing option changes it to "Close Other Tabs".
Is there a way to do this with SwiftUI?
I know how to create basic menus, but I don't see a way to detect the option key.
I think in AppKit you use NSMenuItem's isAlternate property.
struct MyApp: App {
var body: some Scene {
WindowGroup {
...
}.commands {
CommandGroup(replacing: .newItem) {
Button { newFolder() } label: { Text("New Folder") }
.keyboardShortcut("n")
...
}
}
Update to Question
I've tried a few more things, and run into two problems.
I can connect a custom object to the end of the NSResponder chain, and the system will call its flagsChanged method when the user presses the option key. However, it will not call this method when a menu is open.
Even if I find a way to observe the option key while the menu is open, changing state used to build a CommandMenu causes the menu to disappear, not rebuild and stay open.
var body: some Commands {
// If the `isOptionDown` property changes when this menu is open,
// SwiftUI doesn't change the menu, it simply closes it.
// That's not how macOS apps usually behave.
CommandGroup(replacing: .pasteboard) {
Button(...)
if optionKeyWatcher.isOptionDown {
Button(...)
} else {
Button(...)
}

Restore WinForms window to correct position after Aero Snap

When I drag a WinForms window to the top of the screen to perform a Maximize "Aero Snap", if I then hit the "Restore" button after this, the window is restored to the correct size but at the wrong location. It flickers to the correct location for a moment, but then it immediately moves to the top of the screen with its title bar halfway off the screen.
Apparently, the WinForms window restores to its last dragged location before it was maximized, which was at the top of the screen where it was dragged in order to do the Aero Snap.
This behavior is incorrect and annoying. You can see the correct behavior by following those same steps for a Windows Explorer window. After an Aero Snap, the Windows Explorer window correctly restores to the last dropped restore location (wherever it was sitting before it was dragged to do the Aero Snap).
How can I make a WinForms window restore to the correct location after an Aero Snap, like a Windows Explorer window does?
I could try and hook into the form positioning events and save the last-dropped restore location, and restore that after a Restore after an Aero Snap, but I'm hoping there's a simpler way.
You can override the OnResizeBegin, OnResizeEnd and OnSizeChanged methods to:
store a Form's current Location when it's first dragged (when you begin to drag a Form around the OnResizeBegin is called)
clear the stored values if the Form is released (OnResizeEnd is called) while it's WindowState is FormWindowState.Normal
finally restore the Form.Location when OnSizeChanged notifies that the Form.WindowState changes from FormWindowState.Maximized to FormWindowState.Normal.
If you use a Controller or similar, you can subscribe to the corresponding events instead.
Point beginDragLocation = Point.Empty;
FormWindowState beginDragFormState = FormWindowState.Normal;
protected override void OnResizeBegin(EventArgs e)
{
base.OnResizeBegin(e);
beginDragLocation = this.Location;
}
protected override void OnResizeEnd(EventArgs e)
{
base.OnResizeEnd(e);
if (this.WindowState != FormWindowState.Maximized) {
beginDragLocation = Point.Empty;
}
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
if (beginDragFormState == FormWindowState.Maximized && beginDragLocation != Point.Empty) {
BeginInvoke(new Action(() => this.Location = beginDragLocation));
}
beginDragFormState = this.WindowState;
}

Is there a way to create a Windows 10 app that reside in taskbar similar to People App?

I would like to create a solution that will be like an icon on the taskbar and once clicked it will open as a small popup above the taskbar which will not interrupt the user or other windows similar to the Microsoft People app that will show on the bottom right as the following image:
This question has a similar title to my question but it's different subject where the asker was asking for the AppBar of the UWP app which is not my intention.
Other question
Is there a way to do that for normal developers, enterprise companies, or Microsoft partners?
Update 3rd :
Recently I tried to build the App, shared in this repo https://github.com/ejabu/TrayApp
things to note :
WindowStyle
to get Borderless window like People App.
<!-- MainWindow.xaml -->
<Window
....
WindowStyle="None">
<Grid/>
</Window>
ShowInTaskbar
ShowInTaskbar -> False
to prevent it appears on Taskbar
<!-- MainWindow.xaml -->
<Window
....
ShowInTaskbar="False"
...>
<Grid/>
</Window>
Use Hide Method
/// MainWindow.xaml.cs
private void Hide_Window()
{
this.Hide(); /// Minimize Window
}
Adjust Position according to Taskbar
/// MainWindow.xaml.cs
private void AdjustWindowPosition()
{
Screen sc = Screen.FromHandle(new WindowInteropHelper(this).Handle);
if (sc.WorkingArea.Top > 0)
{
Rect desktopWorkingArea = SystemParameters.WorkArea;
Left = desktopWorkingArea.Right - Width;
Top = desktopWorkingArea.Top;
}
else if ((sc.Bounds.Height - sc.WorkingArea.Height) > 0)
{
Rect desktopWorkingArea = SystemParameters.WorkArea;
Left = desktopWorkingArea.Right - Width;
Top = desktopWorkingArea.Bottom - Height;
}
else
{
Rect desktopWorkingArea = SystemParameters.WorkArea;
Left = desktopWorkingArea.Right - Width;
Top = desktopWorkingArea.Bottom - Height;
}
}
Update 2nd :
https://github.com/AronDavis/TwitchBot/blob/master/TwitchBotApp/Notification.xaml
Update:
https://www.youtube.com/watch?v=jdvD55ir1is
original :
this is the good example
Final Result
the Window page has no Close button. And also it cannot be dragged by commenting this line https://github.com/ejabu/AcrylicWindow/blob/343f4f5a6bc23109a97640f9ac35facb31e9ae43/AcrylicWindow/MainWindow.xaml.cs#L30
I found example project here
https://github.com/shenchauhan/MyPeople/tree/master/MyPeople/MyPeople
We may look at MyPeopleCanvas then.
I found also there is new update from Microsoft, that maybe we can replace Icon images with text in System Tray icon in the near future.
https://newswwc.com/technology/dotnet-technologies/personalized-content-at-a-glance-introducing-news-and-interests-on-the-windows-10-taskbar/
This is the closest i got to what i needed.
Although it's using ElectronJS and not WPF or UWP. But since it's doable with ElectronJS then it should also be doable on WPF.
https://github.com/sfatihk/electron-tray-window
Library is not created by me.

Is it possible to embed a video to Windows Media Player?

I have a winform app in visual studio. On the main interface I have panels ( home panel, about us panel & contact us panel ). When I click the button that takes me to the home panel, I want the video to be there already( in Windows media player obviously ). And to be played automatically when the “ home panel button “ is clicked. The client shouldn’t have to go and look for the video.
Is there a way to do this?
Please help.
Add WMP control to the "Toolbox" panel in Visual Studio: https://learn.microsoft.com/en-us/windows/desktop/wmp/using-the-windows-media-player-control-with-microsoft-visual-studio
Drag WMP control from Toolbox to your Home panel in the form designer.
Add the video to the project and in it's properties, choose "Copy if newer" in "Copy to Output Directory" option.
Override Form.OnLoad or find another suitable place and add code that gives the player the URL of the video and sets other properties.
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
var location = Assembly.GetExecutingAssembly().Location;
var folder = Path.GetDirectoryName(location);
var path = Path.Combine(folder, "small.avi");
axWindowsMediaPlayer1.URL = path;
axWindowsMediaPlayer1.uiMode = "none";
// autoplay if current page index is 0 (home?)
if (tabControl1.SelectedIndex == 0)
axWindowsMediaPlayer1.Ctlcontrols.play();
}
If you want the player to restart playback everytime the page gets displayed, add handler to TabControl.SelectedIndexChanged event:
this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.TabControl1_SelectedIndexChanged);
and implement it like this:
private void TabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex == 0)
axWindowsMediaPlayer1.Ctlcontrols.play();
}

Resources