Click here to Skip to main content
15,909,829 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Heavy Duty Client/Server Application Pin
Randor 4-Aug-09 19:07
professional Randor 4-Aug-09 19:07 
Questionoutlook in plain C++ Pin
Fuad Abu Sameer4-Aug-09 3:04
Fuad Abu Sameer4-Aug-09 3:04 
AnswerRe: outlook in plain C++ Pin
David Crow4-Aug-09 5:39
David Crow4-Aug-09 5:39 
QuestionAutomating application for multiple version of word Pin
gadag4-Aug-09 2:58
gadag4-Aug-09 2:58 
Questionassignment operator Pin
p_19604-Aug-09 2:41
p_19604-Aug-09 2:41 
AnswerRe: assignment operator Pin
Cedric Moonen4-Aug-09 2:45
Cedric Moonen4-Aug-09 2:45 
AnswerRe: assignment operator Pin
CPallini4-Aug-09 3:00
mveCPallini4-Aug-09 3:00 
Questionmemory could not be written Pin
caobo9224-Aug-09 1:33
caobo9224-Aug-09 1:33 
AnswerRe: memory could not be written Pin
Adam Roderick J4-Aug-09 1:49
Adam Roderick J4-Aug-09 1:49 
GeneralRe: memory could not be written Pin
caobo9224-Aug-09 2:49
caobo9224-Aug-09 2:49 
QuestionWhat is command routing in VC++ ? Pin
rajajay824-Aug-09 0:08
rajajay824-Aug-09 0:08 
AnswerRe: What is command routing in VC++ ? Pin
_AnsHUMAN_ 4-Aug-09 1:18
_AnsHUMAN_ 4-Aug-09 1:18 
Questionhow to images from a group in MFC Pin
rajapp4-Aug-09 0:08
rajapp4-Aug-09 0:08 
AnswerRe: how to images from a group in MFC [modified] Pin
Adam Roderick J4-Aug-09 0:17
Adam Roderick J4-Aug-09 0:17 
QuestionSize of Dialog at run time Pin
002comp4-Aug-09 0:05
002comp4-Aug-09 0:05 
AnswerRe: Size of Dialog at run time Pin
Adam Roderick J4-Aug-09 0:12
Adam Roderick J4-Aug-09 0:12 
GeneralRe: Size of Dialog at run time Pin
002comp4-Aug-09 0:30
002comp4-Aug-09 0:30 
GeneralRe: Size of Dialog at run time Pin
Adam Roderick J4-Aug-09 0:48
Adam Roderick J4-Aug-09 0:48 
GeneralRe: Size of Dialog at run time Pin
002comp4-Aug-09 1:13
002comp4-Aug-09 1:13 
GeneralRe: Size of Dialog at run time Pin
Cedric Moonen4-Aug-09 0:59
Cedric Moonen4-Aug-09 0:59 
QuestionIWMPPlayer in WMP plugin Pin
da-kak-tak3-Aug-09 23:25
da-kak-tak3-Aug-09 23:25 
QuestionSending keystrokes to other *non-focus* application Pin
audi023-Aug-09 23:00
audi023-Aug-09 23:00 
In order to send keystorkes or mouse clicks to other application that is not in focus, I found
in the internet the concept of using SendInput while attaching my application thread to the application I want to control. Here is the short console program code for writing the letter 'g' on the notepad program.
But still problem - it doesn't put the letter on the notepad... why?

#include "stdafx.h"
#include "conio.h"
#include "windows.h"

void sendKey(WORD wVk)
{
	INPUT input[2];

	input[0].ki.wVk = wVk;
	input[0].ki.wScan = 0;
	input[0].ki.dwFlags = 0; //press down;
	input[0].ki.time = 0;
	input[0].ki.dwExtraInfo = 0;
	input[0].type = INPUT_KEYBOARD;

	input[1].ki.wVk = wVk;
	input[1].ki.wScan = 0;
	input[1].ki.dwFlags = KEYEVENTF_KEYUP;
	input[1].ki.time = 0;
	input[1].ki.dwExtraInfo = 0;
	input[1].type = INPUT_KEYBOARD;

	SendInput(2, input, sizeof(INPUT));
}

int _tmain(int argc, _TCHAR* argv[])
{
	TCHAR	sText[1024];
	HWND	hTargetWnd;
	DWORD   processID;
	DWORD	threadID;
	
	
	HWND hNotepadWnd = FindWindow(NULL,  L"Untitled - Notepad");
    hTargetWnd=FindWindowEx(hNotepadWnd,NULL,L"Edit",NULL);
	threadID = GetWindowThreadProcessId(hTargetWnd , &processID);	
	if(hTargetWnd)
	{
		wsprintf(sText, L"Target window found\nWindow = %p\nprocessID = %x\nThreadID = %x\n",hTargetWnd,processID,threadID);
		wprintf(L"%s",sText);
		
			  if(AttachThreadInput( GetCurrentThreadId(), threadID,true))
			  {
				sendKey('G');
				AttachThreadInput(GetCurrentThreadId(),threadID,   false);
			  }
	}
	else
	{
		wprintf(L"Window Notepad wasn't found\n");
	}

	// if there was SendInput, it also should be seen here
	while(_kbhit())
	{
		wprintf(L"%c",getch());
	}

	// wait for keystroke to exit
	while(!_kbhit());

	return 0;
}

AnswerRe: Sending keystrokes to other *non-focus* application Pin
Adam Roderick J3-Aug-09 23:45
Adam Roderick J3-Aug-09 23:45 
QuestionRe: Sending keystrokes to other *non-focus* application Pin
David Crow4-Aug-09 2:57
David Crow4-Aug-09 2:57 
AnswerRe: Sending keystrokes to other *non-focus* application Pin
audi025-Aug-09 12:06
audi025-Aug-09 12:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.