Click here to Skip to main content
15,897,226 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralCatch image bar under the mouse Pin
progman2-Oct-02 6:59
progman2-Oct-02 6:59 
Generalmakeing VC project with MINGW Pin
sagmam2-Oct-02 6:49
sagmam2-Oct-02 6:49 
GeneralRe: makeing VC project with MINGW Pin
Mike Eriksson2-Oct-02 21:18
Mike Eriksson2-Oct-02 21:18 
GeneralSTL queue Pin
JohnnyG2-Oct-02 6:32
JohnnyG2-Oct-02 6:32 
GeneralRe: STL queue Pin
TyMatthews2-Oct-02 9:04
TyMatthews2-Oct-02 9:04 
GeneralRe: STL queue Pin
JohnnyG2-Oct-02 10:16
JohnnyG2-Oct-02 10:16 
GeneralRe: STL queue Pin
TyMatthews2-Oct-02 10:34
TyMatthews2-Oct-02 10:34 
GeneralGetting an HWND from an HINSTANCE Pin
Harold Bamford2-Oct-02 6:21
Harold Bamford2-Oct-02 6:21 
Greetings,

I need to get an HWND but all I have is an HINSTANCE. There must be some simple way to make the conversion but my brain is blocked. This can't be that difficult! Cry | :((

What I am doing is using ShellExecuteEx() to open up a PDF file. I then want to send keyboard messages to this new process to make it go to Page XXX.

(Yes, I know that if I had the full Acrobat I could do this with OLE or even DDE. But I don't. And the alleged pdf ActiveX control is only intended to work within a browser. Sigh...)

I need to be able to take the hProcess field from the SHELLEXECUTEINFO, as filled in by ShellExecuteEx(), and use it to wait for the new process to stabilize and then send the appropriate WM_KEYDOWN and WM_CHAR messages.

Failing that, I would like to be able to enumerate all the windows and find the one corresponding to the one I spawned. I am looking for a general solution rather than looking for a window containing "Acrobat Reader" in its title bar.

Can anybody give me a clue?

Thanks a lot!

void CIOGuidesView::OnButton1() 
{
	CString filename("PDF Files\\751018a.pdf");

	HANDLE hProcess = NULL;
	SHELLEXECUTEINFO shellInfo;
	::ZeroMemory(&shellInfo, sizeof(shellInfo));
	shellInfo.cbSize = sizeof(shellInfo);
	shellInfo.lpVerb = "open";
	shellInfo.lpFile = filename;
	shellInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
	if(::ShellExecuteEx(&shellInfo))
	{ /* success */
		hProcess = shellInfo.hProcess;
	} /* success */
	else
	{
		ShowLastError("ShellExecuteEx Failed");
		return;
	}

	// I'm not convinced this is actually working. I think that it may
	// actually be interfering with AcroRd32
	int reason = WaitForInputIdle(hProcess,INFINITE);

	switch(reason)
	{
	case 0:
		MessageBox("subprocess now accepting user input");
		break;
	case WAIT_TIMEOUT:
		MessageBox("Wait timeout");
		break;
	case 0xFFFFFFFF:
		ShowLastError("WaitForInputIdle Failure");
		break;
	}

	// This doesn't seem to work. It gets random text from current process
	// rather than new process. And it changes each time I try it!
	char title[1000];
	::GetWindowText((HWND)hProcess,title,sizeof(title));
	MessageBox(title,"Subprocess Window Title");
}

GeneralRe: Getting an HWND from an HINSTANCE Pin
Phil J Pearson2-Oct-02 7:14
Phil J Pearson2-Oct-02 7:14 
GeneralRe: Getting an HWND from an HINSTANCE Pin
Chris Richardson2-Oct-02 9:58
Chris Richardson2-Oct-02 9:58 
GeneralRe: Getting an HWND from an HINSTANCE Pin
Harold Bamford2-Oct-02 11:46
Harold Bamford2-Oct-02 11:46 
GeneralRe: Getting an HWND from an HINSTANCE Pin
Chris Richardson2-Oct-02 11:59
Chris Richardson2-Oct-02 11:59 
GeneralRe: Getting an HWND from an HINSTANCE Pin
Phil J Pearson2-Oct-02 12:10
Phil J Pearson2-Oct-02 12:10 
GeneralRe: Getting an HWND from an HINSTANCE Pin
Chris Richardson2-Oct-02 12:19
Chris Richardson2-Oct-02 12:19 
GeneralRe: Getting an HWND from an HINSTANCE Pin
Harold Bamford2-Oct-02 12:20
Harold Bamford2-Oct-02 12:20 
GeneralRe: Getting an HWND from an HINSTANCE Pin
Chris Richardson2-Oct-02 12:40
Chris Richardson2-Oct-02 12:40 
GeneralRe: Getting an HWND from an HINSTANCE Pin
Harold Bamford2-Oct-02 12:48
Harold Bamford2-Oct-02 12:48 
GeneralRe: Getting an HWND from an HINSTANCE Pin
Chris Richardson2-Oct-02 12:55
Chris Richardson2-Oct-02 12:55 
GeneralRe: Getting an HWND from an HINSTANCE Pin
JT Anderson2-Oct-02 13:07
JT Anderson2-Oct-02 13:07 
GeneralRe: Getting an HWND from an HINSTANCE Pin
Harold Bamford3-Oct-02 7:39
Harold Bamford3-Oct-02 7:39 
GeneralSaving File Formats Pin
SanShou2-Oct-02 6:17
SanShou2-Oct-02 6:17 
GeneralRe: Saving File Formats Pin
JohnnyG2-Oct-02 6:38
JohnnyG2-Oct-02 6:38 
GeneralRe: Saving File Formats Pin
SanShou2-Oct-02 7:10
SanShou2-Oct-02 7:10 
GeneralRe: Saving File Formats Pin
Phil J Pearson2-Oct-02 7:21
Phil J Pearson2-Oct-02 7:21 
GeneralRe: Saving File Formats Pin
Rickard Andersson202-Oct-02 8:28
Rickard Andersson202-Oct-02 8:28 

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.