我有一个问题把我的窗口放在所有的绝对前面,但是当我启动一个打印对话框时,我无法找到将前面的窗口保持在前面:我必须将窗口放在打印对话框上做TopMost,但是任务栏出现虽然是隐藏的。Windows窗体最大化总体上绝对
在我的表格窗口中的代码,将其最大化,并把它整体:
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.TopMost = true;
是启动打印对话框中的代码:
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);
这里的代码,我隐藏任务栏:
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);
}
}
我试过这段代码,在我的表单中调用SetWinFullScreen之后,“this.TopMost = true;”最大限度的形式,但它不工作之一:
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);
}
}
在所有情况下,当打开打印对话框,任务栏上出现,用户可以点击它,因为它是眼前的一切。
有没有办法在后台启动这个打印对话框或将我的表单绝对放在最上面(没有任何任务栏或对话框出现)?
编辑:问题是在这条线:
DocumentProperties(IntPtr.Zero, IntPtr.Zero, printerSettings.PrinterName, devModeData, pDevMode, 14);
该行推出的打印对话框,然后出现任务栏(隐藏或不)。
从雷蒙德陈在这里的页面,但是,你有没有考虑过如果两个程序试图同时这样做会发生什么? – asawyer 2012-08-10 13:27:02
您是否正在编写自助服务终端应用程序? – Jodrell 2012-08-10 13:29:37
@asawyer仅供参考:http://blogs.msdn.com/b/oldnewthing/archive/2005/06/07/426294.aspx – rene 2012-08-10 13:32:58