Question and Answer Database FAQ2501C.txt Trapping the Alt-F4 command. Category :VCL Platform :All Product :C++Builder 3.x Question: How do I prevent someone from useingto shut down an application that I have written? Answer: The answer lies in overriding the WndProc function of your form calss thusly: Add the following to the header file, right under the line that says private: // User declarations protected: virtual void __fastcall WndProc(Messages::TMessage & msg); and then add the following function to the .cpp file void __fastcall TForm1::WndProc(Messages::TMessage & msg) { TWMSysCommand & syscmd = reinterpret_cast (msg); if ( syscmd.Msg == WM_SYSCOMMAND && syscmd.CmdType == SC_CLOSE && syscmd.YPos <= 0 ) { HMENU systemMenu = GetSystemMenu(Handle, FALSE); MENUITEMINFO menuItemInfo; ZeroMemory(&menuItemInfo, sizeof(menuItemInfo)); menuItemInfo.cbSize = sizeof(menuItemInfo); menuItemInfo.fMask = MIIM_STATE; if ( GetMenuItemInfo(systemMenu, SC_CLOSE, FALSE, &menuItemInfo) && menuItemInfo.fState & (MFS_DISABLED | MFS_GRAYED) ) { return; } } TForm::WndProc(msg); } 7/2/98 10:32:32 AM
Last Modified: 01-SEP-99