Muhammad Al-Own
Muhammad Al-Own

Reputation: 237

Read MainWindowHandle For Process

i tried to read MainWindowHanlde For Acrobat Reader 10 Process so i can SetParent API i tried this

private Process pDocked;
private IntPtr hWndDocked;
pDocked = Process.Start(path, PDFPath);
while (hWndDocked == IntPtr.Zero)
{
    pDocked.WaitForInputIdle(1000);
    pDocked.Refresh();
    if (pDocked.HasExited)
    {
        return;
    }
    hWndDocked = pDocked.MainWindowHandle;
}

and the result is hWndDocked = 0 even i tried this on acrobat reader 9 and i got the MainWindowHandle but it didn't work on acrobat reader 10

please help And Thanks

Upvotes: 2

Views: 857

Answers (1)

Joseph
Joseph

Reputation: 1774

I had same issue, and find that when the following properties are true,there is no MainWindowHandle, and if the "main form" have child window, then the MainWindowHandle of process will be the child window handle rather than the expected main window. WEIRD!!! wish I can understand why. but once I find this I solve my problem in another way (in my case I not really need the MainWindowHandle)!

When the following:

public frmMain()
        {
            InitializeComponent();
            this.ShowInTaskbar = false;
            this.ShowIcon = false;
        }

No MainWindowHandle (=0)!!

if you create sub window, in this case the MainWindowHandle of the process will be the handle of frmLogon :

private void frmMain_Load(object sender, EventArgs e)
        {
            frmLogon frm = new frmLogon();
            frm.Show();
        }

Close the frmLogon and the MainWindowHandle of the process back to zero (=0)!!

Hope this info is helpful!

Upvotes: 1

Related Questions