Click here to Skip to main content
15,886,689 members
Articles / Mobile Apps / Windows Mobile

Wifi scanner + custom MFC controls

Rate me:
Please Sign up or sign in to vote.
4.78/5 (29 votes)
30 Jul 2007CPOL16 min read 234.2K   10.2K   146  
A Wifi scanner with custom slider, tab control, buttons and checkboxes
//////////////////////////////////////////////////////////////////////////
//
// CCustomButton - Win32/WinCE/PocketPC compatible button-based controls
//
// Coded by dzolee
// http://dzolee.blogspot.com
//
//////////////////////////////////////////////////////////////////////////

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <afxwin.h>

//just in case
#ifndef RGB_AVERAGE
#define RGB_AVERAGE(a, b)   ( ((((a) ^ (b)) & 0xfffefefeL) >> 1) + ((a) & (b)) )
#endif

#ifndef BS_TYPEMASK
	#define BS_TYPEMASK 0x0fL
#endif

//basic buttom types
enum ButtonType
{
	btCustomButton=0,
	btCustomRadio,
	btCustomCheckBox,
	btCustomGroup
};

//custom button additional flags
#define	bfNone			0
#define bfMask			15		//mask value that contains all flags
#define bfTextLeft		1
#define bfTextRight		2
#define bfTextTop		4
#define bfTextBottom	8
#define bfHGradient		16		//horizontal gradient coloring

/////////////////////////////////////////////////////////////////////////////
class CCustomButton : public CButton
{
	DECLARE_DYNAMIC(CCustomButton)
public:
	CCustomButton();
	virtual ~CCustomButton();
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDIS);

private:
	bool m_bTransparent;
	bool m_bFlat;
	bool m_bHGradient;
	bool m_bPressed;
	bool m_bDisabled;
	bool m_bIsGroup;

	COLORREF m_crBkgIdle;
	COLORREF m_crTxtIdle;
	COLORREF m_crBkgPressed;
	COLORREF m_crTxtPressed;
	COLORREF m_crHGStart;
	COLORREF m_crHGEnd;
	COLORREF m_crFrame;

	HANDLE m_hBmpActive;		//bitmap handle
	HANDLE m_hBmpInactive;		//bitmap handle
	DWORD m_dwBmpW;				//bitmap width
	DWORD m_dwBmpH;				//bitmap height
	DWORD m_cfFlags;			//framework flags
	DWORD m_ctType;

	CString m_strCaption, m_strActiveCaption;

	bool RegisterCustomClass();

	//flicker-free drawing
	CDC m_DrawDC;
	CBitmap m_DrawBitmap;
	HGDIOBJ m_hOldDCBmp;	

	//custom font support
	HFONT m_hCustomFont;

	// Generated message map functions
protected:
	virtual void PreSubclassWindow();
	//push button drawing
	void DrawPB(CDC* pDC, CRect* pRect);
	void DrawPBBorder(CDC* pDC, CRect* pRect);

	//radio button/checkbox drawing
	void DrawRBCB(CDC* pDC, CRect* pRect);

	//group box drawing
	void DrawGB(CDC* pDC, CRect* pRect);

	//DrawText() flag from button style
	DWORD GetDTFlag(DWORD dwStyle);

	//gradient drawing
	void DrawGradient(CDC *pDC);

	//display BMP
	void DisplayTransparentBMP(CDC *pDestDC, HBITMAP hBmp, DWORD dwW, DWORD dwH, int nX, int nY);

	//color util
	COLORREF OffsetColor(COLORREF crColorIn, double dOffs);

	//{{AFX_MSG(CCustomButton)
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg LRESULT OnBMSetCheck(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnBMGetCheck(WPARAM wParam, LPARAM lParam);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
public:
	void SetCaption(CString strCaption, CString strActiveCaption = _T(""));
	void SetFlags(DWORD dwFlags);
	void SetBitmaps(HBITMAP hBmpInactive, HBITMAP hBmpActive = NULL);

	void SetBkgIdleColor(COLORREF crBkgIdle);
	void SetBkgActiveColor(COLORREF crBkgActive);
	void SetFrgIdleColor(COLORREF crFrgIdle);
	void SetFrgActiveColor(COLORREF crFrgActive);
	void SetGradientColors(COLORREF crStart, COLORREF crEnd);
	void SetFrameColor(COLORREF crFrame);
	void SetFont(HFONT hFont);
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Hungary Hungary
I'm a 29-year old software developer. I began programming on a ZX Spectrum many years ago. I've programmed a number of high level languages (Basic, Pascal, C/C++, Java, Php, Perl, C#). I also like reverse-engineering and assembler programming.
I'm interested in handheld devices programming, especially Windows Mobile devices.

Comments and Discussions