OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Identifying a Gadget

You can identify a gadget by using the GetId function to access its identifier.

GetId takes no parameters and returns an int, the gadget identifier. The identifier comes from the value passed in as the first parameter of the TGadget constructor.

There are a number of uses for the gadget identifier:

  • You can use the identifier to identify a particular gadget. If you have a large number of gadgets in a gadget window, the easiest way to determine which gadget is which is to use the gadget identifier.
  • You can set the identifier to the desired event identifier when the gadget is used to generate a command. For example, a button gadget used to open a file usually has the identifier CM_FILEOPEN.
  • You can set the identifier to a string identifier if you want to display a text string in a message bar or status bar when the gadget is pressed. For example, suppose you have a string identifier named IDS_MYSTRING that describes your gadget. You can set the gadget identifier to IDS_MYSTRING. Then, assuming your window has a message or status bar and you have turned menu tracking on, the string IDS_MYSTRING is displayed in the message or status bar whenever you press the gadget IDS_MYSTRING.

These last two techniques are often combined. Suppose you have a command identifier CM_FILEOPEN for the File|Open menu command and a string with the resource identifier CM_FILEOPEN. If you also give the gadget the identifier CM_FILEOPEN, when you press the gadget, the gadget window posts the CM_FILEOPEN event, and the string with the resource identifier CM_FILEOPEN is displayed in the message or status bar.

You can see an illustration of this technique in Step 10 of the Learning ObjectWindows Tutorial manual.

See Also