In short im wondering if there is a way to change the display properties of a Windows 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.
Related
I'm currently in the middle of making a VB.NET project. I want to have the VB.NET project control the actions of the Flash projector. (Stop, play, change text of text control in the Flash projector, etc.) This is a one way control however, nothing about the SWF projector will interact back with the VB.NET project.
The image below shows an idea of what I want to have done.
EDIT: Okay I managed to get a SWF object available to be put in the project. So now, my question is how do I get the two (Visual Studio and the SWF object that is being included in another form windows) to interact. That is, if I push a button on VisualBasic, I can call a function in AS3/SWF to do something and receive a variable from the Visual Basic form.
The AS3 code contains the following
function fl_ClickToGoToWebPage(event:MouseEvent):void
{
lblText.text = "Congrats! It Works!";
}
btnChange.addEventListener(MouseEvent.MOUSE_UP, fl_ClickToGoToWebPage);
Here is a photo of the actual SWF.
What I would like to do is invoke this function (or some similar function) passing info to the SWF projector (being run as an ActiveX Flash object in Visual Studio) from the VB form. (Ignore the button on the actual SWF, that button won't be there on the final run) I'm running into two problems:
1) How do I modify addEventListener so that it can take more than one parameter or is there another event or function I could use?
2) How do I invoke this function from within Visual Studio as a part of a sub or function from within VS/VB.NET?
I don't need it to reciprocate, as in Visual Studio getting information from the SWF.
I just ran a quick test using sendkeys and it worked ok; at the heart of it was:
setting the flashplayer as the foreground window ...
Friend Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd
As IntPtr) As Integer
and then using the sendkeyes command
System.Windows.Forms.SendKeys.SendWait
I would suggest checking out socket connections. They are easy to do with C++ and Flash has built in support for them:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/Socket.html
I am trying to sed a keystroke in vb.net, and my code at the moment is SendKeys.Send("+^(;)")
But unfortunately it won't fire, could anyone tell me why?
I don't recommend using sendkeys for anything really. Reason being that you never can guarantee the keystrokes will go where you intend. This is because you are simulating the input as if it were coming from the keyboard, which also ties up your keyboard.
I suggest instead you take the time and learn about the SendMessage api, or the PostMessage api. With these API's you can send messages to specific windows, regardless of what is going on with the keyboard. For instance, if you write a game bot using sendkeys, then you have to leave your computer alone while it runs and hope no unexpected windows pop open. Whereas if you learn the sendmessage api, then you can write a bot that runs in the background while you do other things with your computer.
here are some links to help:
pinvoke - sendmessage api
pinvoke - postmessage api
A list of windows messages constants/hex values/meanings
A nice description on how to use these api's
I was wondering how to create a sort of auto clicker using VB.NET.
I would basicly have the click coordinates pre-defined and the clicks, which would have to be separated by delays I guess since I want more than one to happen periodically, would happen outside of the application window (I read this envolves extra system hooks?).
The only code I have been able to find is related to clicks on the application window, which is not what I am looking for.
In short: I want to click a button on the app window, which would initiate a number of clicks on certain pre-defined screen coordinates.
Thanks in advance :)
See this discussion on social.msdn: Simulate a mouse click in a program.
Uses winapi: SetCursorPos, GetCursorPos and mouse_event.
I believe you need to P/Invoke into Windows to accomplish this.
Have a look at the SendInput function.
If you are using automate the program,that program have some tabindex in order to relevant control.then you can use;
SendKeys.Send("{TAB}");
SendKeys.Send("{ENTER}");
it is more accurate on desktop application
I used to know vb6 and I need to make a quick application. I hope someone can help me with how to send keys to a minimized window in vb.net
thanks
Normally you can send keys with the SendMessage API function, but I'm not sure if it would be affected in any way by the window being minimized, I don't think so but I haven't tried.
To use a Windows API function from VB.Net you need to use PInvoke to call it, you can find information about how to do that on this page.
The MSDN page for SendMessage might also be useful for information about how it works.
Btw, you probably want to use the WM_CHAR message which is 0x0102.
Use SendKeys
http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx
SendKeys.SendWait()
I am developing a windows service, in VB.NET, that launches a legacy application that performs some work. The service acts as a wrapper around the legacy app allowing users to automate an otherwise manual operation.
Everything is working great, except occasionally the legacy app displays a messagebox. When it does this the process halts until the message box is closed.
As the service will be running on a server there will be no user to close the message box.
The service launches the legacy application in a System.Diagnostics.Process.
Is there way to detect that a message box has been displayed by a process that I have started using System.Diagnostics.Process? And is there a way to close the messagebox through code?
I also found that EnumChildWindows does not return the MessageBox. But I found a site that showed me how to do it. http://vbcity.com/forums/t/105842.aspx
You want to call GetWindow passing in GW_ENABLEDPOPUP. It worked like a charm. Thanks to Scott Waletzko!
Use FindWindow to find the app, the use EnumChildWindows to enumerate all it's childwindows until you find the messagebox (if the messagebox isn't a direct child of the main window of the app you might have to have recursive calls I think).
You might be able to skip the FindWindow call and instead use the MainWindowHandle property of the Process, but I haven't checked if that works.
A good tool for looking at all this is Spy++ which can help you see some information you can get hold of about a running process.