🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: WM_QUIT and Hook

#1012
From: Bob Gonder
Date: Wed, 31 Oct 2007 16:14
27 lines
2152 bytes
Patryk B. wrote:

>Im traying to prevent to close my application.
>I know its function OnCloseQuery but i want to prevent closing
> from Task Manager too.
>In know that global hook should be placed in DLL.
>But I want hook only for my application.

Then you should try hooking in WinMain instead of TForm6::Button1Click
And be aware that non-DLL hooks are for one thread only.

>What is wrong? It dont detect WM_QUIT.

Could it be that VCL doesn't post that message?
In any case, the window will have already been destroyed (WM_DESTROY)
before WM_QUIT is posted. Also, WM_DESTROY comes _after_ the window is destroyed.
It would probably be easier to just place a while(1){} around
the application code in WinMain, than to try to stop WM_QUIT.

I think you want to catch it even sooner.
You might look into WM_SYSCOMMAND-SC_CLOSE

>LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)

I'm not sure what the ncode is for WM_QUIT, but it might be other than HC_ACTION.
You might check all messages.
It might also be a good idea to use the WinAPI instead of VCL code in the handler.
Technical Details
Message-ID: <vt7hi3d1lt8jv8onmj0i7k4jv8hro99p5e@4ax.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!feeder3.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!news2.euro.net!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <op.t0140zizwzezly@dune.intranet>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,611b8a70eeab8356
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: WM_QUIT and Hook
Date: Wed, 31 Oct 2007 09:14:17 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <vt7hi3d1lt8jv8onmj0i7k4jv8hro99p5e@4ax.com>
References: <op.t0140zizwzezly@dune.intranet>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 69.69.84.21
X-Trace: newsgroups.borland.com 1193847255 69.69.84.21 (31 Oct 2007 09:14:15 -0700)
Lines: 29
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!feeder3.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!news2.euro.net!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail