Set the Check Boxes status of the ListView control

zhaozj2021-02-11  260

Set the Check Boxes status of the ListView control

Aawolf Press: Recently, this property is used in the project, although this article is not very high in MSDN, but for projects that need this property is still a better guidance material. So I will share with you, I hope everyone will continue to pay attention to my column: http://www.9cbs.net/develop/author/netauthor/aawolf/

What you need

· Microsoft Embedded Visual Tools 3.0

· Good Working Knowledge of Microsoft Embedded Visual C

BACKGROUND

When designing a user interface, you often need to give a visible prompt for a series of options. This can be represented by different icons or use a check box control. The Pocket PC ListView control provides built-in Check Box (see Figure).

Figure: Check Boxes Allow Intuitive Selection of ListView Items.

In the Pocket PC SDK, you will find the listview_getcheckstate macro in ListView to allow checking a List item's Check Box status. Unfortunately, the corresponding listview_setcheckstate macro is not included in the header file of Microsoft Visual C , such as Pocket PC 2000 SDK, and Pocket PC 2002 SDK current beta version. This macro is included in the platform SDK and MSDN documents. It will be added to the final version of the Pocket PC 2002 SDK.

If you look at ListView_GetCheckState in the definition in CommCtrl.h, you will see that the Check Box status is saved in the 12bit Item Data.

#define listview_getcheckstate (hwndlv, i) /

(((UINT) (SNDMSG ((hwndlv), LVM_GETITEMSTATE, (WPARAM) I, LVIS_STATEIMAGEMASK)) >> 12) -1)

Adding the Missing Pieces

The logic of ListView_GetCheckState will directly affect the status, setting or cancellation flag of the Check Box directly. Therefore, the listview_setCheckState command can be tracked. Copy and paste this macro to your code, you can work. (Aawolf: This macro has been included in the SDK above the Pocket PC 2002, and it can be used directly)

#ifndef listview_setcheckstate

#define listview_setcheckstate (h, i, f) /

ListView_SetItemState (H, I, IndextOstateImageMask ((f) 1), LVIS_STATEIMASK)

#ENDIF

Note that IndextOstateImageMask moves 12 digits.

#define indextostateImageMask (i) ((i) << 12)

Using the checkboxes

In order to use the ListView's Check Box, you need to set up the LVS_EX_CHECKBOXES style:

ListView_sextendedListViewStyle (Hwndlist, LVS_EX_CHECKBOXES);

This style leaves enough space in the first column of the List, and draws Check Box in front of the text. When you want to set Check Box, you need to call the listView_setCheckState to control the handle, the ITEM index, and the desired state.

ListView_setCheckState (HWndList, Dwindex, (BSTATE? 1: 0));

Similarly, you can get the status of Check Box by calling listview_getcheckstate:

Listview_getcheckstate (hwndlist, dwindex);

Conclusion

The complete execution of this feature is final

Pocket PC SDK

It is effective, which allows your program to get the advantage of visual effects through very simple way.

转载请注明原文地址:https://www.9cbs.com/read-5040.html

New Post(0)