Solved

Full screen MFC application

Posted on 2004-10-07
7
1,609 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replacement selected text 2 62
if loop in java 3 142
Doc'in system (example?) BA 7 111
Increment column based of a FK 8 23
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 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