ATLBUTTON Attributes Sample: Demonstrates a Button with Bitmaps for Different States
The ATLBUTTON attributes sample creates a button that displays itself with one of three different bitmaps, depending on its state. The button has a bitmap for the unpushed state, the hover state (when the mouse moves over the button), and the pushed state. Default bitmaps are included with the sample, but you can override these properties to use your own bitmaps.
This sample also demonstrates the use of several IDL, COM, and compiler attributes. The dispinterface attribute is used to place the dispatch interface _ATLButton in the atlbutn.idl file. The propputref attribute is used to allow references to be used instead of values in the PictureStatic, PictureHover, and PicturePush functions. The version attribute is demonstrated, among other commonly used attributes.
Security Note |
---|
This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties. |
To get samples and instructions for installing them:
To access samples from Visual Studio
On the Help menu, click Samples.
By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.
- For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.
Building and Running the Sample
To build and run this sample
Open the solution file atlbutn.sln.
From the Build menu, click Build Solution.
Open the ActiveX Control Test Container and insert the control (CAtlButton Object). For details on accessing Test Container and using it to test a control, see Testing Properties and Events with Test Container.
Open the Properties dialog box for the control, then associate an image with each of the listed properties, by browsing to the sample folder, selecting a BMP file, and clicking Apply.
Note how the image displayed in the control changes if the pointer hovers over it, or if the control is clicked.
Attributes
This sample uses the following attributes:
coclass, default, dispinterface, dll, dual, event_source, helpstring, id, implements_category, in, module, name, object, out, pointer_default, progid, propget, propput, propputref, registration_script, retval, support_error_info, uuid, version, vi_progid
Keywords
This sample uses the following keywords:
Apartment; ATLTRACE; AtlWaitWithMessageLoop; BEGIN_COM_MAP; BEGIN_CONNECTION_POINT_MAP; BEGIN_MSG_MAP; BEGIN_OBJECT_MAP; BEGIN_PROPERTY_MAP; CComCoClass; CComControl; CComControl::FireViewChange; CComControl::InPlaceActivate; CComModule::GetClassObject; CComModule::GetLockCount; CComModule::Init; CComModule::RegisterServer; CComModule::Term; CComModule::UnregisterServer; CComObjectRoot; CloseHandle; CoGetInterfaceAndReleaseStream; CoInitialize; COleControl::OnClick; COM_INTERFACE_ENTRY; COM_INTERFACE_ENTRY_IMPL_IID; CoMarshalInterThreadInterfaceInStream; CONNECTION_POINT_ENTRY; CProxy_ATLButton; CreateDIBPalette; CreatePalette; CreateThread; CTimer; DECLARE_HANDLE; DECLARE_REGISTRY_RESOURCEID; DIBNumColors; DisableThreadLibraryCalls; DLL_PROCESS_DETACH; END_COM_MAP; END_CONNECTION_POINT_MAP; END_MSG_MAP; END_OBJECT_MAP; END_PROPERTY_MAP; GetCursorPos; GetFileSize; GetWindow; GlobalAlloc; GlobalFree; GlobalLock; GlobalSize; GlobalUnlock; IConnectionPointContainerImpl; IConnectionPointImpl; IDispatchImpl; IObjectSafetyImpl; IOleControlImpl; IOleInPlaceActiveObjectImpl; IOleInPlaceObjectWindowlessImpl; IOleInPlaceObjectWindowlessImpl::InPlaceDeactivate; IOleObjectImpl; IPersistPropertyBagImpl; IPersistStreamInitImpl; IProvideClassInfo2Impl; IViewObjectExImpl; LPLOGPALETTE; MESSAGE_HANDLER; OBJECT_ENTRY; PaintDIB; PaletteSize; PROP_ENTRY; PtInRect; PutImage; ReadDIBFile; ReadFile; RealizePalette; ScreenToClient; SelectPalette; SetDIBitsToDevice; SetStretchBltMode; Sleep; StretchDIBits; TimerOff; TimerOn; Unlock; USES_CONVERSION
Note
Some of the samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.