Jump to content





Recent Status Updates

  • Photo
      16 Apr
    Kadence

    If you're reading this, you're on my profile and I know you're on my profile because I'm probably viewing yours.

    Show comments (6)
  • Photo
      10 Apr
    Poe

    Finally (and hopefully) i'm getting a team together that knows a little of this and a little of that; and maybe all my open source projects that are half written can begin to be released. :)

View All Updates
Photo
- - - - -

Dual Monitors and the window position

Managed C++ form

  • Please log in to reply
1 reply to this topic

#1 RobSoftware

RobSoftware

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 141 posts

Posted 15 June 2006 - 04:15 AM

I ran into this problem recently as I just got dual monitors. If you save the location of your program and then load it once the user restarts you need to have code to keep it inside the visible window if they remove the dual monitor. Without this code the user will load your program and never be able to see it.

I took it from a C# sample originially and converted it to C++. It is easy to convert back to C#. Here is the code:

// Make sure the form is visible		
System::Windows::Forms::Screen^ currentScreen  = System::Windows::Forms::Screen::FromHandle(this->Handle);
						
// Ensure top visible
if((this->Top < currentScreen->Bounds.Top) || ((this->Top + this->Height) > (currentScreen->Bounds.Top + currentScreen->Bounds.Height)))	
{
    this->Top = currentScreen->Bounds.Top;
}

// Ensure at least 60 px of Title Bar visible
if(((this->Left + this->Width - 60) < currentScreen->Bounds.Left) || ((this->Left + 60) > (currentScreen->Bounds.Left + currentScreen->Bounds.Width))) 
{
    this->Left = currentScreen->Bounds.Left;
}


Add this just under where the location is restored.

Having a laptop and moving from dual monitor to single monitor often I've noticed several programs have this flaw. It makes the program ...... bad (for lack of a better term). If you save the location you should use this code to restore it.
  • 0

#2 Guest_NeedHelp_*

Guest_NeedHelp_*
  • Guest

Posted 15 June 2006 - 08:02 AM

Yeah, it is kind of cheesy when you load a program and can't see it. I would suggest that anyone using window positions (saving and reloading) use code to protect against dual-monitor.
  • 0





Also tagged with one or more of these keywords: Managed C++, form