📄 wpw_wapi_task_95.html
字号:
<HTML>
<HR><A NAME=WINAPI_TASK_ACT_1ST_INST>
Return to <a href="wpw_wapi_index.html#TOC">Table of Contents for this chapter</a><br>
<H4>Subject: Activating first instance of app?</H4><PRE>
Hi,
I'm making an application that is not allowed to have more than one instance.
To prevent a second instance from being run, I made the following code:
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
if (!hPrevInstance) {
// start the first instance ..
} else
return 0;
}
This seems to work nicely. But what I wanted to do is to activate the
main window of the previous instance if there is one.Therefore I defined a
global ghWin, containing the HWND of the main window,and tried to activate
that one of the previous instance as follows:
HWND ghWin;
.. at initialisation of first instance: ghWin = MainWindow->HWindow;
and then replacing the "return 0;" by
{
GetInstanceData(hPrevInstance,(BYTE *) &ghWin, sizeof(HWND));
ShowWindow(ghWin,SW_RESTORE);
SetFocus(ghWin);
return 0;
}
But it does not work. Any ideas where I made a mistake?
Thanks in advance,
Rik Essenius
<HR>
I think the most common way of doing this might be:
if (! hPrevInstance)
...
else
{
if ((hWnd = FindWindow(pszClass, NULL)) != NULL)
BringWindowToTop(hWnd);
}
</PRE>
<HR><A NAME=WINAPI_TASK_HWND>
Return to <a href="wpw_wapi_index.html#TOC">Table of Contents for this chapter</a><br>
<H4>Subject: Getting HWND from Instant handle</H4><PRE>
"How does one get a window handle from an instance handle?"
Use TaskFirst() and TaskNext() until you find a task whose
instance matches the one you are looking for. Then do an
EnumTaskWindows() to find the top level windows associated
with that task.
Ed
<HR>
In article: <803151253snz@chrism.demon.co.uk> Chris Marriott <chris@chrism.demon.co.uk> writes:
>
> In article <DA2xtv.L6q@cuug.ab.ca> cokars@cuug.ab.ca "Sami Cokar" writes:
>
> >Hi,
> > How does one get a window handle from an instance handle?
> > I've been unable to find it in the FAQ that was posted
> > recently. Thanx.
>
> You can't. There IS no "one to one" correspondance between an HINSTANCE
> and an HWND. An HINSTANCE refers to an application, and an application can
> have an arbitrary number (including zero!) of windows.
>
Not strictly true. Use the EnumTaskWindows to have your callback
function called for windows which belong to a task. As Chris
says, your function may never be called.
EnumTaskWindows (2.x)
BOOL EnumTaskWindows(htask, wndenmprc, lParam)
HTASK htask; /* handle of task */
WNDENUMPROC wndenmprc; /* address of callback function */
LPARAM lParam; /* application-defined value */
Andrew Gebbie
</PRE>
<HR><A NAME=WINAPI_TASK_END_OTHER_APP>
Return to <a href="wpw_wapi_index.html#TOC">Table of Contents for this chapter</a><br>
<H4>Subject: How to end other apps?</H4><PRE>
freek@rabo.nl (Freek Oldenhuis Arwert) wrote:
> With LoadModule , you can start an application, and with
> FreeModule you can (probeable) release the application.
> But this does not work, in my programm.
You can't really force applications to stop, except under bad
circumstances. The TerminateApp function forcibly terminates another
application, but it can leave certain resources in memory, so it is
not recommended.
Probably the best way to terminate another application is to send its
main window a WM_CLOSE message and let it terminate normally. This
will let the application do any normal clean up processing (such as
freeing menus, etc.). The Task List dialog ends other tasks in this
fashion.
If you don't let the normal exit processing occur, menus and certain
other GDI resources will never be freed, and eventually you will run
out of system resources because the GDI and USER heaps will become
full. Then your system will lock up, or you'll have to exit Windows.
<HR>
</PRE>
<HR><A NAME=WINAPI_TASK_HANDLE_APP_DLL>
Return to <a href="wpw_wapi_index.html#TOC">Table of Contents for this chapter</a><br>
<H4>Subject: Getting Task handle of App call DLL</H4><PRE>
In article <3r6cs8$2ob@galaxy.uci.agh.edu.pl>, rydzew@student.uci.agh.edu.pl (Mikolaj Rydzewski) writes:
|> Gavin Hodge (gavin@osa.com.au) wrote:
|> : >I need to know how to identify which application is currently calling
|> : >a procedure in a DLL. If several different apps (or several instances of
|> : >the same app) are all using a single DLL, I need to know which app is
|> : >calling a procedure in the DLL so I can return the correct data.
|>
|> : Another way is to call GetCurrentTask(), on the assumption that the
|>
|> But when you call GetCurrentTask() from a library it will return library's
|> task id, not the calling app.
A DLL is NOT a task. It has no task handle.
--
Kent Tong (tongk@arch.su.edu.au)
Freeman Installer==> ftp.arch.su.edu.au /pub/tongk/finst22.zip
Key Center of Design Computing, Sydney University
</PRE>
<HR><A NAME=WINAPI_TASK_TIMESHARE>
Return to <a href="wpw_wapi_index.html#TOC">Table of Contents for this chapter</a><br>
<H4>Subject: Sharing CPU time with other tasks</H4><PRE>
In article <3s7s76$8p3@ocean.CAM.ORG> mike_t@CAM.ORG (Michael Totilo) writes:
>Hi I'm a novice to this C++ for Win.
>
>My question is this, I wrote a little Windows pgm, and placed a loop like:
>
>for i = 1 to 1000
> for j = 1 to 1000
>
> end
>end
>
>pseudocode...
>
>Anyhow, my program now has the CPU's full attention. In other words while
>in this loop, I wanted to go to another application, however i was not
>able since the the pgm was in the loop. How do I make windows give access
>to other applications as my pgm runs. In other words how do I allow other
>applications to run while mine is executing a loop.
for i=1 to 1000
for j=1 to 1000
while(PeekMessage(...., PM_REMOVE)){
TranslateMessage...
DispatchMessage
}
}
}
You really need to get a good book on the fundamentals of Windows
programming. I can recommend "Programming Windows 3.1" by
Charles Petzold. It will explain the fundamentals of continuing
to pump messages during data processing. Note that the above
is a bit excessive - it checks for messages for every iteration
of j. It's probably enough to check in the outer loop only.
>
> The reason I need something like this is maybe I want to place a
>time check in my pgm. Like maybe if it is 5:00pm beep.... So my pgm will
>constantly check the time.... I know there must be a better may of doing
>this. However I just want to really know how to get out of this problem.
use SetTimer() instead and respond to WM_TIMER.
--
John A. Grant jagrant@emr1.emr.ca
Airborne Geophysics
Geological Survey of Canada, Ottawa
<HR>
Robert Thivierge (thivier1@canuck.com) wrote:
: Is there some command I can sprinkle inside my code that
: will cause my program to share the CPU with others apps.
The following function properly implements a peekmessage
loop. If properly used it will allow your program to co-op
multi-task with others
void BeNice()
{
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
Chris
--
----------------------------------------------------------------------
Chris Reynolds - College of Computing, Georgia Tech - GTRI
http://www.cc.gatech.edu/people/home/chrisr
<HR>
In article <huang.805702483@nickel.cs.umanitoba.ca>
huang@nickel.cs.umanitoba.ca "Hui Huang" writes:
>I use the following function
>
>void GiveUpTimeSlice()
>{
> MSG msg;
> while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
> TranslateMessage(&msg);
> DispatchMessage(&msg);
> }
>}
>
>Just call this function inside your processing loop.
This is good, but I'd add one thing - you MUST explicitly check for
"WM_QUIT" and exit the loop (and the program). Otherwise your program
will crash if someone exits the program whilst you're inside your loop.
Chris
--
--------------------------------------------------------------------------
| Chris Marriott, Warrington, UK | Author of SkyMap v2 shareware |
| chris@chrism.demon.co.uk | astronomy program for Windows. |
| For more info, see http://www.winternet.com/~jasc/skymap.html |
| Author member of Association of Shareware Professionals (ASP) |
--------------------------------------------------------------------------
</PRE>
<HR><A NAME=WINAPI_TASK_ACTIVE_DLL>
Return to <a href="wpw_wapi_index.html#TOC">Table of Contents for this chapter</a><br>
<H4>Subject: Detect an active DLL or task</H4><PRE>
In article <3s3vg6$37d@mo6.rc.tudelft.nl> koen@dutlhs1.lr.tudelft.nl (Koen D'Hondt) writes:
>Hi,
>I'm writing a little program which detects the active applications and
>dll's in the system (need it for debugging purposes).
>What I've got at the moment is a list of active applications and dll's
>loaded, but I want to add something to see which dll's get loaded when
>an application is activated. Currently I have a ``rescan'' button
>which rescans the system for active applications and dll's, each time
>it's pushed.
>So my question is: how do I let my program know when a program starts?
>Must this be done by installing a hook(WH_MSGFILTER) or is there another
>way to do this?
>Greetings,
>Koen
>--
>------------------------------------------------------------------------
>Koen D'Hondt
>koen@master.pisces.macsch.com koen@dutlhs1.lr.tudelft.nl
>Graduate student at Delft University of Technology, The Netherlands
>Faculty of Aeronautics and Aerospace Engineering,
>Section High-Speed aerodynamics.
>------------------------------------------------------------------------
The only other way I know is via NotifyRegister, which isn't much different
than using a hook...
Kit Kauffmann - kitk@mudshark.sunquest.com
AKA 73363,447 (Compu$erve)
Finger me for my public key
</PRE>
<HR><A NAME=WINAPI_TASK_DETECT_END>
Return to <a href="wpw_wapi_index.html#TOC">Table of Contents for this chapter</a><br>
<H4>Subject: How to detect the end of an application?</H4><PRE>
|> When you "Exit Windows", I want my program to detect that the user
|> has decided to close windows, and I want a message box popped up
|> warning the user that my program is still running and that they should
|> close it first.
|>
|> How do you do it?
Instead of looking at the WM_CLOSE mesage, try the WM_QUERYENDSESSION
message.
</PRE>
<HR><A NAME=WINAPI_MISC_EXIT_RESART_WIN>
Return to <a href="wpw_wapi_index.html#TOC">Table of Contents for this chapter</a><br>
<H4>Subject: Exit and restart Windows</H4><PRE>
In article <3rvut3$fuo@metro.ucc.su.OZ.AU> tongk@arch.su.edu.au writes:
>In article <DA8ov4.A0E@emr1.emr.ca>, jagrant@emr1.emr.ca (John Grant) writes:
>|> In article <3rq3ms$pnp@hp19.us.dbisna.com> MazourE@dbisna.com writes:
>|> >Does anybody know the way to restart Windows from program?
>|> >
>|> >Thanks in advance
>|> >
>|> >Efim Mazour
>|>
>|> ExitWindows(...)
>
>So, what is the best way to restart Windows AND then execute
>a Windows program? I know ExitWindowsExec() but it only
>exits Windows, executes a DOS program and then restarts
>Windows, which is not what I want.
Hmm, I wonder what would happen if you did:
ExitWindowsExec("win.com","myapp.exe");
(with appropriate pathnames of course)
--
John A. Grant jagrant@emr1.emr.ca
Airborne Geophysics
Geological Survey of Canada, Ottawa
<HR>
jev@echelon.win-uk.net (Javon Prince) schrieb unter 'Alt+Tab Switching':
> Does anyone know how to disable Alt+Tab switching?
Try to handle the WM_SYSKEYDOWN message, filtering ALT+TAB.
Bye, Felix
</PRE>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -