ウィンドウをすべての前面に絶対に配置する質問がありますが、印刷ダイアログを起動すると、ウィンドウを前面に保持する方法が見つかりません。TopMost を実行している印刷ダイアログの上にウィンドウを保持する必要がありますが、タスクバーが表示されます隠されていますが。
それを最大化して全体的に配置するための私のフォームウィンドウのコード:
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);
}
}
「this.TopMost = true;」の後にフォームで SetWinFullScreen を呼び出すこのコードも試しました。フォームを最大化しますが、どちらも機能しません:
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);
この行は印刷ダイアログを起動し、タスクバーが表示されます (非表示または非表示)。