Solved

Full screen MFC application

Posted on 2004-10-07
7
1,610 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
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Title # Comments Views Activity
Need a Shell script to start a service checking the port 6 52
bobThere java chalenge 45 94
only14 challenge 19 81
abstract class with all non abstract mentods 6 80
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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