The task is this: I need to be able to show popup from my application but doing so should not interact with user typing something in skype, playing games, etc. The window of the application should me opened if it's minimized.
I have the instance of my Main Window. This instance contains code that will show the popup. Thing is I can't use something like this:
window.ShowActivated = false;
simply because this seams to work only if the window is first shown (which is not - the application is already running when I need to call the popup).
Now the other approach that works is using win api.
[DllImport("user32.dll")]
static extern IntPtr GetActiveWindow();
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
var currentForegroundWindow = GetActiveWindow();
window.Show();
SetForegroundWindow(currentForegroundWindow);
What are my concerns - if user is playing game or has low performance PC I can interrupt his actions and he can actually see the window I'm trying to show (which is annoying). So I tried this:
[DllImport("user32.dll", SetLastError=true)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, SetWindowPosFlags uFlags);
SetWindowPos(window.Handle, Bottom, 0, 0, 0, 0, NOREDRAW | NOACTIVATE | NOMOVE);
Now this seams to be ideal. I should be showing the window and I should show it on the bottom. But - it simply don't do the trick. Am I doing something wrong?
Related
We need to hide the taskbar and start menu. We have an app that runs full screen, it is a touch screen application. Our touch screen application is 99.9999% always on screen, covering the entire screen. It is however a complex multimedia app and on rare occasions we have found it crashed exposing the desktop. We have a custom made Win10 LTSB ENT build which is robust and appropriate, but we want to go a step further. We want to remove the taskbar (which is 'hidden') from the desktop entirely.
We can hide the taskbar using the code below, but it keeps returning 5 seconds later. Something keeps undoing our 'hide' and restoring the taskbar without us doing anything.
Am I doing something wrong? Is there a service or mechanism in Windows OS I need to adjust?
private static void setTaskBar(bool hide)
{
IntPtr window = Program.FindWindow("Shell_traywnd", "");
if (hide)
Program.SetWindowPos(window, IntPtr.Zero, 0, 0, 0, 0, 128U);
else
Program.SetWindowPos(window, IntPtr.Zero, 0, 0, 0, 0, 64U);
[DllImport("user32", SetLastError = true)]
private static extern IntPtr FindWindowEx(
IntPtr hWndl,
IntPtr hWnd2,
string lpsz1,
string lpsz2);
}
[DllImport("user32")]
private static extern bool SetWindowPos(
IntPtr hWndl,
IntPtr hWndInsertAfter,
int X,
int Y,
int cx,
int cy,
uint uFlags);
The taskbar is somewhat special, it receives messages from the window manager when other windows go in and out of fullscreen etc and adjusts itself accordingly.
Messing with the shell is the wrong solution. A better solution would be to launch another instance of your program that only has a fullscreen window and does nothing but waiting for the real instance to crash and then restart it if desired.
I wrote an application in C# that brings another application to the foreground.
This function so far. However, there is a problem.
If you set the focus, the application is opened and brought to the foreground, but the Windows docking function does not work. The application is only ever opened in its last window size.
EDIT:
I forgot to mention that the docking should be seen on the Windows desktop (monitor edge).
Does anyone have any idea how to get the docking feature on?
[DllImport("../user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("../user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
public void SetWindowToForeground(List<string> formattedPartList)
{
string windowTitle = formattedPartList[4];
int activeResize = 5; //
IntPtr mainWindowHandle = GetProcessIdByName(windowTitle);
SetForegroundWindow(mainWindowHandle);
ShowWindow(mainWindowHandle, activeResize);
}
There're a lot of ways to simulate a mouse click in an inactive window. I want my program to make clicks even when it's minimized and of course without capturing the main mouse.
Specifically, my C# program will contain a Web Control displaying some flash content and this is where I want the clicks to occur.
here's the techniques I tried:
1.[DllImport("user32.dll", CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
2.[DllImport("user32.dll", SetLastError = true)]
public static extern bool SendMessage(int hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
Both of them did not do any good in my case. Surprisingly, I was able to use the SendMessage() function to send mouse clicks in a minimized chrome displaying some flash content. but, it doesn't seem to do that in my C# program. Is there a possibility that my program not receiving the message for some reason?
Any Hints on how can I do this?
I've been using SendMessage to send mouse clicks to a couple of windows. One being a game(everything works perfectly), but the other window, being a 3rd party tool for the game is having trouble with SendMessage. If the window is 'not minimized' everything works fine, don't matter if window is completely covered up by another. But if that same window is minimized then nothing happens, I checked with spy++ and the messages are indeed getting received but not being processed (correct term?). I've tried to solve this last couple days, doing both searches on here and Google alike, many of topics but nothing helped?
//MyImports
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
And this is how I have it wrapped
public static void LClick(string windowclass, int x, int y)
{
IntPtr WHandle = FindWindow(windowclass, null);
SendMessage(WHandle, (int)WMessages.WM_LBUTTONDOWN, (IntPtr)1, (IntPtr)MakeLParam(x, y));
SendMessage(WHandle, (int)WMessages.WM_LBUTTONUP, (IntPtr)0, (IntPtr)MakeLParam(x, y));
}
I have tried focus, activate. One thing that might be useful info is that the third party program is being loaded as module("Qt5QWindowIcon") of the game.
I tried PostMessage as well, and it does the same thing as SendMessage() same problem when minimized.
This game does allow for macroing and unattended macroing, Hints the third part tool designed to execute the macros (published by the creators) I'm just trying to simulate a mouse click on the program to start the macro.
I would just use SendInput, but the entire purpose of my program is to run in background.
I 've faced same problem .Please change assembly name and project name (Changed name not started with name on that you are throwing/posting windows message)then rebuild it and check it. Now you will able to debug.
By the term of external program, it refer to programs not developed by me.
I have 2 program that needs to be launch together, 1 of it is program developed by me, another is for instance, Window Media Player (just for example only).
These programs will be placed in a static position with no user interaction, so I need to configure their height width and their x/y coordinates. No issue for my own program, but for external program, will I be able to use window message to change their size as well as location.
I have never worked with window message before but I read up somewhere about sendMessage(), but I not sure of the command to move and resize.
My program is done in C#, and I hope to be able to do something like that
You can use the MoveWindow API
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
MoveWindow(ApplicationHandle, 600, 600, 600, 600, True);
If you have the HWND (obtainable through FindWindow or FindWindowEx), you can use SetWindowPos / MoveWindow.