Click here to Skip to main content
15,896,606 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
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 
Chris,

Well, I tried enumerating all the windows and using GetWindowThreadProcessId() and it doesn't seem to give me the same process id as obtained from the SHELLEXECUTEINFO structure (updated by ShellExecuteEx()):

The enumeration callback:

class WININFO
{
public:
	CWnd *hWnd;
	HINSTANCE hInst;
	CString title;
	WININFO(CWnd *wnd = NULL, HINSTANCE inst = NULL) {hWnd = wnd; hInst = inst; title = "";}
};
typedef CArray<WININFO,WININFO> CArrayWinInfo;

BOOL CALLBACK CIOGuidesView::enumwndfn(HWND hWnd, LPARAM lParam)
{
	CIOGuidesView *me = (CIOGuidesView *)lParam;
	return me->enumwndfn(CWnd::FromHandle(hWnd));
}

BOOL CIOGuidesView::enumwndfn(CWnd * wnd)
{
	WININFO wininfo(wnd);

	wnd->GetWindowText(wininfo.title);

	DWORD ProcessId; 
	GetWindowThreadProcessId (wnd->GetSafeHwnd(), &ProcessId ); 
	wininfo.hInst = (HINSTANCE)ProcessId;

	m_WinInfoArray.Add(wininfo);

	return TRUE;
}

The ShellExecuteEx() call:

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;
	}


	int reason = WaitForInputIdle(hProcess,INFINITE);
	// blah, blah


And then I dumped all the windows whose title began with "Acro" OR those whose hInst matched my hProcess:

hProcess=0x01D8  hInst=0x045C  title='Acrobat Reader'

If I understand this, the hProcess and hInst values should have been identical.

Ideas?
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 
GeneralRe: Saving File Formats Pin
Scott H. Settlemier2-Oct-02 9:57
Scott H. Settlemier2-Oct-02 9:57 
GeneralRe: Saving File Formats Pin
SanShou2-Oct-02 10:11
SanShou2-Oct-02 10:11 
GeneralRe: Saving File Formats Pin
Patje2-Oct-02 21:27
Patje2-Oct-02 21:27 

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.