Once I've done 'CreateProcess()' to open Notepad, it's process id can
be found at pi.dwProcessId (where pi is the PROCESS_INFORMATION
structure)?
Therefore, I should use EnumWindows to compare windows' processids to
that one? Something like:
HWND notepadHandle;
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam) {
DWORD processId;
DWORD threadId = GetWindowThreadProcessId(hWnd,&processId);
if(processId == pi.dwProcessId) {
notepadHandle = hWnd;
return FALSE; //Correct window - stop enum
}
return TRUE; //Continue enum
}
EnumWindows(EnumWindowsProc, 0); (in main())
Then I will have the correct handle to the Notepad window stored
at 'notepadHandle?
(Obviously, something is wrong with this as it doesn't work. Could
you help me to figure out what it is?)
Thanks.
--- In [email protected], Thomas Hruska <[EMAIL PROTECTED]> wrote:
>
> remarknibor wrote:
> > I'm trying to make sure I get the handle to the Notepad window
before
> > attempting alterations by using:
> >
> > hNotepad = FindWindow("Notepad",NULL);
> >
> > but it's returning NULL and I'm not sure why. Any ideas?
>
> Because you are trying to locate the first window that has the
class
> name* "Notepad" and not the window name*. You should have Spy++
with
> your VC++ install...Spy++ is your friend. (If you don't have
Spy++,
> download and use Winspector instead).
>
> * Class names are different from window names. A class name is
used to
> create the ATOM object that is then used to create one or more
windows
> using that class.
>
>
> FindWindow() is NOT a good method for locating a top-level window
> handle. What happens if another instance of Notepad is opened and
the
> function picks that handle instead?
>
> A better approach is to use EnumWindows() with
GetWindowThreadProcessId().
>
> --
> Thomas Hruska
> CubicleSoft President
> Ph: 517-803-4197
>
> *NEW* MyTaskFocus 1.1
> Get on task. Stay on task.
>
> http://www.CubicleSoft.com/MyTaskFocus/
>