How to use the windows API to communicate with other applications?
For example, another application has a textbox, I have already set mouse on there using mouse_event, but I don't know how to send a string to it, and display the string on that textbox?
Thank you all!
I have made it by using keybd_event, here is my code:
keybd_event((BYTE)VkKeyScan(lpMsg[i-1]), 0, 0, 0);
keybd_event((BYTE)VkKeyScan(lpMsg[i-1]), 0, KEYEVENTF_KEYUP, 0);
I have another question here, because the window I want to send text to isn't the normal ones, it's an internet form, which content has been downloaded from internet. So I cannot use SetWindowText or something else, but to simulate the keyboard input.
My question is: A form contains many buttons and textboxes and labels and something else. The function EnumChildWindows(hwndGame, EnumChildProc, 0); Will continues until the last child window is enumerated or the callback function returns FALSE. What are Child windows? Are those buttons and textboxes on this form ??
Related
I'm working with 3d party application. Changing a text in Edit control using
SendMessageW(m_edit_handle,WM_SETTEXT,0,str_address);
And it works fine.. It changes visually in the window. But once I click a button (also programmatically) it works as there is a default value but not the one I set with SendMessageW.
Just wondering if after changing the text in Edit window I have to call some other method to force Windows to update the actual value in the field?
Depending on how the target app is coded, you may need to issue an EN_CHANGE notification to the Edit's parent window. Sending WM_SETTEXT will not send that notification, as it is meant to be sent when the user makes changes to the Edit's content, not when code does.
SendMessageW(m_edit_handle, WM_SETTEXT, 0, str_address);
SendMessageW(GetParent(m_edit_handle), WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(m_edit_handle), EN_CHANGE), LPARAM(m_edit_handle));
I have a property sheet with several pages. Most of the pages have one or more edit controls.
Most controls are initialized not from the page dialogs but from the dialog that created the property sheet; some however are initialized in the page dialogs and they behave the same.
Everything starts out fine. One can move between the pages. None of the controls have the input focus.
If one clicks on one of the edit controls in a property sheet page establishing input focus one can modify the control. Again all seems in order.
If one then moves to a different property page, the first edit control in that page gets the input focus AND all the text in that control gets selected! This behavior applies to all the pages except one having an edit control with read only style. After that one can move back to other pages and the initial nothing selected no input focus behavior is restored.
All of the pages handle the PSN_QUERYINITIALFOCUS notification and return zero through the SetWindowLong mechanism.
Is this expected behavior?
And why isn't some control given focus initially?
My primary interest here is to somehow kill the selection. I have tried killing the selection with EM_SETSEL in the PSN_SETACTIVE notification to no avail.
The MSDN says the following under PSN_QUERYINITIALFOCUS "Otherwise, return zero and focus will go to the default control." How do I go about setting a control as default?
I find the the actions described above bizarre! I would still like to know
if they are normal.
why no control receives the focus initially.
I was able to kill the selection by adding code to the property sheet pages to handle the WM_COMMAND/EN_SETFOCUS message for any edit controls. I do not know if other controls
send EN_SETFOCUS messages.
case EN_SETFOCUS:
{
char cn[16];
HWND H = (HWND) lParam;
GetClassName (H, cn, 15);
if (strcmp (cn,"Edit") == 0)
{
SendMessage (H, EM_SETSEL, -1, 0);
}
return true;
}
I presume it would be possible to save any selection in an EN_KILLFOCUS handler and restore it
in the EN_SETFOCUS handler but doing so for an unknown number of controls would be tedious.
Using pure Win32 API, how can I get the handle to the control that currently has the focus? And then how can I determine if it's a Text Box / Rich Text Box?
I'm trying to write a small macro keys program which will allow user to register new hot keys using the RegisterHotKey() function. Everything is working fine except that I don't want to violently call SetWindowText() or SendMessage(hWnd, WM_SETTEXT, 0, TEXT("Something")) without knowing whether the control is a text box or not.
Be noted that I want a handle to the control that currently has the focus, not the whole window the user is working on.
Is there any way to programmatically scroll a single-line edit control in Windows?
For example, if the text in an edit control is too large to display at once, then the default behavior when the edit control gets the focus is to select all text and show the end of the text. I'd like to instead show the beginning of the text (while still leaving all text selected).
Although there's (apparently) no API for scrolling to the beginning and selecting all text, it seems to work to simulate the keystrokes that would do the same:
#ifndef CTRL
#define CTRL(x) (x&037)
#endif
SendMessage(edit_handle, WM_KEYDOWN, VK_HOME, 0);
SendMessage(edit_handle, WM_CHAR, CTRL('A'), 0);
You can either call SetScrollPos or send the WM_VSCROLL/WM_HSCROLL message directly to the window. You can find the full list of scroll functions here.
Description
I'm trying to test application coded in Delphi (VCL components by DevEx) with TestComplete. Application is built without debug info.
I need to scroll TcxTreeList component. The problem is when I set Position property for this component's scrollbars content is not scrolled but scroll bar position changes. I tried a lot of approaches and suppose that WinAPI can help me.
The Question:
How to scroll the scrollbar in external application via WinAPI?
I found PostMessage function, but I do not know how to synthesize WM_SCROLL message...
Scroll one line down (you can see other constants at the page JustBoo mentions);
PostMessage(HWnd, WM_VSCROLL, SB_LINEDOWN, 0)
Scroll to a specific position;
PostMessage(HWnd, WM_VSCROLL, MakeWParam(SB_THUMBPOSITION, 30), 0)
But if you refer to this page on the Devex forums, it is mentioned that
"ScrollBar in the cxTreeList it is another control, not standard windows scrollbar".
So it might not work. In this case you might want to try ScrollWindowEx coupled with setting the position as you already do.
These links should show how to setup the parameters to a PostMessage call for scrolling.
WM_HSCROLL Message
WM_VSCROLL Message