-
May 11th, 2010, 03:11 PM
#1
CreateProcess() Q
I had Launched a Internet Explorer from CreateProcess() ,I want to know how to get HWND of the Internet explorer from PROCESS_INFORMATION structure . tried EnumWindowProc but i am bumb Didn't get anything it gives me handle of Addressbar etc and i want IFrame handle .
Thanks
-
May 11th, 2010, 04:12 PM
#2
Re: CreateProcess() Q
I already answered you this question in your previous thread (my reply)
Did you read it?
Did you try? What was a problem you get while trying it?
Victor Nijegorodov
-
May 11th, 2010, 07:54 PM
#3
Re: CreateProcess() Q
Originally Posted by VictorN
I already answered you this question in your previous thread ( my reply)
Did you read it?
Did you try? What was a problem you get while trying it?
yes i read your ans properly ....In My App only i had used createprocess to launch a IE hey thanks right now your ans is pretty clear to me . Just now got a idea .Let me check it
thanks Victor .
-
May 14th, 2010, 12:38 PM
#4
Re: CreateProcess() Q
Hi Victor according to your suggestion had tried couple of things by making a sample app. Getting proper process ID but still Enum WIndow gives the handle of AddressBar or some other window.Funniest thing some time hook also doesn't work .Anyway that is not a problem only problem is this Process Id in case of IE
Code:
//*********************************************************************************
//
//Title: Terminal Services Window Clipper
//
//Author: Martin Wickett
//
//Date: 2004
//
//*********************************************************************************
#include "hookdll.h"
#include <windows.h>
#include <winuser.h>
#include "wtsapi32.h"
#include <map>
#include <stdio.h>
#include <process.h>
#include <atlstr.h>
#define DLL_EXPORT extern "C" __declspec(dllexport)
#pragma data_seg ( "SHAREDDATA" )
// this is the total number of processes this dll is currently attached to
int iInstanceCount = 0;
sData stData ={0};
HHOOK hkb =0;
std::map<UINT,sData> myMap;
PROCESS_INFORMATION pi = {0};
STARTUPINFO si ={0};
DWORD dThreadId =0;
HHOOK hhook = 0;//cbt
int iVal =0;
#pragma data_seg ()
#pragma comment(linker, "/section:SHAREDDATA,rws")
std::map<UINT,sData> ::iterator iter;
std::map<UINT,HWND> myMapHwnd;
std::map<UINT,HWND> ::iterator iterHWND;
bool bHooked = false;
bool bHooked2 = false;
bool bHooked3 = false;
HWND hWNdOwner = NULL;
HHOOK hhook2 = 0;//shell
HHOOK hhook3 = 0;//wnd proc
HINSTANCE hInst = 0;
HANDLE m_vcHandle = 0;
HANDLE hThread = NULL;
unsigned threadID =-1;
BOOL APIENTRY DllMain( HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID lpReserved )
{
UNREFERENCED_PARAMETER(lpReserved);
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
// remember our instance handle
hInst = hinstDLL;
++iInstanceCount;
break;
}
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
{
--iInstanceCount;
}
break;
}
return TRUE;
}
LRESULT CALLBACK CbtProc(int nCode, WPARAM wParam, LPARAM lParam )
{
if (nCode<0)
{
return CallNextHookEx(hhook, nCode, wParam, lParam);
}
int i = 0;//tmp
switch( nCode )
{
case HCBT_MINMAX:
i = (int)lParam;
if ( i==2 || i==6 )
{
HWND hWnd = (HWND)wParam;
::GetWindowThreadProcessId(hWnd,&dThreadId);
iVal=1;
break;
}
if (i==3 || i==11)
{
HWND hWnd = (HWND)wParam;
::GetWindowThreadProcessId(hWnd,&dThreadId);
iVal=2;
break;
}
break;
case HCBT_DESTROYWND:
{
HWND hWnd = (HWND)wParam;
::GetWindowThreadProcessId(hWnd,&dThreadId);
iVal=3;
break;
}
break;
case HCBT_SETFOCUS:
//buffer = "HCBT_SETFOCUS";
//not needed yet
break;
default:
break;
}
return CallNextHookEx(hhook, nCode, wParam, lParam);
}
//if (GetParent(H) = 0) and (GetWindow(H,GW_OWNER) = 0) and (GetWindowLong(H,GWL_EXSTYLE and WS_EX_TOOLWINDOW) = 0)
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM param)
{
DWORD pid =NULL;
::GetWindowThreadProcessId(hwnd, &pid);
if (pid == (DWORD)param)
{
myMapHwnd.insert(std::pair<UINT,HWND>(pid,hwnd));
::SetWindowPos(hwnd,
HWND_TOPMOST, 0, // left-top of the screen
0, 0,0,
SWP_NOZORDER|SWP_NOMOVE);
//::ShowWindow(hwnd,SW_SHOWNORMAL);
return false;
}
return true;
}
unsigned __stdcall SecondThreadFunc( void* pArguments )
{
UNREFERENCED_PARAMETER(pArguments);
printf( "In second thread...\n" );
while ( true )
{
ULONG uPId =0;
iter = myMap.find(dThreadId);
if(iter!=myMap.end())
{
iterHWND = myMapHwnd.find(dThreadId);
HWND hWnd = (*iterHWND).second;
::ShowWindow(hWnd,SW_MAXIMIZE);
}
}
//
return 0;
}
DLL_EXPORT void SetCbtHook(void)
{
if (!bHooked)
{
for(int i=0;i<1;i++)
{
if (CreateProcess(TEXT("C:\\Program Files\\Internet Explorer\\iexplore.exe"), TEXT("www.google.com"), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
{
::WaitForInputIdle(pi.hProcess,INFINITE);
stData.iVal = i;
strcpy_s(stData.str,strlen("hell")+1,"Hell");
::EnumWindows(&EnumWindowsProc,(LPARAM)pi.dwProcessId);
myMap.insert(std::pair<UINT,sData>(pi.dwProcessId,stData));
}
}
hhook = SetWindowsHookEx(WH_CBT,CbtProc,hInst,NULL);
hThread = (HANDLE)_beginthreadex( NULL, 0, &SecondThreadFunc, NULL, 0, &threadID );
if(hThread!=NULL)
::WaitForSingleObject(hThread,INFINITE);
bHooked = true;
}
}
DLL_EXPORT void RemoveCbtHook(void)
{
if(bHooked)
{
UnhookWindowsHookEx(hhook);
bHooked = false;
}
}
DLL_EXPORT int GetInstanceCount()
{
return iInstanceCount;
}
Thanks
Last edited by humptydumpty; May 14th, 2010 at 01:32 PM.
-
May 14th, 2010, 12:54 PM
#5
Re: CreateProcess() Q
I wonder, dear humptydumpty,
is it your credo to ignore any indentations in your code?
Victor Nijegorodov
-
May 14th, 2010, 01:15 PM
#6
Re: CreateProcess() Q
Originally Posted by VictorN
I wonder, dear humptydumpty,
is it your credo to ignore any indentations in your code?
I am sorry Victor Just copy paste from VS .Actually i am little bit stuck here So just forget to do this. This is really nasty Geetting problem with IE then VLC media player etc. due to these 2 issue i am just stuck.
Thanks
-
May 14th, 2010, 01:19 PM
#7
Re: CreateProcess() Q
Just curious. How did you get the syntax coloring? Is that a VBCode option I don't know about, or did you manually color all that text in the editor?
-
May 14th, 2010, 01:26 PM
#8
Re: CreateProcess() Q
Originally Posted by hoxsiew
Just curious. How did you get the syntax coloring? Is that a VBCode option I don't know about, or did you manually color all that text in the editor?
And Victor a Interesting point
Have a look this function..Even you pass the pid as a input parameter to your function you will come to know that SetWindowPos shows one extra IE short of Window instead of setting IE Window Pos....
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM param)
{
DWORD pid =NULL;
::GetWindowThreadProcessId(hwnd, &pid);
if (pid == (DWORD)param)
{
::SetWindowPos(hwnd,
HWND_TOPMOST, 0, // left-top of the screen
0, 0,0,
SWP_NOZORDER|SWP_NOMOVE);
::ShowWindow(hwnd,SW_SHOWNORMAL);
returnfalse;
}
returntrue;
}
Thanks
-
May 14th, 2010, 03:17 PM
#9
Re: CreateProcess() Q
Originally Posted by humptydumpty
I am sorry Victor Just copy paste from VS .Actually i am little bit stuck here So just forget to do this. This is really nasty Geetting problem with IE then VLC media player etc. due to these 2 issue i am just stuck.
Thanks
Just Copy Paste Visual Studio Code.
-
May 14th, 2010, 03:50 PM
#10
Re: CreateProcess() Q
It's never done the syntax coloring for me on paste. Maybe it's an IE thing (I never use IE--Firefox exclusively).
-
May 15th, 2010, 12:04 AM
#11
Re: CreateProcess() Q
I am quite close .Now getting proper process Id etc. Had varified from SPY++ .Now the only problem is Under my EnumThreadWindowProc() when i try to get HWND from ProcessID it return me the handle of TabWindowClass Not the IEFrame Window Handle. SO how to get the IEFrame Window handle from this processID.
Problem Solved:-
Thanks
Last edited by humptydumpty; May 15th, 2010 at 12:35 AM.
-
May 15th, 2010, 08:45 AM
#12
Re: CreateProcess() Q
Use Spy++ to obtain the relationship between these IE windows.
Victor Nijegorodov
-
May 15th, 2010, 07:32 PM
#13
Re: CreateProcess() Q
Those are TabBrowser Window .this problem occur in case of multilayer window like MSOutlook and IE etc .now how to get main window HWND from this process id . I have something in my mine .But i want to know Ur opinion first.in case of vlc i can c processid is same but no relation between window
Thanks
Last edited by humptydumpty; May 15th, 2010 at 08:03 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|