Permanently hide or move taskbar off screen windows 10 LTSB ENT - c#

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.

Related

Show popup in background wpf

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?

SendMessage() only working when window is open, not when minimized

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.

Moving the location and changing size of a external program

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.

How to bring a window foreground using c#?

I am trying to bring a window foreground. I am using this code. But its not working. Could someone please help?
ShowWindowAsync(wnd.hWnd, SW_SHOW);
SetForegroundWindow(wnd.hWnd);
// Code from Karl E. Peterson, www.mvps.org/vb/sample.htm
// Converted to Delphi by Ray Lischner
// Published in The Delphi Magazine 55, page 16
// Converted to C# by Kevin Gale
IntPtr foregroundWindow = GetForegroundWindow();
IntPtr Dummy = IntPtr.Zero;
uint foregroundThreadId = GetWindowThreadProcessId(foregroundWindow, Dummy);
uint thisThreadId = GetWindowThreadProcessId(wnd.hWnd, Dummy);
if (AttachThreadInput(thisThreadId, foregroundThreadId, true))
{
BringWindowToTop(wnd.hWnd); // IE 5.5 related hack
SetForegroundWindow(wnd.hWnd);
AttachThreadInput(thisThreadId, foregroundThreadId, false);
}
if (GetForegroundWindow() != wnd.hWnd)
{
// Code by Daniel P. Stasinski
// Converted to C# by Kevin Gale
IntPtr Timeout = IntPtr.Zero;
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, Timeout, 0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Dummy, SPIF_SENDCHANGE);
BringWindowToTop(wnd.hWnd); // IE 5.5 related hack
SetForegroundWindow(wnd.hWnd);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Timeout, SPIF_SENDCHANGE);
}
Code Explained
Making a window the foreground window
requires more than just calling the
SetForegroundWindow API. You must
first determine the foreground thread
and attach it to your window, using
AttachThreadInput, then call
SetForegroundWindow. That way they can
share input states.
First I call GetForegroundWindow to
get the handle of the current
foreground window. Then a few calls to
GetWindowThreadProcessId retrieve the
threads associated with the current
foreground window and the window I
want to bring to the foreground. If
these threads are the same a simple
call to SetForegroundWindow is all
that is necessary. Otherwise, the
foreground thread is attached to the
window that I am bringing to the front
and detached from what was the current
foreground window. The
AttachThreadInput API handles this.
Content Taken from here
Thanks.
I've used this method before:
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
Process[] processes = Process.GetProcessesByName("processname");
SetForegroundWindow(processes[0].MainWindowHandle);
More information: http://pinvoke.net/default.aspx/user32.SetForegroundWindow
This code restores and set focus to a window:
[DllImport("User32.dll")]
static extern int SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
internal static extern bool SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam, Int32 lParam);
static Int32 WM_SYSCOMMAND = 0x0112;
static Int32 SC_RESTORE = 0xF120;
And use it like this:
var proc = Process.GetProcessesByName("YourProgram").FirstOrDefault();
if (proc != null)
{
var pointer = proc.MainWindowHandle;
SetForegroundWindow(pointer);
SendMessage(pointer, WM_SYSCOMMAND, SC_RESTORE, 0);
}
In order for SetForegroundWindow to work consistently, you have to meet a few criteria. The first is your process that would run the command must be in the foreground. Only foreground process can make another process foreground. In order to make your process foreground first, you have to bring the main window to the front, if it is not. You minimise it first and then SetForegroundWindow it, to make it foreground. Now find the target process and bring it to the front
The steps are
Minimise the current window
SetForegroundWindow it
Find the target process
SetForegroundWindow it
I've got an example, though it's a slightly different use case.
You should use SetForegroundWindow. Also it may be interesting for you C# Force Form Focus
I'll be brief: Form.BringToFront()
As of Windows 7 these features dont behave quite so well. If there is an application such as Excel in front of the application you want to bring to the front then Windows 7 blocks this and flashes the window. You can set a registry timeout setting ForegroundLockTimeout=0 in HKEY_CURRENT_USER\Control Panel\Desktop but these is known as stealing focus. To set the behaviour of how XP "should" behave and will behave in Windows 7 by default you can create/set the value to 0x00030D40 (200000ms).
I'd like to know what is the preferred solution for trusted Windows applications. eg. If I trust application B to take focus when I double click something in Application A, and some other app is obscuring the window of Application B.

Registry settings immediate effect using C#

I have used the following code to disable the control panel:
RegistryKey RegKey = Registry.CurrentUser.CreateSubKey(
#"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer");
RegKey.SetValue("NoControlPanel", false, RegistryValueKind.DWord);
RegKey.Close();
The above code disables control panel only after restarting, I would like to apply the setting immediately without restarting. Please help me.
Try this...
private const int HWND_BROADCAST = 0xffff;
private const int WM_WININICHANGE = 0x001a, WM_SETTINGCHANGE = WM_WININICHANGE, INI_INTL = 1;
SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, INI_INTL);
[DllImport("user32.dll")]
private static extern int SendMessage(int hWnd, uint wMsg, uint wParam, uint lParam);
This will notify all applications that changes have been made to the registry, and those programs that accept the notification shuould reload their settings.
Note that not all applications may do this, but things like control panel should.
I haven't tested this, but I suspect you only have to close all your explorer.exe processes for this to take effect.
Note that the desktop and taskbar are provided by explorer.exe, so you'll need to start a new one after closing them all.
It's a bit hostile, because the user might have Explorer windows that they don't want to lose, so do it only if it's not going to annoy people. 8-)

Categories