Conclusion: Little VC knowledge!

Source: Internet
Author: User

(61) Why is the menu item still disabled even after the enablemenuitem menu item is called?
You need to set cframewnd: m_bautomenuenable to false. If the data member is true (default), the Work box will automatically Disable menu items without on_update_command_ui or on_command.
// Disable MFC from automatically disabling menu items.
M_bauomenuenable = false
// Now enable the menu item.
Cmenu * pmenu = getmenu ()
Assert_valid (pmenu)
Pmenu-> enablemenuitem (id_menu_item, mf_bycommand | mf_enabled)
(62) how to add a menu item to the System Menu
To add a menu item to the system menu, perform the following three steps:
First, use the resource symbols Dialog (select resource symbols... in the View menu to display the dialog) to define the menu item ID, which should be greater than 0x0f and less than 0xf000;
Next, call cwnd: getsystemmenu to obtain the pointer of the System menu and call cwnd: appendmenu to add the menu item to the menu. In the following example, add two new
Int cmainframe: oncreate (maid)
{
...
// Make sure system menu item is in the right range.
Assert (idm_mysysitem & 0xfff0) = idm_mysysitem)
Assert (IDM-MYSYSITEM <0xf000)
// Get pointer to system menu.
Cmenu * psysmenu = getsystemmenu (false)
Assert_valid (psysmenu)
// Add a separator and our menu item to system menu.
Cstring strmenuitem (_ T ("new menu item "))
Psysmenu-> appendmenu (mf_separator)
Psysmenu-> appendmenu (mf_string, idm_mysysitem, strmenuitem)
...
}
Now, when selecting the system menu item, the user should perform detection. Use classwizard to process the wm_syscommand message and check the NID parameter of the user menu:
Void cmainframe: onsyscommand (uint NID, lparam)
{
// Determine if our system menu item was selected.
If (NID & 0xfff0) = idm_mysysitem)
{
// Todo-Process System menu item
}
Else
Cmdiframewnd: onsyscommand (NID, lparam)
}
Finally, a well-designed UI application should display a help message in the status bar when the system menu item is highlighted, this can be achieved by adding an entry to the string table containing the system menu base ID.
(63) how to determine the number of menu lines occupied by top-level menus
This can be achieved through simple subtraction and division. First, you need to calculate the height of the main box window and the customer area. Second, subtract the height of the customer area, box border, and title from the height of the main box window. Finally, divide it by the height of the menu bar. In the following example, a member function is used to calculate the number of lines occupied by the Main Box menu.
Int cmainframe: getmenurows ()
{
Crect rcframe, rcclient
Getwindowrect (rcframe)
Getclientrect (rcclient)
Return (rcframe. Height ()-rcclient. Height ()-: getsystemmetrics (sm_cycaption)-(: getsystemmetrics (sm_cyframe) * 2)/: getsystemmetrics (sm_cymenu)
}
(64) how to determine the color of the system display element in the user environment
Call the SDK function getsyscolor to obtain the color of a specific display element. The following example shows how to set the title Color of the window by calling the function cmainframewnd: onncpaint In the MFC function.
Void cminiframewnd: onncpaint ()
{
...
DC. settextcolor (: getsyscolor (m_bactive? Color_captiontext: color_inactivecaptiontext ))
...
(65) How to query and set System Parameters
We have introduced the SDK function systemparametersinfo in the Windows 3.1 SDK. You can call this function to query and set system parameters, such as the repeat rate setting of buttons, the delay time of double-clicking the mouse, the icon font, and the desktop overlay bitmap.
// Create a font that is used for icon titles.
Logfont stfont
: Systemparametersinfo (spif_geticontitlelogfont, sizeof (logfont), & stfont, spif_sendwininichange)
M_font.createfontindirect (& stfont)
// Change the wallpaper to leaves.bmp.
: Systemparametersinfo (spi_set1_wallpaper, 0, _ T ("forest.bmp"), spif_updateinifile)
(66) how to determine the current screen resolution
Call the SDK function getsystemmetrics to retrieve information about Windows display, such as the title size, boundary size, and scroll bar size.
// Initialize csize object with screen size.
Csize sizescreen (getsystemmetrics (sm_cxscreen ),
Getsystemmetrics (sm_cyscreen ))
(67) how to use a predefined windows cursor
Call cwinapp: loadstandardcursor and send the cursor identifier.
Bool csampledialog: onsetcursor (cwnd * pwnd,
Uint nhittest, uint
Message)
{
// Display wait cursor if busy.
If (m_bbusy)
{
Setcursor (afxgetapp ()-> loadstandardcursor (idc_wait ))
Return true
}
Return cdialog: onsetcursor (pwnd. nhittest, message)
}
(68) how to retrieve the task list used by the original Task Manager Application
The previous Task Manager application displays the list of top-level windows. To display the list, the window must be visible, contain a title, and cannot be owned by other windows. You can call cwnd: getwindow to retrieve the list of top-level windows. Call iswindowvisible, getwindowtextlength, and getowner to determine whether the window should be in the list. In the following example, the title of the TaskManager window is filled in the list.
Void gettadklist (clistbox & List)
{
Cstring strcaption
// Caption of window.
List. resetcontent ()
// Clear list box.
// Get first window in window list.
Assert_valid (afxgetmainwnd ())
Cwnd * pwnd = afxgetmainwnd ()-> getwindow (gw_hwndfirst)
// Walk window list.
While (pwnd)
{
// I window visible, has a caption, and does not have an owner?
If (pwnd-> iswindowvisible ()
& Pwnd-> getwindowtextlength ()
&&! Pwnd-> getowner ())
{
// Add caption o window to list box.
Pwnd-> getwindowtext (strcaption)
List. addstring (strcaption)
}
// Get next window in window list.
Pwnd = pwnd-> getwindow (gw_hwndnext)
}
}
(69) How to Determine windows and Windows System Directories
There are two SDK functions to complete this function. Getwindowsdirectory and getsystemdirectory. The following example shows how to use these two functions:
Tchar szdir [max_path]
// Get the full path of the Windows directory.
: Getwindowsdirectory (szdir, max_path)
Trace ("Windows Directory % s/n", szdir)
// Get the full path of the Windows System directory.
: Getsystemdirectory (szdir, max_path)
Trace ("Windows System directory % s/n", szdir)
(70) Where to create a temporary file
Call the SDK function gettempath to determine the directory of the temporary file. This function first detects the TMP environment variable for the temporary path: If the TMP environment variable is not specified, check the TMP environment variable and return it to the current directory. The following example shows how to create a temporary file.
...
// Get unique temporary file.
Cstring strfile
Getuniquetempname (strfile)
Try
{
// Create File and write data. Note that file is closed
// In the destructor of the cfile object.
Cfile file (strfile, cfile: modecreate | cfile: modewrite)
// Write data
}
Catch (cfileexception, E)
{
// Error opening file
}
End_catch
...
Void getuniquetempname (cstring & strtempname)
{
// Get the temporary files directory.
Tchar sztemppath [max_path]
DWORD dwresult =: gettemppath (max_path, sztemppath)
Assert (dwresult)
// Create a unique temporary file.
Tchar sztempfile [max_path]
Uint nresult = gettempfilename (sztemppath, _ T ("~ Ex "), 0, sztempfile)
Assert (nresult)
Strtempname = sztempfile
}

Related Article

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.