How to topmost???

S

Son Ha

Here my code:


[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int SetWindowPos(IntPtr hwnd, IntPtr
hWndInsertAfter,int x,int y,int cx,int cy,int wFlags);

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int BringWindowToTop(IntPtr hwnd);

public IntPtr HWND_TOPMOST =(IntPtr)(-1);
public IntPtr HWND_NOTOPMOST =(IntPtr)(-2);
public int SWP_NOSIZE = 0x1;

private void miToolsCalc_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "calc.exe";
process.Start();
process.WaitForInputIdle();
BringWindowToTop(process.Handle);
SetWindowPos(process.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE);
}

Calculator displayed but not "topmost" :( Could you help me?


Thanks,
Son
 
J

Jared Parsons [MSFT]

I believe that BringWindowToTop() is expecting a HWND but you're giving it a
handle to the process. You need to get a handle on the main window of the
process and pass that to BringWindowToTop(). You want to change your code
to read

BringWindowToTop(process.MainWindowHandle);


--
Jared Parsons [MSFT]
(e-mail address removed)
This posting is provided "AS IS" with no warranties, and confers no rights.
OR if you wish to include a script sample in your post please add "Use of
included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top