Article View: borland.public.cppbuilder.nativeapi
Article #17079Re: Another Issue about ShellExecute
From: Ed Mulroy [TeamB]
Date: Tue, 08 Apr 2003 17:14
Date: Tue, 08 Apr 2003 17:14
81 lines
3131 bytes
3131 bytes
> Jo�o Pereira wrote in message
> news:3e92ee2f@newsgroups.borland.com...
>
> but could you make a example explaining how do you
> can move and positionate a window, with
> CreateProcess(), EnumWindows() and
> GetWindowThreadProcessId().
Exactly the same functionality as someone asked me for the other day.
Create a text file named "TEST.TXT" in the project directory and then
compile and run this. It's an API-only program so if you build it from
within the IDE then use the console wizard with the GUI checkbox checked and
the VCL one not checked.
-----------------------
#include <windows.h>
HWND child_hwnd;
BOOL CALLBACK MyEnumProc(HWND hwnd, LPARAM lp)
{
DWORD hwnd_pid;
// get process id for the window
GetWindowThreadProcessId(hwnd, &hwnd_pid);
// if they match, save the value, end the enumeration
if (hwnd_pid == (DWORD) lp)
{
child_hwnd = hwnd;
return FALSE;
}
return TRUE;
}
// move the window down and to the left 2 pixels
// then wait 10 millisec
void MoveDelay()
{
RECT r;
GetWindowRect(child_hwnd, &r);
MoveWindow(child_hwnd, r.left + 2, r.top + 2,
r.right - r.left, r.bottom - r.top, TRUE);
Sleep(10);
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
STARTUPINFO starti;
PROCESS_INFORMATION pi;
// start notepad with the text file as a cmd line argument
ZeroMemory(&starti, sizeof(starti));
starti.cb = sizeof(starti);
CreateProcess(NULL, "notepad.exe test.txt",
NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS,
NULL, NULL, &starti, &pi);
// wait until notepad has initialized
WaitForInputIdle(pi.hProcess, 4000U);
// find the notepad window handle
EnumWindows(MyEnumProc, (LPARAM) pi.dwProcessId);
// if found, then move it
if (child_hwnd)
{
for (int i = 0; i < 100; ++i)
{
MoveDelay();
}
}
return 0;
}
-----------------------
. Ed
Technical Details
Message-ID:
<3e93038d@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3e8c0ea4@newsgroups.borland.com> <3e918b4d@newsgroups.borland.com> <3e91b8e8$1@newsgroups.borland.com> <3e91be11$1@newsgroups.borland.com> <3e91c5c6$1@newsgroups.borland.com> <3e92ee2f@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 10cc67,bff1fa0e8e8777f2 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-04-08 10:17:34 PST From: "Ed Mulroy [TeamB]" <ed@mulroyREMOVETHESECHARS.org> Newsgroups: borland.public.cppbuilder.nativeapi References: <3e8c0ea4@newsgroups.borland.com> <3e918b4d@newsgroups.borland.com> <3e91b8e8$1@newsgroups.borland.com> <3e91be11$1@newsgroups.borland.com> <3e91c5c6$1@newsgroups.borland.com> <3e92ee2f@newsgroups.borland.com> Subject: Re: Another Issue about ShellExecute Date: Tue, 8 Apr 2003 13:14:35 -0400 Lines: 83 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 24.74.175.102 Message-ID: <3e93038d@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1049822093 24.74.175.102 (8 Apr 2003 10:14:53 -0800) X-Authenticated-User: edmulroy Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail