I want to override the normal keypress event Alt+F4 in my application.
I am using borland builder 6.
i wrote a fn for Application->OnMessage = msghandler;
In this handler I am checking for the Key State of the Alt & F4 & then if the key is pressed I am calling some fns. This works fine. But when I press Alt+F4 the function gets called a lot of times if the key is pressed normally. I want my fn to be called only once. Is the way that I have handled correct or should i try to handle this in some other way? Please help!!!

here is my code

msghandler(tagMSG &message, bool &handled)
{
   short shRet;
   shRet = GetAsyncKeyState(VK_MENU);
   bool bVal = (shRet >> 1)&& 1;
   short key = GetAsyncKeyState(VK_F4);
   bool keyState = (key >> 1)&& 1;

   if(bVal == true && keyState == true)
   {
      handled = true;
      // I am calling my fns here which has to be called on press of Alt+F4
   }
}

Recommended Answers

All 2 Replies

Alt-F4 is used by the system to terminate an application. Users expect this. (Don't do things that users don't expect.)

You might want to look at the OnClose and OnCanClose events if you just want to do cleanup before the application terminates or to prevent the application from terminating under some circumstances.

Be warned, though. Programs that can't be stopped make people very angry.

Good luck.

Alt-F4 is used by the system to terminate an application. Users expect this. (Don't do things that users don't expect.)

You might want to look at the OnClose and OnCanClose events if you just want to do cleanup before the application terminates or to prevent the application from terminating under some circumstances.

Be warned, though. Programs that can't be stopped make people very angry.

Good luck.

True one must not not manipulate the Alt+F4. But in a particular scenario, I want to override that key press to call some other function. At this particular scenario I do not want my application to be closed, instead perform my function. Also I am using the Alt+Arrow keys to call my functions which cause the same scenario which I have mentioned in my earlier post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.