Example of how VC 123

Source: Internet
Author: User

How to achieve full screen display

Full Screen Display is some Application SoftwareProgramEssential features. For example, when using VC ++ to edit resources such as the Project source file or the editing dialog box, select "viewfull screen" to enter the full screen display status, press the "ESC" key to exit full screen display.

In VC ++ 6.0, Appwizard is used to generate the application framework of the Single-Document Interface by default. Next, we will first discuss how to click the menu item "viewfull screen" to achieve full screen display, and then how to exit the full screen display status after pressing the "ESC" key.

1) Add the following three member variables in the cmainframe class.

PRIVATE:
Windowplacement m_oldwndplacement; // used to save the original window position
Bool m_bfullscreen; // full screen display flag
Crect m_fullscreenrect; // indicates the position of the window when the screen is displayed.

2) edit the menu idr_mainframe in the resource editor. In the View menu bar, add the menu item "full screen ". In its attribute box, Set ID to id_full_screen and caption to "full screen ". You can also add a new tool icon in the toolbar and associate it with the menu item "full screen" to set its id value to id_full_screen.

3) design the full-screen display processing function, and add the response function of the preceding menu item id_full_screen in the cmainframe class. The response function is as follows:

Void cmainframe: onfullscreen ()
{

Getwindowplacement (& m_oldwndplacement );
Crect windowrect;
Getwindowrect (& windowrect );
Crect clientrect;
Repositionbars (0, 0 xFFFF, afx_idw_pane_first, reposquery, & clientrect );
Clienttoscreen (& clientrect );
// Obtain the screen resolution
Int nfullwidth = getsystemmetrics (sm_cxscreen );
Int nfullheight = getsystemmetrics (sm_cyscreen );
// Display the customer area except the control bar in full screen to the (0, 0) to (nfullwidth, nfullheight) area, and (0, 0) and (nfullwidth, nfullheight) expand the difference between the original window and the customer location except the control bar outside the two points to get the window location displayed in full screen
M_fullscreenrect.left = windowrect. left-ClientRect.left;
M_fullscreenrect.top = windows. top-ClientRect.top;
M_fullscreenrect.right = windowrect. right-ClientRect.right + nfullwidth;
M_fullscreenrect.bottom = windowrect. bottom-ClientRect.bottom + nfullheight;
M_bfullscreen = true; // set the full-screen display flag to true.
// Enter the full screen display status
Windowplacement wndpl;
Wndpl. Length = sizeof (windowplacement );
Wndpl. Flags = 0;
Wndpl. showcmd = sw_shownormal;
Wndpl. rcnormalposition = m_fullscreenrect;
Setwindowplacement (& wndpl );

}
 

4) The ongetminmaxinfo function of the cmainframe class is reloaded to provide the location information displayed in full screen mode.

Void cmainframe: ongetminmaxinfo (minmaxinfo far * lpmmi)
{

If (m_bfullscreen)
{

Lpmmi-> ptmaxsize. x = m_fullscreenrect.width ();
Lpmmi-> ptmaxsize. Y = m_fullscreenrect.height ();
Lpmmi-> ptmaxposition. x = m_fullscreenrect.width ();
Lpmmi-> ptmaxposition. Y = m_fullscreenrect.height ();
// The maximum track size must be changed.
Lpmmi-> ptmaxtracksize. x = m_fullscreenrect.width ();
Lpmmi-> ptmaxtracksize. Y = m_fullscreenrect.height ();
}

Cframewnd: ongetminmaxinfo (lpmmi );
}
 

After completing the coding, You can compile fullscreen.exe and select "viewfull screen" or click the toolbar button associated with it to display the full screen. However, you still need to add an operation interface to exit the full screen display status. The following describes how to exit the full screen display status by pressing "ESC.

1) Select cmainframe in classview, right-click it, and select "add member function..." to add the public-type member function endfullscreen. This function will exit the full screen display.

Void cmainframe: endfullscreen ()
{

If (m_bfullscreen)
{// Exit full screen display and restore the original window display
Showwindow (sw_hide );
Setwindowplacement (& m_oldwndplacement );

}

}
 

2) The function endfullscreen can exit the full screen display. The problem is how to call this function after the "ESC" Key is pressed. Because the View class can process messages related to keyboard input (for example, wm_keydown indicates that the user presses a key), we will add the onkeydown function to the View class cfullscreenview for processing the wm_keydown message. If the press Key is "ESC", call the endfullscreen function of the cmainframe class to exit the full screen display.

Void cfullscreenview: onkeydown (uint nchar, uint nrepcnt, uint nflags)
{

If (nchar = vk_escape) // If you press the ESC key
{// Obtain the pointer of the main frame window

Cmainframe * pframe = (cmainframe *) afxgetapp ()-> m_pmainwnd;
// Call the endfullscreen function of the main window class to exit full screen display.
Pframe-> endfullscreen ();

}
Cview: onkeydown (nchar, nrepcnt, nflags );

}
 

Change the window icon and display it in the taskbar

The following two functions can display a task entry to the taskbar and change their icons for each subwindow in the application. It is particularly useful for applications that hide the main window like QQ.

// Function purpose: Change the icon of a window and display it in the taskbar, task switching entry, and task manager.
// Parameter description:
// The Window handle for the hwnd to change the icon
// Hlargeicon 32*32
// The hsmallicon icon is displayed in addition to the task switch bar. the icon is 16*16.
// The icon displayed on hicon, 32*32. It is automatically compressed to 16*16 when it is displayed in other places except the Task Switch bar.
// Note:
// This function is powerless for the mode dialog box.
// If hicon is null, the function does not change the window icon, but displays the original icon in the taskbar,
// Task Switch entry, in the task manager.
// This function displays the icon to the taskbar, Task Switch entry, and,
// In the task manager, the parent window pointer is no longer available after the call is completed.
Bool sendwndicontotaskbar (hwnd, hicon hlargeicon, hicon hsmallicon );
Bool sendwndicontotaskbar (hwnd, hicon );

Bool cuiapp: sendwndicontotaskbar (hwnd, hicon hlargeicon, hicon hsmallicon)
{
Bool ret = true;
Assert (hwnd );
If (! : Iswindow (hwnd ))
Return false;
// Obtain the window pointer
Cwnd * pwnd;
Pwnd = pwnd-> fromhandle (hwnd );
Assert (pwnd );
If (! Pwnd)
Return false;
// Set the parent window to null
If (pwnd-> getparent ())
If (: setwindowlong (hwnd, gwl_hwndparent, null) = 0)
Return false;

If (! (Pwnd-> modifystyle (null, ws_overlappedwindow )))
Ret = false;
// Set the window icon
If (hlargeicon & hsmallicon)
{
Pwnd-> seticon (hsmallicon, false );
Pwnd-> seticon (hlargeicon, true );
}

Return ret;
}

Bool cuiapp: sendwndicontotaskbar (hwnd, hicon)
{
Bool ret = true;
Assert (hwnd );
If (! : Iswindow (hwnd ))
Return false;
// Obtain the window pointer
Cwnd * pwnd;
Pwnd = pwnd-> fromhandle (hwnd );
Assert (pwnd );
If (! Pwnd)
Return false;
// Set the parent window to null
If (pwnd-> getparent ())
If (: setwindowlong (hwnd, gwl_hwndparent, null) = 0)
Return false;

If (! (Pwnd-> modifystyle (null, ws_overlappedwindow )))
Ret = false;
// Set the window icon
Pwnd-> seticon (hicon, true );
Pwnd-> seticon (hicon, false );

Return ret;
}

 

How to hide the display of an application on the taskbar

For cframewnd, you can modify the window style in the precreatewindow () function.

Bool cmainframe: precreatewindow (createstruct & CS)
{
CS. Style | = ws_popup; // make the main window invisible
CS. dwexstyle | = ws_ex_toolwindow; // The task button is not displayed.
Return cframewnd: precreatewindow (CS );
}

For other windows, you can use modifystyle () and modifystyleex () to modify the style of the window before it is created and showwindow.

How to control the maximum and minimum size of the window frame?

To control the maximum and minimum sizes of a frame, you need to do two things.

Step 1: process the message wm_getminmaxinfo in the inheritance class of cframewnd. The minmaxinfo structure sets the limitation of the entire window class. Therefore, remember to consider the size of the toolbar, scroll bar, and so on.

// Maximum and minimum pixel points-Example
# Define Minx 200
# Define min 300
# Define Maxx 300
# Define Maxy 400

Void cmyframewnd: ongetminmaxinfo (minmaxinfo far * lpmmi)
{
Crect rectwindow;
Getwindowrect (& rectwindow );

Crect rectclient;
Getclientrect (& rectclient );

// Get offset of toolbars, scrollbars, etc.
Int nwidthoffset = rectwindow. Width ()-rectclient. Width ();
Int nheightoffset = rectwindow. Height ()-rectclient. Height ();

Lpmmi-> ptmintracksize. x = Minx + nwidthoffset;
Lpmmi-> ptmintracksize. Y = miny + nheightoffset;
Lpmmi-> ptmaxtracksize. x = Maxx + nwidthoffset;
Lpmmi-> ptmaxtracksize. Y = Maxy + nheightoffset;
}

 

Step 2: remove the ws_maximizebox message from the precreatewindow function of the cframewnd inheritance class. Otherwise, you will not get the expected result when maximizing the value.

Bool cmyframewnd: precreatewindow (createstruct & CS)
{
CS. Style & = ~ Ws_maximizebox;
Return cframewnd: precreatewindow (CS );
}

 

How do I modify the background color of a frame window?

The customer zone of the MDI window is covered by another window owned by the frame window. To change the background color of the frame window, you only need the background color of this customer area. You must process the wm_erasebknd message by yourself. The following is the procedure:

Create a class inherited from the cwnd class and call it javasiclient;

Add the cmdiclient variable to cmdiframewnd.Code)

# Include "mdiclient. H"
Class cmainframe: Public cmdiframewnd
{
...
Protected:
Cmdiclient m_wndmdiclient;
}

Overload cmdiframewnd: oncreateclient. The following code is used. Note the subclasswindow ();

Bool cmainframe: oncreateclient (lpcreatestruct lpcs, ccreatecontext * pcontext)
{
If (cmdiframewnd: oncreateclient (lpcs, pcontext ))
{
M_wndmdiclient.subclasswindow (m_hwndmdiclient );
Return true;
}
Else
Return false;
}

Finally, add the function for processing wm_erasebkgnd to cmdiclient.

How can I change the background color of a view?

To change the cview, the background color of the cframewnd or cwnd object needs to process the wm_erasebkgnd message. The following is an example code:

Bool csampleview: onerasebkgnd (CDC * PDC)
{

// Set the brush to the desired background color
Cbrush backbrush (RGB (255,128,128 ));

// Save the old brush
Cbrush * poldbrush = PDC-> SelectObject (& backbrush );
Crect rect;
PDC-> getclipbox (& rect );

// Draw the desired Region
PDC-> patblt (rect. Left, rect. Top, rect. Width (), rect. Height (), patcopy );
PDC-> SelectObject (poldbrush );

Return true;

}
 

To change the background color of the cfromview inheritance class, the following is an example code:

Hbrush cmyformview: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor)
{

Switch (nctlcolor)
{

Case ctlcolor_btn:
Case ctlcolor_static:
{

PDC-> setbkmode (transparent );
// Do not add any processing or set the background to transparent

}
Case ctlcolor_dlg:
{

Cbrush * back_brush;
Colorref color;
Color = (colorref) getsyscolor (color_btnface );
Back_brush = new cbrush (color );
Return (hbrush) (back_brush-> m_hobject );

}

}

Return (cformview: onctlcolor (PDC, pwnd, nctlcolor ));

}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.