Solved

Full screen MFC application

Posted on 2004-10-07
7
1,611 Views
Last Modified: 2013-11-20
Hi everybody,

I'm developping an application with MFC (VC 6.0), and I'd like that the main modal of my application to be in full screen, and I'd like that it works for different screen size.
For the moment I use the  following code:

// Put window on top and expand it to fill screen
      int cx, cy;
    HDC dc = ::GetDC(NULL);
      cx = GetDeviceCaps(dc,HORZRES) +
        GetSystemMetrics(SM_CXBORDER);
    cy = GetDeviceCaps(dc,VERTRES) +
        GetSystemMetrics(SM_CYBORDER);
    ::ReleaseDC(0,dc);

    ::SetWindowPos(m_hWnd, HWND_TOPMOST,
        -(GetSystemMetrics(SM_CXBORDER)+1),
        -(GetSystemMetrics(SM_CYBORDER)+1),
        cx+1,cy+1, SWP_NOZORDER);

But it just expand the window....
Moreover I'd like that this main window (the window which appears when you launch the program) to be not moved by clicking on the menu bar and moving the mouse...  
Hope you see what I mean.
Thanky by advance.
Vincent.
0
Comment
Question by:vinceTrace
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 12247897
Do you mean maximised?
If so in the InitInstance
m_pMainWnd->ShowWindow(SW_MAXIMIZED);
0
 

Author Comment

by:vinceTrace
ID: 12248078
In the InitInstance of MyApp.cpp, I have put:

m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);

like this
                ...
                int nResponse = dlg.DoModal();
      m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
                ...

and the window is not maximised and I've an error after I close the application...
Could you tell me what I've done wrong?
Thanks
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 12248756
In that case you need the ShowWindow(SW_MAXIMIZED) in the OnInitDialog (after the CDialog::OnInitDialog()) of the dialog and remove the line
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vinceTrace
ID: 12249165
Thanks, now it works. I'd like to know if there is a way to center the window in the screen. For the moment my window is in the left-top corner, and i'd like to change the distance between the items of my window to fit with different screen sizes... A kind of scale change if you see what I mean...
I'd like that a button on the right down corner of my window to be at the right down corner of the screen, even if the user screen is bigger than the original size of my dialog...
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 80 total points
ID: 12249657
Trap the OnSize message (that has the params for the new size).
GetDlgItem(IDC_XXX)->SetWindowPos(NULL, left, top, 0,0, SWP_NOZORDER|SWP_NOSIZE);
will just move a control.

GetWindowRect, GetClientRect and ScreenToClient, ClientToScreen are other functions to look up in help.
0
 
LVL 4

Expert Comment

by:Skonen
ID: 12250748
To center the window on the desktop. Within your OnInitDialog message handler, insert this line:

CenterWindow(CWnd::GetDesktopWindow());
0
 
LVL 49

Assisted Solution

by:DanRollins
DanRollins earned 45 total points
ID: 12268271
Andy is correct... you will need to write special (custom) code to move and resize the controls... MFC does not provide that capability.  

If there are just a few controls, you can just move and resize them "manually" one-at-a-time in the OnSize handler.  If you have *lots* of controls, you may want to use a scheme where you keep track of the positions and sizes of each control in an array, and then cycle through the array moving and resizing them in turn.

=-=-=-=-=-=-=-=-=-=-=-
By the way, I always caustion programmers against forcing their window to cover the entire screen.  There are *very* few cases where this is advisable, but novice programmers tend to always want to do it.  Sure, your program is very important... to YOU... but your user may have several other programs, web browsers, etc. open and those other programs may be very important ... to HIM :-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question