Export (0) Print
Expand All
Expand Minimize

ATLBUTTON Attributes Sample: Demonstrates a Button with Bitmaps for Different States 

Download sample

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 noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

Building and Running the Sample

To build and run this sample

  1. Open the solution file atlbutn.sln.

  2. From the Build menu, click Build Solution.

  3. 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.

  4. 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.

  5. Note how the image displayed in the control changes if the pointer hovers over it, or if the control is clicked.


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


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


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.

See Also

Other Resources

ATL Attributes Samples

Community Additions

© 2014 Microsoft