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: Soundgarden is an unknown quantity at this point 
Solved Threads: 0
Soundgarden Soundgarden is offline Offline
Newbie Poster

Send Minmize Window to a Running Process

 
0
  #1
May 3rd, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Send Minmize Window to a Running Process

 
0
  #2
May 4th, 2008
Why not just use its handle ?
[code]
string pname="notepad";

foreach (Process theprocess in Myprocess)
{
if (theprocess.ProcessName == pname)
{
postmessage( theprocess.Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0);
break;
}
}

// Jerry
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 17
Reputation: Soundgarden is an unknown quantity at this point 
Solved Threads: 0
Soundgarden Soundgarden is offline Offline
Newbie Poster

Re: Send Minmize Window to a Running Process

 
0
  #3
May 4th, 2008
[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...?
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Send Minmize Window to a Running Process

 
0
  #4
May 4th, 2008
Well, you can see what happens when you turn the int into a hex.

  1. int x = 123;
  2. string hex = "0x" + x.ToString("X");
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 17
Reputation: Soundgarden is an unknown quantity at this point 
Solved Threads: 0
Soundgarden Soundgarden is offline Offline
Newbie Poster

Re: Send Minmize Window to a Running Process

 
0
  #5
May 4th, 2008
Originally Posted by JerryShaw View Post
Well, you can see what happens when you turn the int into a hex.

  1. int x = 123;
  2. string hex = "0x" + x.ToString("X");
Thankyou so much for replying...I didn't have much faith in the old forums run for help scenario...

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
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 45
Reputation: _r0ckbaer is an unknown quantity at this point 
Solved Threads: 7
_r0ckbaer's Avatar
_r0ckbaer _r0ckbaer is offline Offline
Light Poster

Re: Send Minmize Window to a Running Process

 
0
  #6
May 4th, 2008
Yes, because you must use the window handle of the Application:
  1. theprocess.MainWindowHandle
use that one...
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 17
Reputation: Soundgarden is an unknown quantity at this point 
Solved Threads: 0
Soundgarden Soundgarden is offline Offline
Newbie Poster

Re: Send Minmize Window to a Running Process

 
0
  #7
May 4th, 2008
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....
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC