Win32 ÄÜÆ®·Ñ ¼Ó¼º »ç¿ëÇϱâ
C++ developers can make use of Win32 control properties. This week's tip shows an example
using the Windows SendMessage() function.
Using Win32 control properties
Win32 control properties (whether or not exposed by the VCL) are available to C++Builder
developers. You can find out about any additional Win32 subclassed control properties and
methods not exposed by the VCL through Microsoft Win32 SDK help and other help files that ship
with C++Builder.
the following example uses the Windows SendMessage() function to set and get numbers in the
item data property of a combo box, without having to use the VCL's AddObject() function (which,
you may be unhappy to discover, makes you pass numbers as objects).
The example code uses the item data property to keep track of the original order in which items
are added to a combo box before it's sorted. To use this example, just put a ComboBox1 and a
Label1 on a Form1, then enter the following code in the FormShow event:
void __fastcall TForm1::FormShow(TObject *Sender)
{
int Position;
// Load unsorted ComboBox1 items property; store positions in
item data property
Position = ComboBox1->Items->Add("RED");
SendMessage(ComboBox1->Handle, CB_SETITEMDATA, Position, Position);
Position = ComboBox1->Items->Add("WHITE");
SendMessage(ComboBox1->Handle, CB_SETITEMDATA, Position, Position);
Position = ComboBox1->Items->Add("BLUE");
SendMessage(ComboBox1->Handle, CB_SETITEMDATA, Position, Position);
// Sort combobox and show first item, which is BLUE
ComboBox1->Sorted = True;
ComboBox1->ItemIndex = Position = 0; //for this demonstration, reset Position to 0
// Read original position of first item -- always include the unused 0 parameter
Position = SendMessage(ComboBox1->Handle, CB_GETITEMDATA,
ComboBox1->ItemIndex, 0);
// Show results -- If you try this you will see Position is now 2
Label1->Caption = "Although BLUE is now item 0, it was item "
+ (String)Position;
}
For a somewhat more elaborate source code example, download the self-extracting file
itemdata.exe from ftp.cobb.com/cpb/tipcode.
by Kevin Berry, DrBerryND@aol.com |