Click here to Skip to main content
15,891,863 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
AnswerRe: Sending keystrokes to other *non-focus* application Pin
amatecki4-Aug-09 3:04
professionalamatecki4-Aug-09 3:04 
AnswerRe: Sending keystrokes to other *non-focus* application Pin
Randor 4-Aug-09 3:23
professional Randor 4-Aug-09 3:23 
GeneralRe: Sending keystrokes to other *non-focus* application Pin
audi025-Aug-09 12:12
audi025-Aug-09 12:12 
GeneralRe: Sending keystrokes to other *non-focus* application Pin
Randor 5-Aug-09 15:30
professional Randor 5-Aug-09 15:30 
QuestionTime Priority In LCC win32 Pin
kyai433-Aug-09 21:07
kyai433-Aug-09 21:07 
AnswerRe: Time Priority In LCC win32 [modified] Pin
Adam Roderick J3-Aug-09 22:03
Adam Roderick J3-Aug-09 22:03 
QuestionCome in please, which VC do you like? Pin
includeh103-Aug-09 20:58
includeh103-Aug-09 20:58 
AnswerRe: Come in please, which VC do you like? Pin
Michael Dunn3-Aug-09 21:54
sitebuilderMichael Dunn3-Aug-09 21:54 
GeneralRe: Come in please, which VC do you like? Pin
includeh103-Aug-09 22:01
includeh103-Aug-09 22:01 
AnswerRe: Come in please, which VC do you like? Pin
Adam Roderick J3-Aug-09 22:08
Adam Roderick J3-Aug-09 22:08 
GeneralRe: Come in please, which VC do you like? Pin
Chandrasekharan P3-Aug-09 22:18
Chandrasekharan P3-Aug-09 22:18 
AnswerRe: Come in please, which VC do you like? Pin
«_Superman_»3-Aug-09 22:09
professional«_Superman_»3-Aug-09 22:09 
GeneralRe: Come in please, which VC do you like? Pin
Naveen3-Aug-09 22:18
Naveen3-Aug-09 22:18 
AnswerRe: Come in please, which VC do you like? Pin
Rajesh R Subramanian3-Aug-09 23:01
professionalRajesh R Subramanian3-Aug-09 23:01 

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.