i wan to active start button in other app, i use spy ++ to check the button styles, i c bs_pushbutton. i try to use win api to do it.i tried WM_SETFOCUS and enter key to do it, but fail
these is my code
Dim hwnd As Int32 = apiFindWindowEx(HWND_DESKTOP, 0, Nothing, "Open File - Security Warning")
Dim cwnd As Int32 = apiFindWindowEx(hwnd, 0, Nothing, "&Run")
Dim i As Integer = SendMessage(cwnd, BS_PUSHBUTTON, 0, 0)
i declare BS_PUSHBUTTON = &H1&
it is correct value for BS_PUSHBUTTON ???
how can i run the app button event??
It's unclear exactly what you're asking for in this question. I'm not sure whether you're attempting to enable a button or emulate a click to it.
Anyway, for the former you simply need to use EnableWindow():
EnableWindow( cwnd, true );
Or alternatively:
Button_Enable( cwnd, true );
For the latter you can use SetActiveWindow() and BM_CLICK:
SetActiveWindow( hwnd );
SendMessage( cwnd, BM_CLICK, 0, 0 );
Related
i will make it simple, i need to silenty (without download dialog pop up) download a file from a website through webbrowser in vb.net, i cant download using WebClient, because i have to be login in first, neither httprequest will work even login in with it first, because first it have google captcha for login, 2nd i dont want automate the login stuff ..
i have tried api stuff:
Dim hwnd = FindWindow(vbNullString, "File Download")
If hwnd <> IntPtr.Zero Then ' dialog window found
'MsgBox("yes")
' find button on dialog window: classname = "Button", text = "OK"
Dim btn = FindWindowEx(hwnd, IntPtr.Zero, "Button", "&Save")
'Dim sd = FindWindowEx(hwnd, IntPtr.Zero, )
If btn <> IntPtr.Zero Then ' button found
' activate the button on dialog first or it may not acknowledge a click msg on first try
SendMessage(btn, WM_ACTIVATE, WA_ACTIVE, 0)
' send button a click message
SendMessage(btn, BM_CLICK, 0, 0)
Else
MsgBox("button not found!")
End If
End If
so the far, it gets the windwo, also the button found, but it wont press/click on it, its like there nothing happens ..(plus: dont incourage me for sendkeys stuff, i want it silenty)
using IE: 11
Any chances that i download using httprequest by transfering the cookie (or whatver) from webbroser to http ? any workaround, please do let me know.
In an external application, there are 8 buttons with any text and all with the same class.
How can i get the exact button that i want?
With FindWindowEx, is it possible to insert an hexadecimal value (taken from spy++) instead of a string?
Dim h1 = FindWindow(Nothing, "TitleWindow")
Dim h2 = FindWindowEx(h1, Nothing, Nothing, "TextButton")
SendMessage(h2, BM_CLICK, 0, 0)
I'm trying to change the solid desktop background color, and i'm using a RegistryKey to do that like so :
Dim CD As New ColorDialog
If CD.ShowDialog = DialogResult.OK Then
Dim RK As RegistryKey = Registry.CurrentUser.OpenSubKey("Control Panel\Colors", True)
RK.SetValue("Background", CD.Color.R & " " & CD.Color.G & " " & CD.Color.B)
End If
I'v seen this question, but it didn't help in my case.
The code above is working because the value in the registry editor is changing, but the background color is not, if i edited the color from the control panel, it will change the same value in the registry editor and the background color will change, anyone have explaining for that, or is there any other way to do it?
I finally got it to work, it can't be done by only editing the registry key, in fact you need to use the user32.dll API to do so, and you can use the registry key to get the value of the color only, but not to set it, thanks to Steve (↑).
Here is what worked for me :
First > Declare this function to use the API :
Private Declare Function SetSysColors Lib "user32.dll" (ByVal one As Integer, ByRef element As Integer, ByRef color As Integer) As Boolean
Second > Use this to call the function and change the color :
Dim CD As New ColorDialog
If CD.ShowDialog = DialogResult.OK Then
Dim BackgroundColor As Integer = ColorTranslator.ToWin32(CD.Color)
SetSysColors(1, 1, BackgroundColor)
End If
Hope that was useful to someone :)
ive seen other questions about this issue but none of them resolved it for me so here i go. I'm trying to send a keypress to a game to save the progress(its a 64bit game). what i've coded so far is :
Dim p() As Process
Dim GameID As Integer = 0
Dim p As Process() = Process.GetProcessesByName("Gamename")
If p.Length > 0 Then
For i As Integer = 0 To p.Length - 1
GameID = (p(i).Id)
Next
End If
AutoSaveTimer.Enabled = True
Dim Test As Integer = 0
GetAsyncKeyState(Test)
AppActivate("GameName")
My.Computer.Keyboard.SendKeys(";", True)
now i've tried Sendkeys.Send(";") but without luck, and the game runs under "GameName" but then the keypress needs to be sent in a window under the game :
Blacked out is the game and under the first window is where the keypress needs to be sent
thanks in advance for the help
I use InputSimulator in my app and it works great.
https://inputsimulator.codeplex.com/
It could be this easy to send keys. The active window will see that as if the user actually used those keys.
var sim = new InputSimulator();
sim.Keyboard.KeyPress(VirtualKeyCode.SPACE);
sim = null;
Here's a screen shot of the methods you can use for keyboard.
You can simulate keyboard input to a program like this:
<DllImport("user32.dll")> _
Public Shared Function SetForegroundWindow(hWnd As IntPtr) As Boolean
End Function
Public Sub Send()
Dim p As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("notepad")
'search for process notepad
If p.Length > 0 Then
'check if window was found
'bring notepad to foreground
SetForegroundWindow(p(0).MainWindowHandle)
End If
SendKeys.SendWait("a")
'send key "a" to notepad
End Sub
I am novice of VB.Net trying to create a plugin for a program with a fairly lacking API. Essentially what I am trying to accomplish is press a button in the interface, which will create a new window. Once this window loads, I have a couple other buttons to press to eventually print out an HTML file it generates.
I attempted to use Windows UI Automation, but was unable to manipulate the first control (it appeared as a "pane" element for some reason, and had no supported control patterns)
I eventually was able to use PostMessage to send a MouseDown and MouseUp message to the control to activate it.
My question is: What is the best way for me to wait for this window to finish loading before continuing my code execution?
I tried using Thread.Sleep after I sent the click to my control, but my code seemed to trigger the sleep before it even started to load the window. I suspect there may be some kind of event-driven options, but I don't even know where I would begin with that.
Side note: I do have access to the program's Process ID if that helps.
EDIT:
To be more explicit about what I have done, here is some code for you to look at:
' These variables declared further up in my program, when plugin is loaded
Private aeDesktop As AutomationElement
Private aeRadan As AutomationElement
Private aeBlocksBtn As AutomationElement
Private Sub UITest1()
Dim rpid As Integer
Dim intret As Integer
' Note: mApp is declared further up in the code, when the plug in initializes
' It sets a reference to the application object (API command from the software)
rpid = mApp.ProcessID
aeDesktop = AutomationElement.RootElement
Dim propcon As New PropertyCondition(AutomationElement.ProcessIdProperty, rpid)
Dim propcon2 As New PropertyCondition(AutomationElement.NameProperty, "big_button_blocks.bmp")
aeRadan = aeDesktop.FindFirst(TreeScope.Children, propcon)
aeBlocksBtn = aeRadan.FindFirst(TreeScope.Descendants, propcon2)
' MAKELONG is a function that concatenates given x and y coordinates into an appropriate "lparam" value for PostMessage.
' Coordinates 20, 20 are chosen arbitrarily
Dim lParam As Long = MAKELONG(20, 20)
intret = PostMessage(CInt(aeBlocksBtn.GetCurrentPropertyValue(AutomationElement.NativeWindowHandleProperty)), &H201, &H1, lParam)
intret = PostMessage(CInt(aeBlocksBtn.GetCurrentPropertyValue(AutomationElement.NativeWindowHandleProperty)), &H202, &H0, lParam)
Dim bwinprop As New PropertyCondition(AutomationElement.NameProperty, "Radan Block Editor")
Dim aeblockwin As AutomationElement
Dim numwaits As Integer = 0
Do
numwaits += 1
Thread.Sleep(100)
aeblockwin = aeRadan.FindFirst(TreeScope.Children, bwinprop)
Loop While (numwaits < 50) AndAlso (aeblockwin Is Nothing)
If numwaits >= 50 Then
MessageBox.Show("ERROR: Block Editor Window Not found")
End If
I am fairly sure what is happening has to do with the code moving to the Do While loop before the PostMessage is processed by the program. I have tried using SendMessage to try to bypass this, but unfortunately that does not seem to work.
I feel like there is a pretty simple solution here, like maybe some kind of alternate wait or sleep command that I don't know about, so maybe someone could help guide me to it?
EDIT 2:
Screenshot of the inspect.exe output for this control.
Also, a screenshot of the user interface. This is from Radan, a CAM software I use for nesting and processing sheet metal parts to be laser cut. I put a red box around the control I would like to activate.