开发者

Can I change the properties of a different running program?

开发者 https://www.devze.com 2023-02-23 12:06 出处:网络
In short im wondering if there is a way to change the display properties of a Windows 开发者_StackOverflow社区form, from a different program.

In short im wondering if there is a way to change the display properties of a Windows 开发者_StackOverflow社区form, from a different program.

For instance, lets say I have two applications running (A and B respectively), Program A has a button that says 'Re-size Program B'. My question is, is there any way when that button is pressed in program A, I can access program B in memory and change its forms Width and Height properties (or any properties for that matter)?

I don't necessarily need source code, (if this is even possible- it would be very much appreciated), mainly I am just curious of such a thing is possible (in any language/IDE)- then I can sink my time into learning how to implement this concept.

My guess- for obvious security reasons, would be no... but its better to ask a dumb question than assume a dumb answer, if you ask me.

Thanks kindly for your time on this issue


Got it for the Window Size, how about for properties like 'TopMost'?

Thanks again,


Simply wonderful thank you all for your great help!


You can resize other programs' windows by sending system messages into them. It is done by WinAPI function

LRESULT WINAPI SendMessage(
  __in  HWND hWnd,
  __in  UINT Msg,
  __in  WPARAM wParam,
  __in  LPARAM lParam
);

First parameter is a handle of target window. You can get it with other API functions (like FindWindow).

Second is message code - in your case it's WM_SIZE.

The last two parameters are described here http://msdn.microsoft.com/en-us/library/ms632646(v=vs.85).aspx

This is for C++ WinAPI. In .NET you can use P-Invoke to call WinAPI functions. Declarations for P-Invoke can be found at http://www.pinvoke.net/

UPD: There are other functions that fit better for this: SetWindowPos and MoveWindow

This is example for resizing. For other things that you can do, see this MSDN section

http://msdn.microsoft.com/en-us/library/ff468919(v=VS.85).aspx

Most controls inside window (buttons etc..) are windows too. You can get their handles and control them in same way


If the window is already open and your code can find it then it can resize it. For instance, the code to arrange windows when you right-click on an empty area of the taskbar does this.

0

精彩评论

暂无评论...
验证码 换一张
取 消