-Windows CE programming (3rd edition)-5.2 Public controls (8)

Source: Internet
Author: User

Save the band LayoutTranslation:Tellmenow

The configurable capabilities of commands with controls pose a problem for programmers. After you rearrange the band, you want the custom layout to be restored at the next startup of the application. By using the following functions, you can easily achieve the goal:
Bool commandbans_getrestoreinformation (hwnd hwndcmdbands, uint uband, lpcommandbandsrestoreinfo pcbr );
This function saves the information of a single band to the commandbandsrestoreinfo structure. This function has two parameters: a command with a control handle and a partition index value to be queried. The following code snippet shows how to query the information of each zone in the Command Belt control.
// Get the handle of the command bands control.
Hwndcb = getdlgitem (hwnd, idc_cmdband );

// Get information for each band.
For (I = 0; I <numbands; I ++ ){
// GET Band index from ID value.
Nband = sendmessage (hwndcb, rb_idtoindex, idb_cmdband + I, 0 );

// Initialize the size field, and get the restore information.
CBR [I]. cbsize = sizeof (commandbandsrestoreinfo );
Commandbands_getrestoreinformation (hwndcb, nband, & CBR [I]);
}

The code above uses the rb_idtoindex message to convert a zone ID into a zone index for commandbands_getrestoreinformation. The data in the structure is usually stored in the system registry. I will explain how to read and write the registry data in Chapter 3 "files and registries.

When the application recovers, it should read the recovery information from the registry and use it when creating commands with controls.
// Restore configuration to a command band.
Commandbandsrestoreinfo CBR [numbands];
Rebarbandinfo RBI;

// Initialize size field.
RBI. cbsize = sizeof (rebarbandinfo );

// Set only style and size fields.
RBI. fmask = rbbim_style | rbbim_size;

// Set the size and style for all bands.
For (I = 0; I <numbands; I ++ ){
RBI. Cx = CBR [I]. cxrestored;
RBI. fstyle = CBR [I]. fstyle;

Nband = sendmessage (hwndcb, rb_idtoindex, CBR [I]. WID, 0 );
Sendmessage (hwndcb, rb_setbandinfo, nband, (lparam) & RBI );
}

// Only after the size is set for all bands can the bands
// Needing maximizing be maximized.
For (I = 0; I <numbands; I ++ ){
If (CBR [I]. fmaximized ){
Nband = sendmessage (hwndcb, rb_idtoindex, CBR [I]. WID, 0 );
Sendmessage (hwndcb, rb_maximizeband, nband, true );
}
}

The above Code assumes that the command Belt control has been created according to the default configuration. In practical applications, the size and style restoration information is used when the control is initially created. In that case, the remaining values are determined based on the status of the fmaximized domain in the commandbandsrestoreinfo structure. The last step in the above Code is made only after all the band areas are created and properly adjusted.

The system has a limit on saving and restoring the layout of a zone, that is, you cannot determine the order of the Zone in the control. A zone index cannot provide reliable information, because after you reschedule the zone several times, the index values are neither consecutive nor in any defined order. The only way to solve this problem is to forcibly arrange the band so that users cannot rearrange the band. You can achieve this by setting the rbs_fixedorder style. This can solve this problem, but if the user wants a different order, it cannot help the user. In the example program at the end of this section, I use the band index value to guess the order. However, this method cannot be guaranteed to be effective.

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.