对话框的属性在代码中设置.doc_第1页
对话框的属性在代码中设置.doc_第2页
对话框的属性在代码中设置.doc_第3页
对话框的属性在代码中设置.doc_第4页
对话框的属性在代码中设置.doc_第5页
已阅读5页,还剩22页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

对话框的属性在代码中设置(源文件)针对对话框的控件的属性设置代码如下,可以拿来直接使用,无须改动,直接嵌入到你的程序代码,提高编程效率。文件BtnST.h 头文件/ Class: CButtonST/ Compiler: Visual C+/ Tested on: Visual C+ 5.0/ Version: See GetVersionC() or GetVersionI()/ Created: xx/xxxx/1998/ Updated: 19/September/1999/ Author: Davide Calabro davide_/#ifndef _BTNST_H#define _BTNST_H#if _MSC_VER = 1000#pragma once#endif / _MSC_VER = 1000/ CBtnST.h : header file/ Comment this if you dont want that CButtonST hilights itself/ also when the window is inactive (like happens in Internet Explorer)/#define ST_LIKEIE/ Comment this if you dont want to use CMemDC class/#define ST_USE_MEMDC/ CButtonST windowclass CButtonST : public CButton/ Constructionpublic: CButtonST(); CButtonST(); enum ST_ALIGN_HORIZ, ST_ALIGN_VERT, ST_ALIGN_HORIZ_RIGHT;/ Attributespublic:/ Operationspublic:/ Overrides / ClassWizard generated virtual function overrides /AFX_VIRTUAL(CButtonST) public: virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); virtual BOOL PreTranslateMessage(MSG* pMsg); protected: virtual void PreSubclassWindow(); virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam); /AFX_VIRTUAL/ Implementationpublic: void DrawTransparent(BOOL bRepaint = FALSE); BOOL GetDefault(); void SetTooltipText(int nId, BOOL bActivate = TRUE); void SetTooltipText(CString* spText, BOOL bActivate = TRUE); void ActivateTooltip(BOOL bEnable = TRUE); BOOL SetBtnCursor(int nCursorId = -1); void SetFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint = FALSE); BOOL GetFlatFocus(); void SetDefaultActiveFgColor(BOOL bRepaint = FALSE); void SetActiveFgColor(COLORREF crNew, BOOL bRepaint = FALSE); const COLORREF GetActiveFgColor(); void SetDefaultActiveBgColor(BOOL bRepaint = FALSE); void SetActiveBgColor(COLORREF crNew, BOOL bRepaint = FALSE); const COLORREF GetActiveBgColor(); void SetDefaultInactiveFgColor(BOOL bRepaint = FALSE); void SetInactiveFgColor(COLORREF crNew, BOOL bRepaint = FALSE); const COLORREF GetInactiveFgColor(); void SetDefaultInactiveBgColor(BOOL bRepaint = FALSE); void SetInactiveBgColor(COLORREF crNew, BOOL bRepaint = FALSE); const COLORREF GetInactiveBgColor(); void SetShowText(BOOL bShow = TRUE); BOOL GetShowText(); void SetAlign(int nAlign); int GetAlign(); void SetFlat(BOOL bState = TRUE); BOOL GetFlat(); void DrawBorder(BOOL bEnable = TRUE); void SetIcon(int nIconInId, int nIconOutId = NULL); void SetIcon(HICON hIconIn, HICON hIconOut = NULL); static const short GetVersionI(); static const char* GetVersionC();protected: /AFX_MSG(CButtonST) afx_msg void OnCaptureChanged(CWnd *pWnd); afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); afx_msg void OnKillFocus(CWnd* pNewWnd); afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg void OnSysColorChange(); /AFX_MSG afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor); DECLARE_MESSAGE_MAP()private: void DrawTheIcon(CDC* pDC, CString* title, RECT* rcItem, CRect* captionRect, BOOL IsPressed, BOOL IsDisabled); void InitToolTip(); void PaintBk(CDC* pDC); int m_nAlign; BOOL m_bShowText; BOOL m_bDrawBorder; BOOL m_bIsFlat; BOOL m_MouseOnButton; BOOL m_bDrawFlatFocus; HCURSOR m_hCursor; CToolTipCtrl m_ToolTip; HICON m_hIconIn; HICON m_hIconOut; BYTE m_cyIcon; BYTE m_cxIcon; CDC m_dcBk; CBitmap m_bmpBk; CBitmap* m_pbmpOldBk; BOOL m_bDrawTransparent; BOOL m_bIsDefault; COLORREF m_crInactiveBg; COLORREF m_crInactiveFg; COLORREF m_crActiveBg; COLORREF m_crActiveFg;#ifdef ST_USE_MEMDC/ CMemDC - memory DC/ Author: Keith Rule/ Email: / Copyright 1996-1997, Keith Rule/ You may freely use or modify this code provided this/ Copyright is included in all derived versions./ History - 10/3/97 Fixed scrolling bug./ Added print support./ 25 feb 98 - fixed minor assertion bug/ This class implements a memory Device Contextclass CMemDC : public CDCpublic: / constructor sets up the memory DC CMemDC(CDC* pDC) : CDC() ASSERT(pDC != NULL); m_pDC = pDC; m_pOldBitmap = NULL; m_bMemDC = !pDC-IsPrinting(); if (m_bMemDC) / Create a Memory DC pDC-GetClipBox(&m_rect); CreateCompatibleDC(pDC); m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height(); m_pOldBitmap = SelectObject(&m_bitmap); SetWindowOrg(m_rect.left, m_rect.top); else / Make a copy of the relevent parts of the current DC for printing m_bPrinting = pDC-m_bPrinting; m_hDC = pDC-m_hDC; m_hAttribDC = pDC-m_hAttribDC; / Destructor copies the contents of the mem DC to the original DC CMemDC() if (m_bMemDC) / Copy the offscreen bitmap onto the screen. m_pDC-BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), this, m_rect.left, m_rect.top, SRCCOPY); /Swap back the original bitmap. SelectObject(m_pOldBitmap); else / All we need to do is replace the DC with an illegal value, / this keeps us from accidently deleting the handles associated with / the CDC that was passed to the constructor. m_hDC = m_hAttribDC = NULL; / Allow usage as a pointer CMemDC* operator-() return this; / Allow usage as a pointer operator CMemDC*() return this;private: CBitmap m_bitmap; / Offscreen bitmap CBitmap* m_pOldBitmap; / bitmap originally found in CMemDC CDC* m_pDC; / Saves CDC passed in constructor CRect m_rect; / Rectangle of drawing area. BOOL m_bMemDC; / TRUE if CDC really is a Memory DC.;#endif/AFX_INSERT_LOCATION/ Microsoft Developer Studio will insert additional declarations immediately before the previous line.#endif文件BtnST.cpp 源文件#include stdafx.h#include BtnST.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CButtonSTCButtonST:CButtonST() m_MouseOnButton = FALSE; m_hIconIn = NULL; m_hIconOut = NULL; m_cxIcon = 0; m_cyIcon = 0; m_hCursor = NULL; / Default type is flat button m_bIsFlat = TRUE; / By default draw border in flat button m_bDrawBorder = TRUE; / By default icon is aligned horizontally m_nAlign = ST_ALIGN_HORIZ; / By default show the text button m_bShowText = TRUE; / By default, for flat button, dont draw the focus rect m_bDrawFlatFocus = FALSE; / By default the button is not the default button m_bIsDefault = FALSE; SetDefaultInactiveBgColor(); SetDefaultInactiveFgColor(); SetDefaultActiveBgColor(); SetDefaultActiveFgColor(); / No tooltip created m_ToolTip.m_hWnd = NULL; / Do not draw as a transparent button m_bDrawTransparent = FALSE; m_pbmpOldBk = NULL; / End of CButtonSTCButtonST:CButtonST() / Restore old bitmap (if any) if (m_dcBk.m_hDC != NULL & m_pbmpOldBk != NULL) m_dcBk.SelectObject(m_pbmpOldBk); / Destroy the icons (if any) / Note: the following two lines MUST be here! even if / BoundChecker says they are unnecessary! if (m_hIconIn != NULL) :DestroyIcon(m_hIconIn); if (m_hIconOut != NULL) :DestroyIcon(m_hIconOut); / Destroy the cursor (if any) if (m_hCursor != NULL) :DestroyCursor(m_hCursor); / End of CButtonSTBEGIN_MESSAGE_MAP(CButtonST, CButton) /AFX_MSG_MAP(CButtonST) ON_WM_CAPTURECHANGED() ON_WM_SETCURSOR() ON_WM_KILLFOCUS() ON_WM_MOUSEMOVE() ON_WM_CTLCOLOR_REFLECT() ON_WM_SYSCOLORCHANGE() /AFX_MSG_MAPEND_MESSAGE_MAP()void CButtonST:SetIcon(int nIconInId, int nIconOutId) HICON hIconIn; HICON hIconOut; HINSTANCE hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nIconInId), RT_GROUP_ICON); / Set icon when the mouse is IN the button hIconIn = (HICON):LoadImage(hInstResource/*AfxGetApp()-m_hInstance*/, MAKEINTRESOURCE(nIconInId), IMAGE_ICON, 0, 0, 0); / Set icon when the mouse is OUT the button hIconOut = (nIconOutId = NULL) ? NULL : (HICON):LoadImage(hInstResource/*AfxGetApp()-m_hInstance*/, MAKEINTRESOURCE(nIconOutId), IMAGE_ICON, 0, 0, 0); SetIcon(hIconIn, hIconOut);/* / Note: the following two lines MUST be here! even if / BoundChecker says they are unnecessary! if (m_hIconIn != NULL) :DestroyIcon(m_hIconIn); if (m_hIconOut != NULL) :DestroyIcon(m_hIconOut); / Set icon when the mouse is IN the button m_hIconIn = (HICON):LoadImage(hInstResource, MAKEINTRESOURCE(nIconInId), IMAGE_ICON, 0, 0, 0); / Set icon when the mouse is OUT the button m_hIconOut = (nIconOutId = NULL) ? m_hIconIn : (HICON):LoadImage(hInstResource, MAKEINTRESOURCE(nIconOutId), IMAGE_ICON, 0, 0, 0); ICONINFO ii; / Get icon dimension ZeroMemory(&ii, sizeof(ICONINFO); :GetIconInfo(m_hIconIn, &ii); m_cxIcon = (BYTE)(ii.xHotspot * 2); m_cyIcon = (BYTE)(ii.yHotspot * 2); :DeleteObject(ii.hbmMask); :DeleteObject(ii.hbmColor); RedrawWindow();*/ / End of SetIconvoid CButtonST:SetIcon(HICON hIconIn, HICON hIconOut) / Note: the following two lines MUST be here! even if / BoundChecker says they are unnecessary! if (m_hIconIn != NULL) :DestroyIcon(m_hIconIn); if (m_hIconOut != NULL) :DestroyIcon(m_hIconOut); / Set icon when the mouse is IN the button m_hIconIn = hIconIn; / Set icon when the mouse is OUT the button m_hIconOut = (hIconOut = NULL) ? m_hIconIn : hIconOut; ICONINFO ii; / Get icon dimension ZeroMemory(&ii, sizeof(ICONINFO); :GetIconInfo(m_hIconIn, &ii); m_cxIcon = (BYTE)(ii.xHotspot * 2); m_cyIcon = (BYTE)(ii.yHotspot * 2); :DeleteObject(ii.hbmMask); :DeleteObject(ii.hbmColor); RedrawWindow(); / End of SetIconBOOL CButtonST:SetBtnCursor(int nCursorId) HINSTANCE hInstResource; / Destroy any previous cursor if (m_hCursor != NULL) :DestroyCursor(m_hCursor); m_hCursor = NULL; / If we want a cursor if (nCursorId != -1) hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nCursorId), RT_GROUP_CURSOR); / Load icon resource m_hCursor = (HCURSOR):LoadImage(hInstResource/*AfxGetApp()-m_hInstance*/, MAKEINTRESOURCE(nCursorId), IMAGE_CURSOR, 0, 0, 0); / If something wrong then return FALSE if (m_hCursor = NULL) return FALSE; return TRUE; / End of SetBtnCursorvoid CButtonST:SetFlat(BOOL bState) m_bIsFlat = bState; Invalidate(); / End of SetFlatBOOL CButtonST:GetFlat() return m_bIsFlat; / End of GetFlatvoid CButtonST:SetAlign(int nAlign) switch (nAlign) case ST_ALIGN_HORIZ: m_nAlign = ST_ALIGN_HORIZ; break; case ST_ALIGN_HORIZ_RIGHT: m_nAlign = ST_ALIGN_HORIZ_RIGHT; break; case ST_ALIGN_VERT: m_nAlign = ST_ALIGN_VERT; break; Invalidate(); / End of SetAlignint CButtonST:GetAlign() return m_nAlign; / End of GetAlignvoid CButtonST:DrawBorder(BOOL bEnable) m_bDrawBorder = bEnable; / End of DrawBorderconst char* CButtonST:GetVersionC() return 2.6; / End of GetVersionCconst short CButtonST:GetVersionI() return 26; / Divide by 10 to get actual version / End of GetVersionIvoid CButtonST:SetShowText(BOOL bShow) m_bShowText = bShow; Invalidate(); / End of SetShowTextBOOL CButtonST:GetShowText() return m_bShowText; / End of GetShowTextvoid CButtonST:OnMouseMove(UINT nFlags, CPoint point) CWnd* pWnd; / Finestra attiva CWnd* pParent; / Finestra che contiene il bottone CButton:OnMouseMove(nFlags, point); / If the mouse enter the button with the left button pressed / then do nothing if (nFlags & MK_LBUTTON & m_MouseOnButton = FALSE) return; / If our button is not flat then do nothing if (m_bIsFlat = FALSE) return; pWnd = GetActiveWindow(); pParent = GetOwner(); if (GetCapture() != this) & (#ifndef ST_LIKEIE pWnd != NULL & #endif pParent != NULL) m_MouseOnButton = TRUE; /SetFocus(); / Thanks Ralph! SetCapture(); Invalidate(); else /* CRect rc; GetClientRect(&rc); if (!rc.PtInRect(point) */ POINT p2 = point; ClientToScreen(&p2); CWnd* wndUnderMouse = WindowFromPoint(p2);/ if (wndUnderMouse != this) if (wndUnderMouse & wndUnderMouse-m_hWnd != this-m_hWnd) / Redraw only if mouse goes out if (m_MouseOnButton = TRUE) m_MouseOnButton = FALSE; Invalidate(); / If user is NOT pressing left button then release capture! if (!(nFlags & MK_LBUTTON) ReleaseCapture(); / End of OnMouseMovevoid CButtonST:OnKillFocus(CWnd * pNewWnd) CButton:OnKillFocus(pNewWnd); / If our button is not flat then do nothing if (m_bIsFlat = FALSE) return; if (m_MouseOnButton = TRUE) m_MouseOnButton = FALSE; Invalidate(); / End of OnKillFocusvoid CButtonST:OnCaptureChanged(CWnd *pWnd) if (m_MouseOnButton = TRUE) ReleaseCapture(); Invalidate(); / Call base message handler CButton:OnCaptureChanged(pWnd); / End of OnCaptureChangedvoid CButtonST:DrawItem(LPDRAWITEMSTRUCT lpDIS)#ifdef ST_USE_MEMDC CDC *pdrawDC = CDC:FromHandle(lpDIS-hDC); CMemDC memDC(pdrawDC); CDC *pDC = &memDC;#else CDC* pDC = CDC:FromHandle(lpDIS-hDC);#endif CPen *pOldPen; BOOL bIsPressed = (lpDIS-itemState & ODS_SELECTED); BOOL bIsFocused = (lpDIS-itemState & ODS_FOCUS); BOOL bIsDisabled = (lpDIS-itemState & ODS_DISABLED); CRect itemRect = lpDIS-rcItem; pDC-SetBkMode(TRANSPARENT); if (m_bIsFlat = FALSE) if (bIsFocused | (GetDefault() = TRUE) CBrush br(RGB(0,0,0); pDC-FrameRect(&itemRect, &br); itemRect.DeflateRect(1, 1); / Prepare draw. paint buttons area with background color COLORREF bgColor; if (m_MouseOnButton = TRUE) | (bIsPressed) bgColor = GetActiveBgColor(); else bgColor = GetInactiveBgColor(); CBrush br(bgColor); / Draw transparent? if (m_bDrawTransparent = TRUE) PaintBk(pDC); else pDC-FillRect(&itemRect, &br); / Disegno lo sfondo del bottone/CBrush br(GetSysColor(COLOR_BTNFACE); /pDC-FillRect(&itemRect, &br); / Draw pressed button if (bIsPressed) if (m_bIsFlat = TRUE) if (m_bDrawBorder = TRUE) pDC-Draw3dRect(itemRect, :GetSysColor(COLOR_BTNSHADOW), :GetSysColor(COLOR_BTNHILIGHT);/* CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT); / Bianco CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW); / Grigio scuro / Disegno i bordi a sinistra e in alto / Dark gray line pOldPen = pDC-SelectObject(&penBtnShadow); pDC-MoveTo(itemR

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论