Thread: Disable Alt-F4

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Disable Alt-F4

    I've tried returning 0 from windowproc when this is pressed, but it still closes the window.

    Does anyone know of a way to prevent alt-f4 from closing the window?

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is to keep the window from closing via a boolean variable. For example, the program closes only when the user does it manually via menu. Otherwise, ignore the WM_CLOSE message.

    Kuphryn

  3. #3
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    just so you know, that won't work if the user presses ctrl alt del...that's impossible to get around if it's a windows app because windows handles the execution of the program, hence the uses of messages (like wm_close).
    PHP and XML
    Let's talk about SAX

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Check for SC_CLOSE flag in response to a WM_SYSCOMMAND msg. Send all other flags to DefWindowProc (or return FALSE if using a dialog) for default system handling.

    Use GetSystemMenu to get a copy of the system(window) menu and gray out the 'Close Alt + F4' menuitem (assuming you have a visible system menu).

    Hope that helps.

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    It's as simple as that.
    Thanks alot

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Originally posted by Waldo2k2
    just so you know, that won't work if the user presses ctrl alt del...that's impossible to get around if it's a windows app because windows handles the execution of the program, hence the uses of messages (like wm_close).

    Not really. You could block the use of ctrl alt del.

  7. #7
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    Originally posted by golfinguy4
    Not really. You could block the use of ctrl alt del.
    Really?
    I'm curious as to how that works...i didn't think windows would let you do it.
    PHP and XML
    Let's talk about SAX

  8. #8
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    It doesn't really let you.... You have to trick it into thinking that you are running a screensaver.

    Look up SystemParametersInfo and the SPI_SETSCREENSAVEACTIVE option.

  9. #9
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    As far as I know - the SPI_SETSCREENSAVEACTIVE is ineffective in Win 2000 and XP......

  10. #10
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    That's correct. I just tried this on Xp:
    Code:
    if(!SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE, NULL, 0))
    		GetErr("SystemParametersInfo");
    GetErr() Displays return from GetLastError()

  11. #11
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    >> ust so you know, that won't work if the user presses ctrl alt del...that's impossible to get around if it's a windows app because windows handles the execution of the program, hence the uses of messages (like wm_close). <<

    not true, you can use a keyboard hook if you want to disable key presses

  12. #12
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by Okiesmokie
    >> ust so you know, that won't work if the user presses ctrl alt del...that's impossible to get around if it's a windows app because windows handles the execution of the program, hence the uses of messages (like wm_close). <<

    not true, you can use a keyboard hook if you want to disable key presses
    I doubt that........I havent tested it....but on Win 2K and above, the CTL-ALT-DEL combination basically frezzes other process's access to the keyboard and mouse.......I think this applies to hooks too

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Disable ALT key commands
    By Lionmane in forum Windows Programming
    Replies: 9
    Last Post: 09-23-2005, 10:41 AM
  2. MD5 hashing problems =(
    By Uncle Rico in forum C Programming
    Replies: 4
    Last Post: 02-28-2005, 10:31 AM
  3. MD5 Algorithm
    By Inquirer in forum C Programming
    Replies: 2
    Last Post: 12-28-2003, 11:55 PM
  4. Thanks Stoned_Coder! ALT key works!!
    By johnnyd in forum C Programming
    Replies: 0
    Last Post: 03-11-2002, 10:39 AM
  5. Capturing ALT in C
    By johnnyd in forum C Programming
    Replies: 2
    Last Post: 03-10-2002, 10:03 PM