I have a question to put my window in front of all absolutely, but when I launch a print dialog I cant found anyway to hold my window in front: I got to hold my window over the print dialog doing the TopMost, but the taskbar appears although is hidden.
The code in my form window to maximize it and put it overall:
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.TopMost = true;
The code that launch the print dialog:
PrinterSettings printerSettings = new PrinterSettings();
IntPtr hDevMode = printerSettings.GetHdevmode(printerSettings.DefaultPageSettings);
IntPtr pDevMode = GlobalLock(hDevMode);
int sizeNeeded = DocumentProperties(IntPtr.Zero, IntPtr.Zero, printerSettings.PrinterName, IntPtr.Zero, pDevMode, 0);
IntPtr devModeData = Marshal.AllocHGlobal(sizeNeeded);
DocumentProperties(IntPtr.Zero, IntPtr.Zero, printerSettings.PrinterName, devModeData, pDevMode, 14);
// <--- Here the print dialog appears and the thread stops till I close the dialog
GlobalUnlock(hDevMode);
printerSettings.SetHdevmode(devModeData);
printerSettings.DefaultPageSettings.SetHdevmode(devModeData);
GlobalFree(hDevMode);
Marshal.FreeHGlobal(devModeData);
Here the code where I hide the taskbar:
public class Taskbar
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int FindWindow(string className, string windowText);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int ShowWindow(int hwnd, int command);
private const int SW_HIDE = 0;
private const int SW_SHOW = 1;
public Taskbar()
{
}
protected static int Handle
{
get
{
return FindWindow("Shell_TrayWnd", "");
}
}
public static void Show()
{
ShowWindow(Handle, SW_SHOW);
}
public static void Hide()
{
ShowWindow(Handle, SW_HIDE);
}
}
I tried this code also calling SetWinFullScreen in my form after "this.TopMost = true;" to maximize the form but it doesn't work either:
public class WinApi
{
[DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
private static extern int GetSystemMetrics(int which);
[DllImport("user32.dll")]
private static extern void
SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,
int X, int Y, int width, int height, uint flags);
private const int SM_CXSCREEN = 0;
private const int SM_CYSCREEN = 1;
private static IntPtr HWND_TOP = IntPtr.Zero;
private const int SWP_SHOWWINDOW = 64; // 0×0040
public static int ScreenX
{
get { return GetSystemMetrics(SM_CXSCREEN);}
}
public static int ScreenY
{
get { return GetSystemMetrics(SM_CYSCREEN);}
}
public static void SetWinFullScreen(IntPtr hwnd)
{
SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW);
}
}
In all cases, when the print dialog is launched, the taskbar appears and the user can click it because is it in front of everything.
Is there a way to launch this print dialog in the background or put my form topmost absolutely (without any taskbar or dialog appearing) ?
Edited: The problem is in this line:
DocumentProperties(IntPtr.Zero, IntPtr.Zero, printerSettings.PrinterName, devModeData, pDevMode, 14);
This line launch the print dialog and then taskbar appears (hide or not).