Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CWnd from HINSTANCE ???

133 views
Skip to first unread message

Carsten Witte

unread,
Oct 27, 1997, 3:00:00 AM10/27/97
to

Hi Gurus,

anybody knows how to detect the window for a given HINSTANCE ???

Problem is, that I have "started" a document via ShellExecute() and
want to know if that is still running. Since I don't know which
applications is bound to .txt I neither know for what class nor for
what title to search with FindWindow ...

On second "open" I need to test if an instance of that documen is
already started and reactivate that before starting another thread.

If I'd get the window, I know the task to bring it back. ;)

Thanx for any suggestions.

Carsten Witte

book&data GmbH, Reventloustraße 5, 24235 Laboe, Germany
- Human : +49 (4343) 427713
- Fox : +49 (4343) 427721
- Spider: http://www.bookdata.de

· Nothing in live is ever easy. (Calvin)

Girish Bharadwaj

unread,
Oct 27, 1997, 3:00:00 AM10/27/97
to

I guess you can do a EnumWindows () call to enumerate all the windows on
the system and make sure that its GW_OWNER is null i.e. its the top
level window , then get its GWL_HINSTANCE and compare it with your
hInstance. If its the same, You got it..

It might be something like this
::EnumWindows ((WNDENUMPROC)EnumWindowsProc, (LPARAM)createdHinstance);

BOOL CALLBACK CEXEListDlg::EnumWindowsProc (HWND hWnd, LPARAM lParam)
{
//Here I will do all thats said above

if ((::GetWindow (hWnd, GW_OWNER) == NULL) && (::GetWindowLong (hWnd,
GWL_HINSTANCE)== lParam))
{
// You got the window..
// Do what you want
return FALSE; // Enuf Enumaration
}
return TRUE; //Continue enumeration
}

Well. EnumWindowsProc is defined as static
static BOOL CALLBACK EnumWindowsProc (HWND hWnd, LPARAM lParam);

You know the rest of the story..
I dont know of any other way.. There may be ..

--
Girish Bharadwaj
Software developer
http://members.tripod.com/~GBharadwaj/index.html
Email #1:gir...@usa.net
Email #2:GBhar...@aol.com

Girish Bharadwaj

unread,
Oct 27, 1997, 3:00:00 AM10/27/97
to

ooops,, David is right.. How can you have unique HInstances in win32??
This is the effect of too many coffee ,late nights,drab days and win16
thinking interfering with the win32 world.. :-) Try ShellExecuteEx wnd
GetWindowThreadProcessID() as Dave said... I guess I will have to
hibernate for sometime...:-)

Girish Bharadwaj wrote:
<forget anything I said>

Carsten Witte

unread,
Oct 29, 1997, 3:00:00 AM10/29/97
to

Hi Girish,

> I guess I will have to hibernate for sometime...:-)

Feeling a little bit squirreld, eh ??? ;)

Carsten Witte

unread,
Oct 29, 1997, 3:00:00 AM10/29/97
to

Hi David,

Thanx for your reply.

>If you use ShellExecuteEx you can get a process handle that should be
>more useful in identifying the window along with
>GetWindowThreadProcessId.

Okay, I got that ShellExecuteEx to work (someway):

SHELLEXECUTEINFO sei;
sei.cbSize = sizeof (sei);
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
sei.hwnd = GetSafeHwnd();
sei.lpVerb = NULL;
sei.lpFile = FN_ALERTLOG;
sei.lpParameters= NULL;
sei.lpDirectory = NULL;
sei.nShow = SW_SHOWNORMAL;

if (ShellExecuteEx (&sei)) TRACE ("Happy[nm]ess\n");

Very weird stuff. ;) Despite of what the help (similar to
ShellExecute) says, I think one should not pass NULL for .nShow on
documents. That one just gave me an invisible editor that I had to
kill from taskmanager. <veg>

The .hwnd seems to be good for nothing, since in my case the editor
still was been inserted under desktop. :( That ripped me off the
chance to detect the window the easy way.

After all, I've traced a little bit around and figured out that
neither the processID, nor the instance handle - not to mention the
window handle - are unique enough for my problem. Each might be reused
someday. e.g.: If I kill the application, leaving the viewer alone I
get another 7 for processID on application restart ... and so on.

Now, to make a long story short, I now let the user open as much
viewer viewers as he likes to and ressources will let him. :) If he
needs a million zillion viewer, who am I to deny.

But your and everyones help is sure valued, even if I didn't use the
idea this time. Who know when I really need ShellExecuteEx and then I
know everything about it. :)

0 new messages