Knowledge Base Nr: 00141 sendmsgkeys.cpp - http://www.swe-kaiser.de

Win32: Tastaturevents mit SendMessage() an Fenster schicken

  
CString text = "My string";

CWnd* pWnd = CWnd::FindWindow("My application title",NULL);
if(!pWnd )
{
MessageBox("Application not found");
return;
}

char buffer[500];

sprintf(buffer, "%s\n", text);

for(int i=0; buffer[i] != '\0'; i++)
{
pWnd->SendMessage(WM_KEYDOWN, 69,1);
pWnd->SendMessage(WM_CHAR, buffer[i],1);
pWnd->SendMessage(WM_KEYUP, 69,1);
}

pWnd->SetFocus();
pWnd->SetForegroundWindow();