🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #4086

Re: From Process to Window Handle

#4086
From: KL Chin
Date: Tue, 14 Mar 2006 06:37
141 lines
4751 bytes
Hi Gambit,

I'm not sure, is these any bugs?
Somehow, the STARTUPINFO is useless in CreateProcess to launch the 
NotePad.exe.

Before that I did the samething like your method, and I try again with your 
code, same
thing happended, the window did not place to the correct place, instead in 
start at the
previous location, any ideal what could the problem,

Regards,
KL Chin



"KL Chin" <klchin@1asia.com.my> wrote in message 
news:44165869@newsgroups.borland.com...
> Hi Gambit,
>
> Thx for you suggestion & code.
>
> I had no problem to do it with CreateProcess.
> But I do have problem with ShellExecEx, bcoz I need to open
> any kind document file (doc,txt,bmp) instead of exe file.
>
> Regards
> KL Chin
>
>
> "Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
> news:4415eab2@newsgroups.borland.com...
>>
>> "KL Chin" <klchin@1asia.com.my> wrote in message
>> news:4414f5b4$1@newsgroups.borland.com...
>>
>>> Which function should I used to find a window with a Handle
>>> Procees
>>
>> There isn't any one specific function for that.  You will have to find 
>> the
>> window handle manually, using EnumWindows() and 
>> GetWindowProcessThreadId().
>>
>>> with execture by ShellExecuteEx
>>
>> I would suggest you use CreateProcess() instead of ShellExecuteEx().
>> ShellExecute() does not return the ID of the spawned process.
>> CreateProcess() does.  You need that ID so that you have something to
>> compare with GetWindowThreadProcessId().
>>
>>> so that I can postion the window.
>>
>>    struct sWndInfo
>>    {
>>        HWND hWnd;
>>        DWORD dwProcessId;
>>    };
>>
>>    BOOL CALLBACK FindMainWindow(HWND hwnd, LPARAM lParam)
>>    {
>>        sWndInfo *pInfo = (sWndInfo*) lParam;
>>
>>        DWORD dwProcessId;
>>        GetWindowThreadProcessId(hwnd, &dwProcessId);
>>
>>        if( dwProcessId == pInfo->dwProcessId )
>>        {
>>            if( hwnd matches some criteria )
>>            {
>>                pInfo->hWnd = hwnd;
>>                return FALSE;
>>            }
>>        }
>>
>>
>>        return TRUE;
>>    }
>>
>>    {
>>        AnsiString CmdLine = AnsiQuotedStr(sexe, '"') + " "  + sprm;
>>
>>        STARTUPINFO si = {0};
>>        PROCESS_INFORMATION pi = {0};
>>
>>        si.cb = sizeof(si);
>>        si.dwFlags = STARTF_USESHOWWINDOW;
>>        si.wShowWindow = SW_SHOWNORMAL;
>>
>>        if( CreateProcess(NULL, CmdLine.c_str(), NULL, NULL, FALSE, 0, 
>> NULL,
>> spth.c_str(), &si, &pi);
>>        {
>>            WaitForInputIdle(pi.hProcess, INFINITE);
>>            CloseHandle(pi.hThread);
>>            CloseHandle(pi.hProcess);
>>
>>            sWndInfo Info = {0};
>>            Info.dwProcessId = pi.dwProcessId;
>>            EnumWindows((WNDENUMPROC) FindMainWindow, (LPARAM) &Info);
>>
>>            if( Info.hWnd )
>>                // use Info.hWnd as needed...
>>        }
>>    }
>>
>>
>> Even better, the lpStartupInfo parameter of CreateProcess() allows you to
>> pass in the desired position and size directly:
>>
>>    {
>>        AnsiString CmdLine = AnsiQuotedStr(sexe, '"') + " "  + sprm;
>>
>>        STARTUPINFO si = {0};
>>        PROCESS_INFORMATION pi = {0};
>>
>>        si.cb = sizeof(si);
>>        si.dwFlags = STARTF_USESHOWWINDOW;
>>        si.dwX = ...;
>>        si.dwY = ...;
>>        si.dwXSize = ...;
>>        si.dwYSize = ...;
>>        si.wShowWindow = SW_SHOWNORMAL | STARTF_USEPOSITION |
>> STARTF_USESIZE;
>>
>>        if( CreateProcess(NULL, CmdLine.c_str(), NULL, NULL, FALSE, 0, 
>> NULL,
>> spth.c_str(), &si, &pi);
>>        {
>>            CloseHandle(pi.hThread);
>>            CloseHandle(pi.hProcess);
>>        }
>>    }
>>
>>
>> Gambit
>>
>>
>
> 
Technical Details
Message-ID: <441664ca$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4414f5b4$1@newsgroups.borland.com> <4415eab2@newsgroups.borland.com> <44165869@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,e1b5a692dc7fc69d
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "KL Chin" <klchin@1asia.com.my>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4414f5b4$1@newsgroups.borland.com> <4415eab2@newsgroups.borland.com> <44165869@newsgroups.borland.com>
Subject: Re: From Process  to Window Handle
Date: Tue, 14 Mar 2006 14:37:57 +0800
Lines: 143
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 60.49.242.118
Message-ID: <441664ca$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1142318282 60.49.242.118 (13 Mar 2006 22:38:02 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail