| | |
Send Minmize Window to a Running Process
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: May 2008
Posts: 17
Reputation:
Solved Threads: 0
Howdy all and anyone who cares to read this. I was hoping you could help me with one small issue I am having. OK to cut a long story short...
I need to be able to search through all running process.id and then sendmessage(hwnd, blah,blah, MIN_WINDOW);
In other words I need find notepad by name in the running processes and then get the Handle. Then send message to that handle to minimize the window or Set the Window Position.
Now my problem is that when I get the Handle using:
string pname="notepad";
foreach (Process theprocess in Myprocess)
{
if (theprocess.ProcessName == pname)
{
textBox1.Text = theprocess.Id.ToString();
//_________________________________//
AS you can see that the textbox1.text will show that the handle value(process.id) is an int. Now when I pass it to the showwindows(hwnd.......). It's not the Hexadecimal value so it doesn’t exist...It seem that when it's pulled using the Process[] method it converts it to a short type of Int. Please is there away to collect the Process.Id and the pass it to Handle name as Hex...
int handle = 0x00D7A;
postmessage(handle, WM_SYSCOMMAND, SC_MINIMIZE, 0);
Now this would work if a window with that PID exist...Which It did AS I used WinSpy to get the value for notepad then check it and it worked...but soon as I pass the handle via the above collected method it only pass a short version of the handle. I need to convert it to HEX to pass it. Please can you point me in the right direction...?
Cheers
Sound
I need to be able to search through all running process.id and then sendmessage(hwnd, blah,blah, MIN_WINDOW);
In other words I need find notepad by name in the running processes and then get the Handle. Then send message to that handle to minimize the window or Set the Window Position.
Now my problem is that when I get the Handle using:
string pname="notepad";
foreach (Process theprocess in Myprocess)
{
if (theprocess.ProcessName == pname)
{
textBox1.Text = theprocess.Id.ToString();
//_________________________________//
AS you can see that the textbox1.text will show that the handle value(process.id) is an int. Now when I pass it to the showwindows(hwnd.......). It's not the Hexadecimal value so it doesn’t exist...It seem that when it's pulled using the Process[] method it converts it to a short type of Int. Please is there away to collect the Process.Id and the pass it to Handle name as Hex...
int handle = 0x00D7A;
postmessage(handle, WM_SYSCOMMAND, SC_MINIMIZE, 0);
Now this would work if a window with that PID exist...Which It did AS I used WinSpy to get the value for notepad then check it and it worked...but soon as I pass the handle via the above collected method it only pass a short version of the handle. I need to convert it to HEX to pass it. Please can you point me in the right direction...?
Cheers
Sound
•
•
Join Date: May 2008
Posts: 17
Reputation:
Solved Threads: 0
[QUOTE=
postmessage( theprocess.Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0);
break;
}
}
// Jerry[/QUOTE]
Thanks jerry for your niffty response....but It seems that the value is still being passed as (short or not HEX) it will only pass a int value....
the value (theprocess.Handle) outputs a small in (1140) this is not eh Real HAndle name it should be 003B0510..any idea to convert the theprocess.handle to a hex and passit or add 0x0 value to the start...?
postmessage( theprocess.Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0);
break;
}
}
// Jerry[/QUOTE]
Thanks jerry for your niffty response....but It seems that the value is still being passed as (short or not HEX) it will only pass a int value....
the value (theprocess.Handle) outputs a small in (1140) this is not eh Real HAndle name it should be 003B0510..any idea to convert the theprocess.handle to a hex and passit or add 0x0 value to the start...?
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
Well, you can see what happens when you turn the int into a hex.
C# Syntax (Toggle Plain Text)
int x = 123; string hex = "0x" + x.ToString("X");
•
•
Join Date: May 2008
Posts: 17
Reputation:
Solved Threads: 0
•
•
•
•
Well, you can see what happens when you turn the int into a hex.
C# Syntax (Toggle Plain Text)
int x = 123; string hex = "0x" + x.ToString("X");
Here ther basic Code for what I need....The basic Premiss is that when the prog is run, it checks for given program names as varible in running process list then gets the Handle using this method
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetWindowPos")]
static extern bool SetWindowPos(
int hWnd, // window handle
int hWndInsertAfter, // placement-order handle
int X, // horizontal position
int Y, // vertical position
int cx, // width
int cy, // height
uint uFlags); // window positioning flags
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
int clicked = 0;
string pname = "notepad";
int whandle;
string whandled;
void checkproc(string pname)
{
int SW_SHOWNOACTIVATE = 4;
int HWND_TOPMOST = -1;
uint SWP_NOACTIVATE = 0x0010;
clicked++;
Process[] processlist = Process.GetProcesses();
foreach (Process theprocess in processlist)
{
if (theprocess.ProcessName == pname)
{
// int dothiswin=0x0104A;
ShowWindow(theprocess.Handle, SW_SHOWNOACTIVATE);
MessageBox.Show(theprocess.Handle.ToString());
SetWindowPos(theprocess.Handle.ToInt32(), HWND_TOPMOST, 100, 100, 100, 100, SWP_NOACTIVATE);
break;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = whandle.ToString();
checkproc(pname);
}
this is a quick idea of what i want to happen but setWindowPos(THEPROCESS.HANDLE..... is the problem.....Any Idea....Thanks for your time......BTW
Yes, because you must use the window handle of the Application:
use that one...
C# Syntax (Toggle Plain Text)
theprocess.MainWindowHandle
•
•
Join Date: May 2008
Posts: 17
Reputation:
Solved Threads: 0
Jerry thankvery much for spending the time to try and work this crap out...I really do appreciate it....Hope to do business again...lol..
_r0ckbaer - THANKS - THANKS SO MUCH FOR typing such a quick response and solving it in one statement I can't believe i spent a whole day trying everything including writing about 10 differnt version...and never even noticed the MainWindowHandle.....ARGGGG...IS all can Say....But ONCE Karma +10 to all.. and R
BTW R0ckbaer Nice Tounge...You could rest a Beer can on that handy....
_r0ckbaer - THANKS - THANKS SO MUCH FOR typing such a quick response and solving it in one statement I can't believe i spent a whole day trying everything including writing about 10 differnt version...and never even noticed the MainWindowHandle.....ARGGGG...IS all can Say....But ONCE Karma +10 to all.. and R
BTW R0ckbaer Nice Tounge...You could rest a Beer can on that handy....
![]() |
Other Threads in the C# Forum
- Previous Thread: OpenGL Exception Problem
- Next Thread: Get Program Install Directory
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array bitmap box broadcast buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation visualstudio webbrowser windows winforms wpf xml





