Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help with OnKillFocus

Help with OnKillFocus

Scheduled Pinned Locked Moved C / C++ / MFC
c++game-devhelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    John Cruz
    wrote on last edited by
    #1

    i wrote a simple game in MFC and when someone has won or lose the game i want to kill the focus and display a messagebox saying you have won/lose... can i use OnKillFocus() to do that? i did that but it will only display the messagebox when i minimize the window or point on another window. Any suggestions or anything on what am doing wrong??? ... anyways, thank your for your help in advance....

    J D 2 Replies Last reply
    0
    • D Derek Waters

      OnKillFocus is a handler for WM_KILLFOCUS, which is sent to a window when it loses the focus. That's why it's called when you minimise or point to another window (as your game's window loses the focus). The change the window that has the focus, use SetFocus(). If you create a message box, that will by default obtain the focus, so your game will lose it. I don't think you need to worry about focus at all in this circumstance, you just need to:

      if (game_is_won)
      {
      MessageBox(NULL, _T("Game over, dude!"), _T("MyGame"), MB_OK);
      }

      ------------------------ Derek Waters derek@lj-oz.com

      J Offline
      J Offline
      John Cruz
      wrote on last edited by
      #2

      Oh, ok thank you very much Derek :)

      1 Reply Last reply
      0
      • J John Cruz

        i wrote a simple game in MFC and when someone has won or lose the game i want to kill the focus and display a messagebox saying you have won/lose... can i use OnKillFocus() to do that? i did that but it will only display the messagebox when i minimize the window or point on another window. Any suggestions or anything on what am doing wrong??? ... anyways, thank your for your help in advance....

        J Offline
        J Offline
        Joaquin M Lopez Munoz
        wrote on last edited by
        #3

        OnKillFocus is used to perform whatever action you please when the window has lost the focus. To make a window lose its focus, set it elsewehere with SetFocus or SetForegroundWindow. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        1 Reply Last reply
        0
        • J John Cruz

          i wrote a simple game in MFC and when someone has won or lose the game i want to kill the focus and display a messagebox saying you have won/lose... can i use OnKillFocus() to do that? i did that but it will only display the messagebox when i minimize the window or point on another window. Any suggestions or anything on what am doing wrong??? ... anyways, thank your for your help in advance....

          D Offline
          D Offline
          Derek Waters
          wrote on last edited by
          #4

          OnKillFocus is a handler for WM_KILLFOCUS, which is sent to a window when it loses the focus. That's why it's called when you minimise or point to another window (as your game's window loses the focus). The change the window that has the focus, use SetFocus(). If you create a message box, that will by default obtain the focus, so your game will lose it. I don't think you need to worry about focus at all in this circumstance, you just need to:

          if (game_is_won)
          {
          MessageBox(NULL, _T("Game over, dude!"), _T("MyGame"), MB_OK);
          }

          ------------------------ Derek Waters derek@lj-oz.com

          J 1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups