Article View: borland.public.cppbuilder.nativeapi
Article #11751SHExecInfo.hInstApp != GetWindowLong(hwnd,GWL_HINSTANCE);
From: Rodrigo
Date: Fri, 23 Jan 2004 17:17
Date: Fri, 23 Jan 2004 17:17
86 lines
4210 bytes
4210 bytes
Hi... I'm trying to match a SHELLEXECUTEINFO.hInstApp with the one retrieved
by GetWindowLong. All this is to retrieve the window handle trought the
window instance, however it seems like both "instances" are not the same (or
perhaps I'm doing something wrong).
I faced several problems:
1.- When watching the values of SHELLEXECUTEINFO, the instance retrieved by
GetWindowLong appears to be more similar to the hProcess value than the
hInstApp value (see the GetWinHandle function below).
2.- I couldn't make the callback function belong to the TMainForm class
because compiler showed a message telling that the function must be called
or its address taken... When fully quallifying the method it showed a "cant
cast x to y" message.
3.-I got some of this code from the "Builder C++ 5 Developers Guide",
however they use the Create Process function to spawn the app so they can
retrieve the process ID. I don't want to use CreateProcess to avoid the
hassle of retrieving the application module for each of the files to be
opened (but if that what it takes I will have to...)
4.-For what I understood from the documentation of both API functions,
EnumWindows should loop until callback returns false, however after
inspecting the hwnd and h variables from the callback function:
a) It repeats hwnd values
b) Despite that the callback function returns true, the EnumWindows
exits after a while
A sleepless man appreciates any help you can provide...
Regards...
<R>.
Here is the code...:
HWND TMainForm::LookForWindowHandle(HANDLE Hinstance)
{
unsigned long temp;
temp=(long)Hinstance;
if (!EnumWindows((WNDENUMPROC)GetWinHandle,temp))
return swProcess; //global variable
else
return 0;
}
//--------------------------------------------------------------------------
-
BOOL CALLBACK GetWinHandle(HWND hwnd,unsigned long Hinstance)
{
unsigned long h;
h=GetWindowLong(hwnd,GWL_HINSTANCE);
//GetWindowThreadProcessId(hwnd,&h);
if (h != Hinstance)
return true;
swProcess=hwnd;
return false; //handle found
}
//--------------------------------------------------------------------------
-
void TMainForm::AppSpawnFunction(NodeInfo *dataPtr){ //my class to hold
properties of the spawnes app
SHELLEXECUTEINFO shExecInfo;
bool b_res;
//...
//spawn application to open the document
shExecInfo.cbSize=sizeof(SHELLEXECUTEINFO);
memset(&shExecInfo,0,sizeof(shExecInfo));
shExecInfo.cbSize=sizeof(shExecInfo);
shExecInfo.hwnd=Handle;
shExecInfo.lpVerb="open";
shExecInfo.lpFile=dataPtr->systemString.c_str(); //contains
the filename with the whole path
shExecInfo.nShow=SW_NORMAL;
shExecInfo.fMask=SEE_MASK_NOCLOSEPROCESS;
//spawn application to open the document
b_res=ShellExecuteEx(&shExecInfo);
if(b_res)
{
dataPtr->hProcess=shExecInfo.hProcess;
dataPtr->hInstance=shExecInfo.hInstApp;
dataPtr->windowHandle=LookForWindowHandle(dataPtr->hInstance);
//dataPtr->windowHandle=LookForWindowHandle(dataPtr->hProcess);
}
//...
}
Technical Details
Message-ID:
<401157db$2@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,b936e6c0846d144e,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-01-23 09:40:38 PST Reply-To: "Rodrigo" <rmorteo@eudoramail.com> From: "Rodrigo" <rmorteo@eudoramail.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: SHExecInfo.hInstApp != GetWindowLong(hwnd,GWL_HINSTANCE); Date: Fri, 23 Jan 2004 09:17:21 -0800 Lines: 88 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 200.38.16.98 Message-ID: <401157db$2@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1074878427 200.38.16.98 (23 Jan 2004 09:20:27 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail