📄 subject_17005.htm
字号:
<blockquote><p>
回复者:弱兔 回复日期:2002-10-07 14:43:02
<br>内容:我还是不明白,程序在运行中,都是动态的,怎么手动?怎么用classwazd?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:凯凯 回复日期:2002-10-07 16:45:52
<br>内容:先看书,把基本概念搞明白。<BR><BR>TO:Green_Pig<BR>是俺自己做的。如果你要这种革命图像,我倒是有不少。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Norton AntivVirus 回复日期:2002-10-07 17:18:36
<br>内容:To : KK<BR><BR>来几张,看看<BR><BR>mail给我吧,资料中有地址
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:黄飚 回复日期:2002-10-07 17:42:57
<br>内容:1.你从CButton派生一个类,然后在OnNotify里写上你的代码!<BR>CWnd::OnNotify<BR>virtual BOOL CWnd::OnNotify( WPARAM wParam, LPARAM lParam, LRESULT* pResult );<BR><BR>Return Value<BR><BR>An application returns nonzero if it processes this message; otherwise 0.<BR><BR>Parameters<BR><BR>wParam<BR><BR>Identifies the control that sends the message if the message is from a control. Otherwise, wParam is 0.<BR><BR>lParam<BR><BR>Pointer to a notification message (NMHDR) structure that contains the notification code and additional information. For some notification messages, this parameter points to a larger structure that has the NMHDR structure as its first member.<BR><BR>pResult<BR><BR>Pointer to an LRESULT variable in which to store the result code if the message is handled.<BR><BR>Remarks<BR><BR>The framework calls this member function to inform the parent window of a control that an event has occurred in the control or that the control requires some kind of information.<BR><BR>OnNotify processes the message map for control notification.<BR><BR>Override this member function in your derived class to handle the WM_NOTIFY message. An override will not process the message map unless the base class OnNotify is called.<BR><BR>For more information on the WM_NOTIFY message, see Technical Note 61 (TN061), ON_NOTIFY and WM_NOTIFY messages. You may also be interested the related topics described in TN060, The New Windows Common Controls, and TN062, Message Reflection for Windows Controls.<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:黄飚 回复日期:2002-10-08 08:46:02
<br>内容:// BasicButton.cpp : implementation file<BR>//<BR><BR>#include "stdafx.h"<BR>#include "BaseButton.h"<BR>#include "MouseRepeater.h"<BR><BR>#ifdef _DEBUG<BR>#define new DEBUG_NEW<BR>#undef THIS_FILE<BR>static char THIS_FILE[] = __FILE__;<BR>#endif<BR><BR>// disable warning for use if this-pointer in constructor<BR>#pragma warning(disable : 4355) <BR><BR>/////////////////////////////////////////////////////////////////////////////<BR>// CBaseButton<BR><BR>CBaseButton::CBaseButton()<BR>: m_bMouseOnButton(false),<BR> m_pCallback(NULL),<BR> m_pCallbackParam(NULL)<BR>{<BR> // create mouse repeaters<BR> m_pLButtonRepeater = new CMouseRepeater(this, WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDBLCLK, WM_LBUTTONDOWN);<BR> m_pMButtonRepeater = new CMouseRepeater(this, WM_MBUTTONDOWN, WM_MBUTTONUP, WM_MBUTTONDBLCLK, WM_MBUTTONREPEAT);<BR> m_pRButtonRepeater = new CMouseRepeater(this, WM_RBUTTONDOWN, WM_RBUTTONUP, WM_RBUTTONDBLCLK, WM_RBUTTONREPEAT);<BR>}<BR><BR>CBaseButton::~CBaseButton()<BR>{<BR> // delete the mouse repeaters<BR> delete m_pLButtonRepeater;<BR> delete m_pMButtonRepeater;<BR> delete m_pRButtonRepeater;<BR>}<BR><BR><BR>BEGIN_MESSAGE_MAP(CBaseButton, CButton)<BR> //{{AFX_MSG_MAP(CBaseButton)<BR> ON_WM_MOUSEMOVE()<BR> //}}AFX_MSG_MAP<BR> ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)<BR>END_MESSAGE_MAP()<BR><BR>/////////////////////////////////////////////////////////////////////////////<BR>// CBaseButton message handlers<BR><BR>BOOL CBaseButton::Create(LPCTSTR szCaption, DWORD dwStyle, CRect &rect, CWnd* pParentWnd, UINT nID)<BR>{<BR> dwStyle |= BS_OWNERDRAW|WS_CHILD|WS_VISIBLE;<BR> BOOL bRes = CButton::Create(szCaption, dwStyle, rect, pParentWnd, nID);<BR> ModifyStyleEx(0, WS_EX_TRANSPARENT);<BR> return bRes;<BR>}<BR><BR>void CBaseButton::SetCallbackFunction(CallbackFunction pCallbackFct, void* pCallbackParam)<BR>{<BR> m_pCallback = pCallbackFct;<BR> m_pCallbackParam = pCallbackParam;<BR>}<BR><BR>void CBaseButton::Notify(long nMessage, unsigned long wParam, long lParam)<BR>{<BR> if(m_pCallback)<BR> m_pCallback(m_pCallbackParam, nMessage, wParam, lParam);<BR>}<BR><BR>COLORREF CBaseButton::GetCurrentTextColor()<BR>{<BR> // if disabled<BR> if(!IsWindowEnabled())<BR> return m_colorMap.GetColor(CColorMap::TEXTDISABLED);<BR> // if highlighted<BR> else if(m_bMouseOnButton)<BR> return m_colorMap.GetColor(CColorMap::TEXTHIGHLIGHTED);<BR> else<BR> return m_colorMap.GetColor(CColorMap::TEXTNORMAL);<BR>}<BR><BR>long CBaseButton::GetTextAlignment(const CRect &textRect, const CString &sText, CDC* pDC)<BR>{<BR> // find the text alignment<BR> DWORD nStyle = GetStyle();<BR><BR> long nAlignment;<BR> if(textRect.Width() < pDC->GetTextExtent(sText).cx)<BR> nAlignment = DT_WORDBREAK;<BR> else<BR> nAlignment = DT_SINGLELINE;<BR><BR> // horisontal alignment<BR> if(BS_CENTER==(BS_CENTER & nStyle))<BR> nAlignment |= DT_CENTER;<BR> else if(BS_LEFT & nStyle)<BR> nAlignment |= DT_LEFT;<BR> else if(BS_RIGHT & nStyle)<BR> nAlignment |= DT_RIGHT;<BR> else<BR> nAlignment |= DT_CENTER;<BR><BR> // vertical alignment<BR> if(BS_VCENTER==(BS_VCENTER & nStyle))<BR> nAlignment |= DT_VCENTER;<BR> else if(BS_TOP & nStyle)<BR> nAlignment |= DT_TOP;<BR> else if(BS_BOTTOM & nStyle)<BR> nAlignment |= DT_BOTTOM;<BR> else<BR> nAlignment |= DT_VCENTER;<BR><BR> return nAlignment;<BR>}<BR><BR>LRESULT CBaseButton::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) <BR>{<BR> m_pLButtonRepeater->OnMessage(message, wParam, lParam);<BR> m_pMButtonRepeater->OnMessage(message, wParam, lParam);<BR> m_pRButtonRepeater->OnMessage(message, wParam, lParam);<BR><BR> switch(message)<BR> {<BR> case WM_LBUTTONDOWN:<BR> case WM_LBUTTONUP:<BR> case WM_MBUTTONDOWN:<BR> case WM_MBUTTONUP:<BR> case WM_MBUTTONREPEAT: <BR> case WM_RBUTTONDOWN:<BR> case WM_RBUTTONUP:<BR> case WM_RBUTTONREPEAT:<BR> Notify(message, GetDlgCtrlID(), 0);<BR> break;<BR> }<BR> <BR> return CButton::WindowProc(message, wParam, lParam);<BR>}<BR><BR>void CBaseButton::OnMouseMove(UINT nFlags, CPoint point) <BR>{<BR> if(!m_bMouseOnButton){<BR> TRACKMOUSEEVENT tme;<BR> tme.cbSize = sizeof(tme);<BR> tme.dwFlags = TME_LEAVE;<BR> tme.hwndTrack = m_hWnd;<BR> tme.dwHoverTime = 0;<BR> _TrackMouseEvent(&tme);<BR> m_bMouseOnButton = true;<BR> SetFocus();<BR> Invalidate(false);<BR> }<BR> <BR> CButton::OnMouseMove(nFlags, point);<BR>}<BR><BR>long CBaseButton::OnMouseLeave(UINT /*wParam*/, LONG /*lParam*/)<BR>{<BR> m_bMouseOnButton = false;<BR> Invalidate(false);<BR> return true;<BR>}<BR><BR>void CBaseButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) <BR>{<BR> CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);<BR><BR> // background<BR> {<BR> CBrush brush(m_colorMap.GetColor(CColorMap::BACKGROUND));<BR> pDC->FillRect(&lpDrawItemStruct->rcItem, &brush);<BR> if(m_bMouseOnButton && ODS_DISABLED != lpDrawItemStruct->itemState)<BR> {<BR> if((ODS_SELECTED | ODS_CHECKED) & lpDrawItemStruct->itemState)<BR> pDC->Draw3dRect(&lpDrawItemStruct->rcItem,<BR> m_colorMap.GetColor(CColorMap::EDGE2),<BR> m_colorMap.GetColor(CColorMap::EDGE1));<BR> else<BR> pDC->Draw3dRect(&lpDrawItemStruct->rcItem,<BR> m_colorMap.GetColor(CColorMap::EDGE1),<BR> m_colorMap.GetColor(CColorMap::EDGE2));<BR> }<BR> }<BR><BR> // text <BR> DrawText(pDC, &lpDrawItemStruct->rcItem);<BR>}<BR><BR>void CBaseButton::DrawText(CDC* pDC, LPRECT pRect)<BR>{<BR> pDC->SetTextColor(GetCurrentTextColor());<BR> pDC->SetBkMode(TRANSPARENT);<BR><BR> CString sText;<BR> GetWindowText(sText);<BR> CRect textRect(pRect);<BR> textRect.DeflateRect(2,2);<BR> pDC->DrawText(sText, &textRect, GetTextAlignment(textRect, sText, pDC));<BR>}<BR><BR>void CBaseButton::PreSubclassWindow() <BR>{<BR> ModifyStyle(0, BS_OWNERDRAW); <BR> // set the default font<BR> SetFont(GetDefaultFont());<BR> CButton::PreSubclassWindow();<BR>}<BR>#if !defined(AFX_BASICBUTTON_H__F4311646_514F_4386_99E5_B9394FB3AAB4__INCLUDED_)<BR>#define AFX_BASICBUTTON_H__F4311646_514F_4386_99E5_B9394FB3AAB4__INCLUDED_<BR><BR>#if _MSC_VER > 1000<BR>#pragma once<BR>#endif // _MSC_VER > 1000<BR>// BasicButton.h : header file<BR>//<BR><BR>#include "UserInterfaceControlsXIPORT.h"<BR>#include "ColorMap.h"<BR><BR>typedef void(*CallbackFunction)(void* pOwner, long nMessage, unsigned long wParam, long lParam);<BR>class CMouseRepeater;<BR><BR>/////////////////////////////////////////////////////////////////////////////<BR>// CBaseButton window<BR><BR>class _UICONTROLS_API_ CBaseButton : public CButton<BR>{<BR>public:<BR> // class constructor<BR> CBaseButton();<BR><BR> // class destructor<BR> virtual ~CBaseButton();<BR><BR> // Create<BR> // <BR> // Description:<BR> // Creates the button as a child window on 'pParentWnd'. <BR> // Remember to call DestroyWindow when removing button<BR> BOOL Create(LPCTSTR szCaption /* caption */,<BR> DWORD dwStyle /* button style (std Win32) */,<BR> CRect &rect /* button position */,<BR> CWnd* pParentWnd /* parent window */,<BR> UINT nID /* control ID */);<BR><BR> // Set Callback function<BR> // <BR> // Description:<BR> // Sets the call back function and call back parameter<BR> void SetCallbackFunction(CallbackFunction, void* pCallbackParam);<BR><BR> // object containing colors for the button<BR> CColorMap m_colorMap;<BR><BR> // Overrides<BR> // ClassWizard generated virtual function overrides<BR> //{{AFX_VIRTUAL(CBaseButton)<BR> public:<BR> virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);<BR> protected:<BR> virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);<BR> virtual void PreSubclassWindow();<BR> //}}AFX_VIRTUAL<BR><BR>protected:<BR> // mouse button repeater for L-button<BR> CMouseRepeater* m_pLButtonRepeater;<BR> // mouse button repeater for M-button<BR> CMouseRepeater* m_pMButtonRepeater;<BR> // mouse button repeater for R-button<BR> CMouseRepeater* m_pRButtonRepeater;<BR> // pointer to owner call back notification function<BR> CallbackFunction m_pCallback; <BR> // pointer to use in callback function<BR> void* m_pCallbackParam;<BR> // flag indicating if mouse is on the button<BR> bool m_bMouseOnButton; <BR><BR> // Notify<BR> // <BR> // Description:<BR> // Sends a notification message to the callback function if set.<BR> // Use CBaseButton::SetCallbackFunction to set the function pointer.<BR> virtual void Notify(long nMessage, unsigned long wParam, long lParam);<BR> <BR> // Get Current Text Color<BR> // <BR> // Output:<BR> // Returns the RGB reference of the current text color<BR> COLORREF GetCurrentTextColor();<BR><BR> // Get Text Alignment<BR> // <BR> // Output:<BR> // Returns the text alignment on the button (alignment for CDC::DrawText)<BR> long GetTextAlignment(const CRect &textRect /* text area */, const CString &sText /* text */, CDC* pDC /* drawing device */);<BR><BR> // DrawText<BR> // <BR> // Description:<BR> // Draws the caption text<BR> void DrawText(CDC* pDC /*device context*/, LPRECT pRect /*button rect*/);<BR><BR> //{{AFX_MSG(CBaseButton)<BR> afx_msg void OnMouseMove(UINT nFlags, CPoint point);<BR> //}}AFX_MSG<BR> // WM_MOUSELEAVE handler<BR> afx_msg long OnMouseLeave(UINT wParam, LONG lParam);<BR><BR> DECLARE_MESSAGE_MAP()<BR>};<BR><BR>/////////////////////////////////////////////////////////////////////////////<BR><BR>//{{AFX_INSERT_LOCATION}}<BR>// Microsoft Visual C++ will insert additional declarations immediately before the previous line.<BR><BR>#endif // !defined(AFX_BASICBUTTON_H__F4311646_514F_4386_99E5_B9394FB3AAB4__INCLUDED_)<BR>你参考一下,能不能给点分鼓励一下,谢谢<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -