투명 이미지 버튼

Posted by 빵빵빵
2009/04/30 13:49 전산(컴퓨터)/Mobile-CE&PPC



출처 : http://www.codeproject.com/ce/UniButtonDemo.asp?df=100&forumid=249337&exp=0&select=1317158

Universal Button for Pocket PC

사용자 삽입 이미지


Introduction
I tried to find a ready to use button class that would work with Pocket PC and look better than the dull Microsoft buttons. I thought, it would be very easy to find one. Well, it didn't work out. The best code I could find still required a lot of modifications to meet my expectations.

The objectives were.... Well, let's take a look at the list of features.

Features
Owner drawn button class.
Fully transparent option.
Transparent bitmap support for up and down buttons.
Plain or 3D text on top of the button.
WAV file association with the button.
These are the basic requirements that allow you to make simple and professionally looking/acting buttons.

Using the code
Add UniButton.cpp and UniButton.h to the project.
Add #include "UniButton.h" to xxxxxxDlg.h file or wherever required.
Add a background bitmap to the resources and a member variable m_hBmpBkgnd as a handle to the bitmap. Load the bitmap and assign the result to handle in OnInitDialog(). This member variable value will be later passed to the UniButton class. Draw the background in OnPaint().
Add buttons to the dialog resources as desired. For each button, add a member variable of CButton type using the Class Wizard. In the xxxxxDlg.h file, replace CButton type with CUniButton. In the resource editor, check the "Owner Draw" property.
Add the required bitmaps to the resources. For instance, IDB_BITMAP_BTNUP and IDB_BITMAP_BTNDOWN.
All the button configurations are done in OnInitDialog() using the public member functions of CUniButton class. This is where the bitmap handle m_hBmpBkgnd is passed to CUniButton. The reason it is done this way is to minimize memory usage due to multiple copies of the background.
Public methods
All these methods are self-explanatory. A few of them are listed below:



Details
When CUniButton is created, the availability of WAV support is done automatically. The main function can check the availability by calling WavIsSipported() before calling LoadWAV(). However, since LoadWAV() does similar checking itself, it is safe to call it without prior checking.

LoadWAV() has two parameters. fileName specifies the path to the WAV file. loadMEM, if true, will load the WAV file into the memory buffer therefore making it faster at the expense of memory used. When it is false, each time the file is to be played, the buffer will be created and the the WAV file will be copied into it, and then played. This will be slower but it requires less memory.

Transparency, in this class, has two meanings. When transparency is set with SetTransparent(TRUE) button bitmaps are ignored and the button is drawn with a background. When transparency is off button bitmaps are used. Although, it might sound confusing they are painted with transparency on. The bitmap's color (255,255,255) - white will be made transparent. Transparent color can be changed with SetTranspColor().

In order to try out the included Test.wav file it has to be placed in the "My Device" directory. Since, I was unable to figure out how to do it with an emulator I tested the sound on the actual device. The pre-built demo can be downloaded from here.

Misc
This code is provided "AS IS" without any warranties and for non-commercial use only. For all questions, please contact Advatronix.

History
12/25/2005: Version 1.0 - Initial release.
 
License
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author
advatronix
 

2009/04/30 13:49 2009/04/30 13:49

이 글에는 트랙백을 보낼 수 없습니다