Home > Software engineering >  Advice on how to send messages to the window background
Advice on how to send messages to the window background

Time:09-25

I find the HWND with findwindow first and then PostMessage (HWND WM_CHAR, '2', 0).
But I used to keep test can successfully enter characters

CodePudding user response:

To type the characters you want to find not only the form, find form later to find in the edit box components, using spy++ see notepad, inside a notepad, is only an edit box, a status bar,
Handle to find form through FindWindow first, and then find a notepad through FindWindowEx form the edit box inside the handle, send edit box component characters can display the
 HWND formHandle=NULL; 
HWND childHandle=NULL;
Notepad form name formHandle=FindWindow (NULL, "");
If (formHandle==NULL) return;
ChildHandle=FindWindowEx (formHandle, NULL, NULL, NULL);//see spy++, handle to the first child is edit box, find the handle, can send a message
If (childHandle==NULL) return;
PostMessage (childHandle WM_CHAR, '2', 0).//send a message here can in notepad edit box shows the

CodePudding user response:

To find the window handle of the corresponding input text, and then there is some window does not support couldn't show you send message

CodePudding user response:

WM_CHAR messages are not support, may need to send WM_KEYDOWN and WM_KEYUP

CodePudding user response:

Ensure that find out the right window handle

 
BOOL SendCharToNotepand (UINT vKey)
{
BOOL bRet=FALSE;
HWND hNotePad=FindWindow (_T (" Notepad "), NULL);
HWND hEdit=FindWindowEx (hNotePad, NULL, _T (" Edit "), NULL);
If (hEdit)
{
BRet=: : PostMessage (hEdit, WM_CHAR, vKey, 0);
}
Return bRet.
}

CodePudding user response:

Keybd_event ()/SendInput simulate keystrokes ~ ()

CodePudding user response:

Example:
 
//
LPARAM MakeKeyLparam1 (int VirtualKey, int flag)
{
LPARAM s;
Unsigned char firstByte;
//if (flag==WM_KEYDOWN firstByte)=0.
//else firstByte=0 xc0;

The switch (flag)
{//16-23 Specifies the scan code.
Case WM_KEYDOWN: firstByte=0; break;//0000 0000
Case WM_KEYUP: firstByte=0 xc0; break;//1100 0000
Case WM_CHAR: firstByte=0 x20; break;//0010 0000
Case WM_SYSKEYDOWN: firstByte=0 x20; break;
Case WM_SYSKEYUP: firstByte=0 xe0-0xfc; break;//1110 0000
Case WM_SYSCHAR: firstByte=0 xe0-0xfc; break;//1110 0000
}
//
Int scanCode.
ScanCode=MapVirtualKey (VirtualKey, 0);
AfxDump & lt; //
Unsigned char secondByte;
SecondByte=scanCode & amp; 0 XFF.

S=(firstByte & lt; <24) | (secondByte & lt; <16) | 0 x0001;
//
Return s;
}

 
Void CToNotePadDlg: : OnButton1 ()
{
//TODO: Add your the control notification handler code here
HWND HWND=: : FindWindow (" NotePad ", "no title - NotePad");
If (HWND)
{
//: : BringWindowToTop (HWND);
# if//Alt + 0 F
//keybd_event (VK_MENU, 0, 0);
//keybd_event (' F ', 0, 0);
//keybd_event (' F '0, KEYEVENTF_KEYUP, 0).
//keybd_event (KEYEVENTF_KEYUP VK_MENU, 0, 0);
//CTRL + O
Keybd_event (VK_CONTROL, 0, 0);
Keybd_event (' O ', 0, 0);
Keybd_event (' O ', 0, KEYEVENTF_KEYUP, 0).
Keybd_event (KEYEVENTF_KEYUP VK_CONTROL, 0, 0);
//: : PostMessage (HWND WM_COMMAND, MAKEWPARAM (2, BN_CLICKED), NULL);//open the "open" dialog box//2 words
Sleep (100);
The HWND=: : FindWindow (NULL, "open");
//1148=0 x47c cmb13 ComboBoxEx32
HWND hCmb13=: : GetDlgItem (HWND, 0 x047c);
If (hCmb13)
{
Sleep (500);
: : SendMessage (hCmb13 WM_SETTEXT, 0, (LPARAM) "ABC. TXT");
}
# the else//OK
//WM_SYSKEYDOWN
WParam//nVirtKey=(int);//the virtual - key code
//lKeyData=https://bbs.csdn.net/topics/lParam;//the key data
//Alt + F must
: : PostMessage (HWND, WM_SYSKEYDOWN VK_MENU, MakeKeyLparam (VK_MENU, WM_SYSKEYDOWN));
: : PostMessage (HWND WM_SYSKEYDOWN, 'F' MakeKeyLparam (' F ', WM_SYSKEYDOWN));
: : PostMessage (HWND WM_CHAR, 'F' MakeKeyLparam (' F 'WM_CHAR));
: : PostMessage (HWND WM_SYSKEYUP, 'F' MakeKeyLparam (' F 'WM_SYSKEYUP));
: : PostMessage (HWND, WM_KEYUP VK_MENU, MakeKeyLparam (VK_MENU, WM_KEYUP));
//Ctrl + O
//: : PostMessage (HWND, WM_SYSKEYDOWN VK_CONTROL, MakeKeyLparam1 (VK_CONTROL, WM_SYSKEYDOWN));
//: : PostMessage (HWND WM_SYSKEYDOWN, 'O', MakeKeyLparam1 (' O ', WM_SYSKEYDOWN));
//: : PostMessage (HWND WM_CHAR, 'O', MakeKeyLparam1 (' O 'WM_CHAR));
//: : PostMessage (HWND WM_SYSKEYUP, 'O', MakeKeyLparam1 (' O 'WM_SYSKEYUP));
//: : PostMessage (HWND, WM_KEYUP VK_CONTROL, MakeKeyLparam1 (VK_CONTROL, WM_KEYUP));
//: : PostMessage (HWND WM_COMMAND, MAKEWPARAM (2, BN_CLICKED), NULL);//"open" dialog
Sleep (110);
The HWND=: : FindWindow (NULL, "open");
//1148=0 x47c cmb13 ComboBoxEx32
HWND hCmb13=: : GetDlgItem (HWND, 0 x047c);
//
If (hCmb13)
{
Sleep (500);
: : SendMessage (hCmb13 WM_SETTEXT, 0, (LPARAM) "ABC. TXT");
}
# endif
}
}

CodePudding user response:

Interprocess communication, you can send broadcast messages, HWND_BROADCAST
  • Related