Thread: VK_ESCAPE Problem

  1. #1
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215

    VK_ESCAPE Problem

    Hi

    i have an application that creates a new window when the user presses a button. when the user wants to come out of the fullscrenn they press the ESCAPE key and this changes the window back to its orgional state.

    also this ESCAPE key needs to exit the application IF its not in fullscreen mode.

    The problem i have is when the user is in fullscreen and presses ESCAPE it exits the application. or if i dont have the second part it will just exit full screen

    here is the code i am using

    Code:
    if(Key == VK_ESCAPE) // if the user presses the ESCAPE key
    {
     imgImage->Height = ScreenHeight;
     imgImage->Width = ScreenWidth;
     imgImage->Stretch = true;
    
     Form1->BorderStyle = bsToolWindow;
     Form1->Height = 754;
     Form1->Width = 1070;
     Form1->Left = 190;
     Form1->Top = 115;
    
     Panel1->Visible = true;
     Label1->Visible = true;
     Prop->Visible = true;
     Stretch->Visible = true;
     ProgressBar1->Visible = true;
     StatusBar1->Visible = true;
     spOpen->Visible = true;
     spSave->Visible = true;
    
     if(Key == VK_ESCAPE)
     {
     Application->Terminate();
     }
     }
    Can anyone help?

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Recheck your logic:
    Code:
    if(Key == VK_ESCAPE) // if the user presses the ESCAPE key
    {
      if(Key == VK_ESCAPE)
       {
        //will always terminate
       Application->Terminate();
       }
    }
    Alternatively, perhaps you should consider using a different key for a different action? ESC for quitting is a good choice; try using one of the function keys for your display switching.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Like Ken is trying to point out, your second IF statment will return the same as your first, so it's like not even being there.

    Try somthing more like:
    Code:
    if(Key == VK_ESCAPE) // if the user presses the ESCAPE key
    {
     if(bFullscreen)
     {
      bFullscreen = FALSE;
    
      imgImage->Height = ScreenHeight;
      imgImage->Width = ScreenWidth;
      imgImage->Stretch = true;
    
      Form1->BorderStyle = bsToolWindow;
      Form1->Height = 754;
      Form1->Width = 1070;
      Form1->Left = 190;
      Form1->Top = 115;
    
      Panel1->Visible = true;
      Label1->Visible = true;
      Prop->Visible = true;
      Stretch->Visible = true;
      ProgressBar1->Visible = true;
      StatusBar1->Visible = true;
      spOpen->Visible = true;
      spSave->Visible = true;
     }
     else
     {
       Application->Terminate();
     }
    }
    Of course, you need to set bFullscreen to TRUE when the user goes fullscreen.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM