By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 911 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

How to topmost???

P: n/a
Here my code:
[System.Runtime.InteropServices.DllImport("user32.d ll")]
public static extern int SetWindowPos(IntPtr hwnd, IntPtr
hWndInsertAfter,int x,int y,int cx,int cy,int wFlags);

[System.Runtime.InteropServices.DllImport("user32.d ll")]
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
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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]
ja******@online.microsoft.com
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"
"Son Ha" <so***********@hotmail.com> wrote in message
news:ud*************@TK2MSFTNGP10.phx.gbl...
Here my code:
[System.Runtime.InteropServices.DllImport("user32.d ll")]
public static extern int SetWindowPos(IntPtr hwnd, IntPtr
hWndInsertAfter,int x,int y,int cx,int cy,int wFlags);

[System.Runtime.InteropServices.DllImport("user32.d ll")]
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

Nov 16 '05 #2

P: n/a
Jared Parsons [MSFT] wrote:
BringWindowToTop(process.MainWindowHandle);


Thanks a lot Jared
process.MainWindowHandle did it!

Regars,
Son
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.