|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionYesterday I published an article about template today custom item class Back to CTodayWindow classSource containsCTodayWindow class as well. I've made some changes to this class. First of all message handling in TodayWndProc has been improved as well as getting default fonts for text being drawn on today window. These fonts are stored in member variables m_hNormalTodayFont and m_hBoldTodayFont. Default color for these two fonts should be one defined for today custom items and it's stored in member variable m_crTodayText. That's all for CTodayWindow class for now.
BackgroundThe purpose of doing this was to write a class which would be similar to MFC AbstractClass class CTodayOptionsDialog { public: HWND m_hWnd; CTodayOptionsDialog(); CTodayOptionsDialog(HINSTANCE hInstance, CTodayWindow *pToday, BOOL bFullScreen = TRUE); virtual ~CTodayOptionsDialog(); // Get methods HINSTANCE GetInstance() {return m_hInstance;}; BOOL GetFullScreen() {return m_bFullScreen;}; int GetTitleHeight() {return m_nTitleHeight;}; // Set methods void SetInstance(HINSTANCE hInstance) {m_hInstance = hInstance;}; void SetFullScreen(BOOL bFullScreen) {m_bFullScreen = bFullScreen;}; void SetTitle(LPCTSTR lpszTitle, BOOL bRefresh = FALSE); void SetTitle(UINT nID, BOOL bRefresh = FALSE); // Association with option dialog created by system void AssociateWithOptionsDlg(HWND hWnd); void RefreshWindow(); virtual LRESULT CALLBACK TodayOptionsWndProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); protected : // Reference to Today plug-in window CTodayWindow *m_pWndTW; BOOL m_bFullScreen; int m_nTitleHeight; LPCTSTR m_lpszTitle; HINSTANCE m_hInstance; HFONT m_hTitleFont; // Methods for better work with controls HWND ItemHandleFromID(UINT nID); BOOL IsButtonChecked(UINT nID); void CheckButton(UINT nID, BOOL bCheck = TRUE); void CheckRadionButton(UINT nIDFirst, UINT nIDLast, UINT nIDToCheck); virtual void DrawDialogTitle(HDC hDC); virtual void GetDefaultTitleFont(); // Message handlers virtual BOOL OnInitDialog(TODAYLISTITEM *ptli); virtual void OnDestroy(); virtual void OnOK(); virtual void OnCancel(); virtual void OnPaint(HDC hDC); virtual void OnActivate(UINT nState, HWND hWndPrevious, BOOL bMinimized); virtual void OnCommand(UINT nID, UINT nNotifyCode, HWND hWndCtrl); virtual void OnSettingChange(UINT nFlags, LPCTSTR lpszSection); virtual LRESULT OnNotify(UINT nID, NMHDR* pNMHDR); virtual LRESULT OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam); }; Basic class informationAs you can see, I've pre-defined recently used messages into message handlers which are easy-to-use in derived classes. You don't need write anymore huge code in LRESULT CALLBACK TodayOptionsWndProc(HWND hDlg,
UINT uMsg, WPARAM wParam, LPARAM lParam)
This method handles some basic messages and I've defined some virtual methods you can override. From my point of view the most used messages are:
These messages have their own message handlers. Special behavior have following handlers:
Using the codeUsage of this class is very simple. Just derive your own class from BOOL CMyOption::OnInitDialog(TODAYLISTITEM *ptli)
{
BOOL bResult = CTodayOptionsDialog::OnInitDialog(ptli);
CMyToday *pToday = (CMyToday*)m_pWndTW;
CheckButton(IDC_CHECK_SHOW_FIRST, pToday->m_bShowFirst);
CheckButton(IDC_CHECK_SHOW_SECOND, pToday->m_bShowSecond);
CheckButton(IDC_CHECK_SHOW_POWER, pToday->m_bShowPower);
return bResult;
}
void CMyOption::OnOK()
{
CMyToday *pToday = (CMyToday*)m_pWndTW;
pToday->m_bShowFirst = IsButtonChecked(IDC_CHECK_SHOW_FIRST);
pToday->m_bShowSecond = IsButtonChecked(IDC_CHECK_SHOW_SECOND);
pToday->m_bShowPower = IsButtonChecked(IDC_CHECK_SHOW_POWER);
CTodayOptionsDialog::OnOK();
}
Initialization of DLL library and example of connecting today custom item window class to its option dialog class is shown here: static CMyToday* myToday; static CMyOption *myOption; BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) { switch (dwReason) { case DLL_PROCESS_ATTACH : myToday = new CMyToday((HINSTANCE)hModule, _T("MyTodayClass"), _T("MyTodayWnd")); myToday->SetItemHeight(40); myToday->SetIcon(IDI_APP_ICON); myToday->UnregisterTodayClass(); myOption = new CMyOption((HINSTANCE)hModule, myToday, TRUE); myOption->SetTitle(_T("My Today Options"), FALSE); break; case DLL_PROCESS_DETACH : delete myToday; delete myOption; break; } return TRUE; } HWND InitializeCustomItem(TODAYLISTITEM *ptli, HWND hWndParent) { myToday->RegisterTodayClass((WNDPROC)WndProc); myToday->Create(hWndParent, WS_VISIBLE | WS_CHILD); myToday->RefreshWindow(TRUE); return myToday->m_hWnd; } LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { return myToday->TodayWndProc(uMsg, wParam, lParam); } LRESULT WINAPI CustomItemOptionsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { return myOption->TodayOptionsWndProc(hDlg, message, wParam, lParam); } RemarksThese two classes co-working together give developers possibility of writing today custom items in a style "close to" MFC. Someone finds this code useful whereas another doesn't. For basic work with today custom items it's, as I think, enough.
|
||||||||||||||||||||||