如何使PrintDialog最顶端
本文关键字:PrintDialog 何使 | 更新日期: 2023-09-27 18:08:52
我已经创建了一个exe,并将在新线程中提示打印对话框。当用户点击另一个应用程序中的按钮时,此exe将运行。我如何使打印对话框顶部最多或不允许用户切换回调用者,直到打印对话框被关闭?谢谢。
Thread t = new Thread(() =>
{
System.Windows.Controls.PrintDialog pDialog = new System.Windows.Controls.PrintDialog();
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;
Nullable<Boolean> print = pDialog.ShowDialog();
if (print == true)
{
}
});
t.SetApartmentState(ApartmentState.STA);
t.Start();
`[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetWindowPos(IntPtr hWnd,
int hWndInsertAfter, int x, int y, int cx, int cy, int uFlags);
private const int HWND_TOPMOST = -1;
private const int HWND_NOTOPMOST = -2;
private const int SWP_NOMOVE = 0x0002;
private const int SWP_NOSIZE = 0x0001;
private const int SWP_SHOWWINDOW = 0x0040;
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle);
private bool TweakPrintDialog()
{
IntPtr result = IntPtr.Zero;
IntPtr printDialogHandle = FindWindowEx(<Insert here Current WindowHandler>, result, "#32770", null);
if (printDialogHandle != IntPtr.Zero)
{
SetWindowPos(printDialogHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
return false;
}
return true;
}
'使用:
Dispatcher.BeginInvoke(new Action(() =>
{
do
{
Thread.Sleep(100);
} while (TweakPrintDialog());
}));
if (printDialog.ShowDialog() == true)
{