以 STATIC TEXT 控件,写个点击 忘记密码 为例:
头文件(.h)中:
COMMAND_ID_HANDLER(IDC_STATIC_FORGETPWD, OnClickForgetPwd)
MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnCtlColor)
LRESULT OnCtlColor(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle);
LRESULT OnClickForgetPwd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
.cpp文件中:
LRESULT CLoginPDDlg::OnCtlColor(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle)
{
HDC hDC = (HDC)wParam;
HWND hWnd = (HWND)lParam;
if(hDC != NULL && hWnd != NULL && ::GetDlgCtrlID(hWnd) == IDC_STATIC_FORGETPWD)
{
::SetBkMode(hDC, TRANSPARENT);
::CreatePen(PS_SOLID, 1, ::SetTextColor(hDC, RGB(0, 0, 255))); //设置文本颜色为蓝色
return (LRESULT)(::GetStockObject(HOLLOW_BRUSH));
}
return 0;
}
LRESULT CLoginPDDlg::OnClickForgetPwd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CAuthStringDlg oAuthStringDlg;
return oAuthStringDlg.DoModal();
}