Hi,
I created button window on common dialog using API "CreateWindowEx" , it is created successfully.
PageSetupDialog object created and called ShowDialog() function.
from other thread I call method which is creating button window using following syntax.
I used following syntax:
IntPtr childwind = CreateWindowEx(WindowStylesEx.WS_EX_LEFT, "BUTTON", "Print",
WindowStyles.WS_VISIBLE | WindowStyles.WS_CHILD,
0, 0, width, height, hwnd, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
I checked using GetChildwindow and window count is increase by one , but button window is not displayed on dialog.
I am missing any important step ? Please let me know solution for same.
Additional Info:
when I use same syntax and add window to Form , it is working fine.
Edit: Code from answer moved here
Hi SAKryukov,
I am sharing my code with you.
public partial class Form1 : Form
{
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string strClassName, string strWindowName);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr CreateWindowEx(
WindowStylesEx dwExStyle,
string lpClassName,
string lpWindowName,
WindowStyles dwStyle,
int x,
int y,
int nWidth,
int nHeight,
IntPtr hWndParent,
IntPtr hMenu,
IntPtr hInstance,
IntPtr lpParam);
[DllImport("user32.dll", SetLastError = true)]
static extern int ShowWindow(IntPtr Hwnd, int iCmdShow);
[DllImport("user32.dll", SetLastError = true)]
static extern bool UpdateWindow(IntPtr hWnd);
Thread mythread;
PageSetupDialog dlg;
public Form1()
{
InitializeComponent();
dlg = new PageSetupDialog();
}
private void button1_Click(object sender, EventArgs e)
{
dlg.Document = new System.Drawing.Printing.PrintDocument();
mythread = new Thread(new ThreadStart(TestMethod));
mythread.Start();
dlg.ShowDialog();
}
void TestMethod()
{
IntPtr hWndPageSetup = FindWindow(null, dlg.ToString());
Boolean finPageSetupHandle = false;
while (!finPageSetupHandle && hWndPageSetup == IntPtr.Zero)
{
System.Threading.Thread.Sleep(500);
hWndPageSetup = FindWindow(null, "Page Setup");
finPageSetupHandle = true;
}
IntPtr childwind = CreateWindowEx(WindowStylesEx.WS_EX_LEFT, "BUTTON", "Print",
WindowStyles.WS_VISIBLE | WindowStyles.WS_CHILD,
0, 0, 50, 50, hWndPageSetup, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
ShowWindow(childwind, 1);
UpdateWindow(childwind);
}
}