本站有教程用sdi+formview模拟对话框
但我工程里sdi已经被占用了,请问各位怎么办呢
35 个解决方案
#1
没人看么
#2
帮忙顶一个~
#3
VS2008+SP1里用的BCG的东西
#4
部长 来啦 是bcg的 不过好像没有针对对话框进行美化的类 还是05里的那种界面
#5
VS2008+SP1自带的Sample下的Visual C++ 2008 Feature Pack文件夹下有个例子程序DesktopAlertDemo,你可以参考一下,它的对话框样式看上去还是很不错的
#6
好像很不错的感觉,以前没注意发现
#7
我也想看一下,我这边装的就是VS2008+SP1,好像都没这个文件夹,例子程序DesktopAlertDemo也找不到
#8
我看到了那个文件夹了 楼上 好像要自己从ms下 才有
#9
在构造函数中加如下一语句
EnableVisualManagerStyle ();
EnableVisualManagerStyle ();
#10
PS:在对话框的构造函数中。加了的对话框就有统一效果,不加没有,顾函数名思意
#11
学习楼上的..我千方百计的网上找了代码.实现了这个东西.唉..气人啊.
#12
貌似这是BCG的吧?
#13
--------------------------------
我加了这句话,怎么找不到这个函数啊:
error C3861: 'EnableVisualManagerStyle': identifier not found,我的是vs08sp1
#14
楼上的几位朋友可否稍微说明一下,谢谢了!
#15
那个是BCG界面库的函数的,,额,,,
#16
呵呵~刚才百度了一下BCG界面库的东西,稍微了解了一下。
#17
BCG的例子里有这个函数 ms的应该也有 今天准备搜下
#18
怎么实现的呀
#19
无幻兄 看了你很多sp1的文章呀 呵呵 能不能具体说下 这个
#20
我实现了..可以帖代码..这个木问题
#21
你实现的代码? 能否贴来共享下?
#22
我也在找对话框可以美化的,但是那个函数是BCG才找得到的。
#23
嗯 是的 在BCG环境下 好像很方便 ms集成过来之后 例子倒是很多 但感觉文档查不到
#24
我的想法是从sdi里截取颜色 或者位图 然后通过响应ncpaint 绘制的
不知道你是怎么实现的
#25
sorry哦...只是对话框背景色改变...没有其他的那些主题.唉

#26
呵呵 在sp1下 改变对话框背景色比较方便 从CDiagEx派生之后 SetBackgroundColor就可以 贴图也很方便
#27
哥们,把代码贴出来看看啊,在此谢过了~
#28
// ColorDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "WebGuard.h"
#include "ColorDlg.h"
// CColorDlg
IMPLEMENT_DYNAMIC(CColorDlg, CDialogEx)
CColorDlg::CColorDlg()
{
m_bDragging=FALSE;
}
CColorDlg::CColorDlg(UINT nIDTemplate, CWnd *pParent)
: CDialogEx(nIDTemplate, pParent),m_bNoScroll(TRUE)
{
m_bDragging=FALSE;
}
CColorDlg::~CColorDlg()
{
}
BEGIN_MESSAGE_MAP(CColorDlg, CDialogEx)
ON_WM_CTLCOLOR()
ON_WM_VSCROLL()
ON_WM_HSCROLL()
ON_WM_SIZE()
ON_WM_MOUSEWHEEL()
//ON_WM_LBUTTONDOWN()
//ON_WM_LBUTTONUP()
//ON_WM_MOUSEMOVE()
//ON_WM_KILLFOCUS()
//ON_WM_SETCURSOR()
//ON_WM_MOUSEACTIVATE()
END_MESSAGE_MAP()
// CColorDlg 消息处理程序
BOOL CColorDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
m_hCursor1=AfxGetApp()->LoadCursor(IDC_CURSOR1);
m_hCursor2=AfxGetApp()->LoadCursor(IDC_CURSOR2);
//SetClassLong(m_hWnd,GCL_HCURSOR,(long)m_hCursor1);
// save the original size
GetWindowRect(m_rcOriginalRect);
m_ScrollPos.SetPoint(0,0);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
HBRUSH CColorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
/*
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: 在此更改 DC 的任何属性
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
return hbr;
*/
//return ISGUI::VisualStyleHelper::OnCtlColor(pDC,pWnd,nCtlColor);
HBRUSH hbrRet = NULL;
if (VisualStyleHelper::GetBackgroundBr().GetSafeHandle() != NULL )
{
#define AFX_MAX_CLASS_NAME 255
#define AFX_STATIC_CLASS _T("Static")
#define AFX_BUTTON_CLASS _T("Button")
#define AFX_EDIT_CLASS _T("Edit")
#define AFX_SLIDE_CLASS _T("msctls_trackbar32")
if (nCtlColor == CTLCOLOR_STATIC)
{
TCHAR lpszClassName[AFX_MAX_CLASS_NAME + 1];
int nChars = ::GetClassName(pWnd->GetSafeHwnd(), lpszClassName, AFX_MAX_CLASS_NAME);
if ((nChars > 0)
&& ( ( _tcsncmp( lpszClassName, AFX_STATIC_CLASS, nChars ) == 0 )
|| ( _tcsncmp( lpszClassName, AFX_BUTTON_CLASS, nChars ) == 0 )
|| ( _tcsncmp( lpszClassName, AFX_EDIT_CLASS, nChars ) == 0 )
|| ( _tcsncmp( lpszClassName, AFX_SLIDE_CLASS, nChars ) == 0 )
))
{
pDC->SetBkMode(TRANSPARENT);
hbrRet = (HBRUSH)VisualStyleHelper::GetBackgroundBr();
}
}
else if (nCtlColor == CTLCOLOR_DLG)
{
pDC->SetBkMode(TRANSPARENT);
hbrRet = (HBRUSH)VisualStyleHelper::GetBackgroundBr();
}
}
if( hbrRet == NULL )
{
pDC->SetBkMode(OPAQUE);
hbrRet = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
}
return hbrRet;
}
COLORREF VisualStyleHelper::s_clrBackground = ::GetSysColor(COLOR_WINDOW);
CBrush VisualStyleHelper::s_brBackground;
void VisualStyleHelper::DetermineCurrentThemeClr()
{
CMFCVisualManager* pManager = CMFCVisualManager::GetInstance();
if( pManager == NULL )
{
s_clrBackground = ::GetSysColor(COLOR_BTNFACE);
return;
}
CMFCVisualManagerOffice2007* pManager2007 = DYNAMIC_DOWNCAST(CMFCVisualManagerOffice2007, pManager);
if( pManager2007!=NULL )
{
switch( pManager2007->GetStyle() )
{
default:
case CMFCVisualManagerOffice2007::Office2007_LunaBlue:
s_clrBackground = RGB(193,215,245);
break;
case CMFCVisualManagerOffice2007::Office2007_ObsidianBlack:
s_clrBackground = RGB(225,226,229) ;
break;
case CMFCVisualManagerOffice2007::Office2007_Silver:
s_clrBackground = RGB(208,212,221) ;
break;
case CMFCVisualManagerOffice2007::Office2007_Aqua:
s_clrBackground = RGB(212,218,233) ;
break;
}
}
else if( pManager->IsKindOf(RUNTIME_CLASS(CMFCVisualManagerVS2005)) )
{
s_clrBackground = ( ::GetSysColor(COLOR_WINDOW) );
}
else if( pManager->IsKindOf(RUNTIME_CLASS(CMFCVisualManagerOffice2003)) )
{
s_clrBackground = ( ::GetSysColor(COLOR_WINDOW) );
}
else if( pManager->IsKindOf(RUNTIME_CLASS(CMFCVisualManagerOfficeXP)) )
{
s_clrBackground = ( ::GetSysColor(COLOR_WINDOW) );
}
else if( pManager->IsKindOf(RUNTIME_CLASS(CMFCVisualManagerWindows)) )
{
s_clrBackground = ( ::GetSysColor(COLOR_WINDOW) );
}
else
{
s_clrBackground = ( ::GetSysColor(COLOR_BTNFACE) );
}
}
CBrush& VisualStyleHelper::GetBackgroundBr()
{
if(s_brBackground.GetSafeHandle())
{
s_brBackground.DeleteObject();
}
DetermineCurrentThemeClr();
s_brBackground.CreateSolidBrush(s_clrBackground);
return s_brBackground;
}
void CColorDlg::DoHVScroll(int nBar, UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
SCROLLINFO scrol;
scrol.cbSize = sizeof(SCROLLINFO);
scrol.fMask = SIF_ALL;
GetScrollInfo(nBar,&scrol);
CRect rect;
GetClientRect(rect);
int minpos = 0;
int maxpos = scrol.nMax - scrol.nPage;
if(maxpos <= minpos)
return;
long* pLastPost;
if (nBar == SB_VERT)
{
pLastPost = &m_ScrollPos.y;
}
else if(nBar == SB_HORZ)
{
pLastPost = &m_ScrollPos.x;
}
else
{
return;
}
long& nRealPos = *pLastPost;
int oldPos = nRealPos;
// Determine the new position of scroll box.
switch (nSBCode)
{
case SB_TOP: // Scroll to far left.
nRealPos = minpos;
break;
case SB_BOTTOM: // Scroll to far right.
nRealPos = maxpos;
break;
case SB_LINEUP: // Scroll left.
nRealPos -= 10;
if (nRealPos < minpos)
nRealPos = minpos;
break;
case SB_LINEDOWN: // Scroll right.
nRealPos += 10;
if (nRealPos > maxpos)
nRealPos = maxpos;
break;
case SB_PAGEUP: // Scroll one page left.
nRealPos -= scrol.nPage;
if (nRealPos < minpos)
nRealPos = minpos;
break;
case SB_PAGEDOWN: // Scroll one page right.
nRealPos += scrol.nPage;
if (nRealPos > maxpos)
nRealPos = maxpos;
break;
case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
nRealPos = nPos; // of the scroll box at the end of the drag operation.
break;
case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is the
nRealPos = nPos; // position that the scroll box has been dragged to.
break;
}
SetScrollPos(nBar, nRealPos);
if (nBar == SB_VERT)
{
ScrollWindow(0, oldPos - nRealPos);
CDialogEx::OnVScroll(nSBCode, nRealPos, pScrollBar);
}
else if(nBar == SB_HORZ)
{
ScrollWindow(oldPos - nRealPos, 0);
CDialogEx::OnHScroll(nSBCode, nRealPos, pScrollBar);
}
}
void CColorDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
DoHVScroll(SB_HORZ, nSBCode, nPos, pScrollBar);
}
void CColorDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
DoHVScroll(SB_VERT, nSBCode, nPos, pScrollBar);
}
void CColorDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
if (m_bNoScroll) return;
if (GetSafeHwnd())
{
if (cy > m_rcOriginalRect.Height())
{
SetScrollPos(SB_VERT, 0);
ScrollWindow(0, m_ScrollPos.y);
m_ScrollPos.y = 0;
}
if (cx > m_rcOriginalRect.Width())
{
SetScrollPos(SB_HORZ, 0);
ScrollWindow(m_ScrollPos.x, 0);
m_ScrollPos.x = 0;
}
}
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL;
si.nMin = 0;
si.nMax = m_rcOriginalRect.Height();
si.nPage = cy;
si.nPos = 0;
SetScrollInfo(SB_VERT, &si, TRUE);
si.nMax = m_rcOriginalRect.Width();
si.nPage = cx;
SetScrollInfo(SB_HORZ, &si, TRUE);
}
// PostMessage(WM_MOUSEWHEEL,(UINT)MAKELONG(nFlags,zDelta),(LPARAM)MAKELONG(pt.x,pt.y));
BOOL CColorDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
BOOL bUp = TRUE;
int nDelta = zDelta;
if(zDelta < 0) {
bUp = FALSE;
nDelta = -nDelta;
}
UINT nWheelScrollLines;
::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
&nWheelScrollLines, 0);
int nLines = (nDelta * nWheelScrollLines) / WHEEL_DELTA;
while(nLines--)
SendMessage(WM_VSCROLL, MAKEWPARAM(bUp ? SB_LINEUP : SB_LINEDOWN, 0), 0);
return CDialogEx::OnMouseWheel(nFlags, zDelta, pt);
}
//void CColorDlg::OnLButtonDown(UINT nFlags, CPoint point)
//{
//
// m_bDragging=TRUE;
// SetCapture();
//
// m_ptDragPoint=point;
//
// SetCursor(m_hCursor2);
// CDialogEx::OnLButtonDown(nFlags, point);
//}
//
//void CColorDlg::OnLButtonUp(UINT nFlags, CPoint point)
//{
// EndDrag();
//
// CDialogEx::OnLButtonUp(nFlags, point);
//}
//
//void CColorDlg::OnMouseMove(UINT nFlags, CPoint point)
//{
// if (m_bDragging)
// {
// int nDelta=m_ptDragPoint.y-point.y;
// m_ptDragPoint=point;
//
// int nNewPos=m_nScrollPos+nDelta;
//
// if (nNewPos<0)
// nNewPos=0;
// else if (nNewPos>m_rcOriginalRect.Height() - m_nCurHeight)
// nNewPos=m_rcOriginalRect.Height() - m_nCurHeight;
//
// nDelta=nNewPos-m_nScrollPos;
// m_nScrollPos=nNewPos;
//
// SetScrollPos(SB_VERT,m_nScrollPos,TRUE);
// ScrollWindow(0,-nDelta);
// }
//
// CDialogEx::OnMouseMove(nFlags, point);
//}
//
//void CColorDlg::OnKillFocus(CWnd* pNewWnd)
//{
// CDialogEx::OnKillFocus(pNewWnd);
//
// EndDrag();
//}
//
//void CColorDlg::EndDrag()
//{
// m_bDragging=FALSE;
// ReleaseCapture();
// SetCursor(m_hCursor1);
//}
//
//BOOL CColorDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
//{
// BOOL bRet=TRUE;
//
// if (nHitTest==HTCLIENT)
// {
// SetCursor(m_hCursor1);
// bRet=FALSE;
// }
// else
// bRet=CDialogEx::OnSetCursor(pWnd,nHitTest,message);
//
// return bRet;
//}
//int CColorDlg::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
//{
// // TODO: 在此添加消息处理程序代码和/或调用默认值
// //SetFocus();
//
// //return MA_ACTIVATE;
//
// return CDialogEx::OnMouseActivate(pDesktopWnd, nHitTest, message);
//}
#29
#pragma once
// CColorDlg
class CColorDlg : public CDialogEx
{
DECLARE_DYNAMIC(CColorDlg)
public:
CColorDlg();
CColorDlg(UINT nIDTemplate, CWnd *pParent = NULL);
virtual ~CColorDlg();
void DoHVScroll(int nBar, UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
void SetNoScroll(BOOL bNoScroll = TRUE) { m_bNoScroll = bNoScroll; }
// 对话框数据
HCURSOR m_hCursor1, m_hCursor2;
// dialog size as you see in the resource view (original size)
CRect m_rcOriginalRect;
// dragging
BOOL m_bDragging;
CPoint m_ptDragPoint;
// actual scroll position
CPoint m_ScrollPos;
BOOL m_bNoScroll;
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
//afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
//afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
//afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//afx_msg void OnKillFocus(CWnd* pNewWnd);
public:
virtual BOOL OnInitDialog();
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
//afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
//afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
};
class VisualStyleHelper
{
public:
static void DetermineCurrentThemeClr();
static CBrush& GetBackgroundBr();
public:
static COLORREF s_clrBackground;
static CBrush s_brBackground;
};
#30
只是背景色变化.
需要改变背景色的时候调用
RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);
需要改变背景色的时候调用
RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);
#31
楼上 是对话框的客户区背景色么 你试试SetBackgroundColor()?
#32
我是要根据你现在的主题能自动变
#33
发现个有趣的 设置了office07的主题后 对话框是不会变化 不过里面的cmfcpropertygridctrl却有主题的改变 哈哈
#34

难道我代码没给全?不是吧..哈哈
#35
呵呵 还没试你的代码
#1
没人看么
#2
帮忙顶一个~
#3
VS2008+SP1里用的BCG的东西
#4
部长 来啦 是bcg的 不过好像没有针对对话框进行美化的类 还是05里的那种界面
#5
VS2008+SP1自带的Sample下的Visual C++ 2008 Feature Pack文件夹下有个例子程序DesktopAlertDemo,你可以参考一下,它的对话框样式看上去还是很不错的
#6
好像很不错的感觉,以前没注意发现
#7
我也想看一下,我这边装的就是VS2008+SP1,好像都没这个文件夹,例子程序DesktopAlertDemo也找不到
#8
我看到了那个文件夹了 楼上 好像要自己从ms下 才有
#9
在构造函数中加如下一语句
EnableVisualManagerStyle ();
EnableVisualManagerStyle ();
#10
PS:在对话框的构造函数中。加了的对话框就有统一效果,不加没有,顾函数名思意
#11
学习楼上的..我千方百计的网上找了代码.实现了这个东西.唉..气人啊.
#12
貌似这是BCG的吧?
#13
--------------------------------
我加了这句话,怎么找不到这个函数啊:
error C3861: 'EnableVisualManagerStyle': identifier not found,我的是vs08sp1
#14
楼上的几位朋友可否稍微说明一下,谢谢了!
#15
那个是BCG界面库的函数的,,额,,,
#16
呵呵~刚才百度了一下BCG界面库的东西,稍微了解了一下。
#17
BCG的例子里有这个函数 ms的应该也有 今天准备搜下
#18
怎么实现的呀
#19
无幻兄 看了你很多sp1的文章呀 呵呵 能不能具体说下 这个
#20
我实现了..可以帖代码..这个木问题
#21
你实现的代码? 能否贴来共享下?
#22
我也在找对话框可以美化的,但是那个函数是BCG才找得到的。
#23
嗯 是的 在BCG环境下 好像很方便 ms集成过来之后 例子倒是很多 但感觉文档查不到
#24
我的想法是从sdi里截取颜色 或者位图 然后通过响应ncpaint 绘制的
不知道你是怎么实现的
#25
sorry哦...只是对话框背景色改变...没有其他的那些主题.唉

#26
呵呵 在sp1下 改变对话框背景色比较方便 从CDiagEx派生之后 SetBackgroundColor就可以 贴图也很方便
#27
哥们,把代码贴出来看看啊,在此谢过了~
#28
// ColorDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "WebGuard.h"
#include "ColorDlg.h"
// CColorDlg
IMPLEMENT_DYNAMIC(CColorDlg, CDialogEx)
CColorDlg::CColorDlg()
{
m_bDragging=FALSE;
}
CColorDlg::CColorDlg(UINT nIDTemplate, CWnd *pParent)
: CDialogEx(nIDTemplate, pParent),m_bNoScroll(TRUE)
{
m_bDragging=FALSE;
}
CColorDlg::~CColorDlg()
{
}
BEGIN_MESSAGE_MAP(CColorDlg, CDialogEx)
ON_WM_CTLCOLOR()
ON_WM_VSCROLL()
ON_WM_HSCROLL()
ON_WM_SIZE()
ON_WM_MOUSEWHEEL()
//ON_WM_LBUTTONDOWN()
//ON_WM_LBUTTONUP()
//ON_WM_MOUSEMOVE()
//ON_WM_KILLFOCUS()
//ON_WM_SETCURSOR()
//ON_WM_MOUSEACTIVATE()
END_MESSAGE_MAP()
// CColorDlg 消息处理程序
BOOL CColorDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
m_hCursor1=AfxGetApp()->LoadCursor(IDC_CURSOR1);
m_hCursor2=AfxGetApp()->LoadCursor(IDC_CURSOR2);
//SetClassLong(m_hWnd,GCL_HCURSOR,(long)m_hCursor1);
// save the original size
GetWindowRect(m_rcOriginalRect);
m_ScrollPos.SetPoint(0,0);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
HBRUSH CColorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
/*
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: 在此更改 DC 的任何属性
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
return hbr;
*/
//return ISGUI::VisualStyleHelper::OnCtlColor(pDC,pWnd,nCtlColor);
HBRUSH hbrRet = NULL;
if (VisualStyleHelper::GetBackgroundBr().GetSafeHandle() != NULL )
{
#define AFX_MAX_CLASS_NAME 255
#define AFX_STATIC_CLASS _T("Static")
#define AFX_BUTTON_CLASS _T("Button")
#define AFX_EDIT_CLASS _T("Edit")
#define AFX_SLIDE_CLASS _T("msctls_trackbar32")
if (nCtlColor == CTLCOLOR_STATIC)
{
TCHAR lpszClassName[AFX_MAX_CLASS_NAME + 1];
int nChars = ::GetClassName(pWnd->GetSafeHwnd(), lpszClassName, AFX_MAX_CLASS_NAME);
if ((nChars > 0)
&& ( ( _tcsncmp( lpszClassName, AFX_STATIC_CLASS, nChars ) == 0 )
|| ( _tcsncmp( lpszClassName, AFX_BUTTON_CLASS, nChars ) == 0 )
|| ( _tcsncmp( lpszClassName, AFX_EDIT_CLASS, nChars ) == 0 )
|| ( _tcsncmp( lpszClassName, AFX_SLIDE_CLASS, nChars ) == 0 )
))
{
pDC->SetBkMode(TRANSPARENT);
hbrRet = (HBRUSH)VisualStyleHelper::GetBackgroundBr();
}
}
else if (nCtlColor == CTLCOLOR_DLG)
{
pDC->SetBkMode(TRANSPARENT);
hbrRet = (HBRUSH)VisualStyleHelper::GetBackgroundBr();
}
}
if( hbrRet == NULL )
{
pDC->SetBkMode(OPAQUE);
hbrRet = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
}
return hbrRet;
}
COLORREF VisualStyleHelper::s_clrBackground = ::GetSysColor(COLOR_WINDOW);
CBrush VisualStyleHelper::s_brBackground;
void VisualStyleHelper::DetermineCurrentThemeClr()
{
CMFCVisualManager* pManager = CMFCVisualManager::GetInstance();
if( pManager == NULL )
{
s_clrBackground = ::GetSysColor(COLOR_BTNFACE);
return;
}
CMFCVisualManagerOffice2007* pManager2007 = DYNAMIC_DOWNCAST(CMFCVisualManagerOffice2007, pManager);
if( pManager2007!=NULL )
{
switch( pManager2007->GetStyle() )
{
default:
case CMFCVisualManagerOffice2007::Office2007_LunaBlue:
s_clrBackground = RGB(193,215,245);
break;
case CMFCVisualManagerOffice2007::Office2007_ObsidianBlack:
s_clrBackground = RGB(225,226,229) ;
break;
case CMFCVisualManagerOffice2007::Office2007_Silver:
s_clrBackground = RGB(208,212,221) ;
break;
case CMFCVisualManagerOffice2007::Office2007_Aqua:
s_clrBackground = RGB(212,218,233) ;
break;
}
}
else if( pManager->IsKindOf(RUNTIME_CLASS(CMFCVisualManagerVS2005)) )
{
s_clrBackground = ( ::GetSysColor(COLOR_WINDOW) );
}
else if( pManager->IsKindOf(RUNTIME_CLASS(CMFCVisualManagerOffice2003)) )
{
s_clrBackground = ( ::GetSysColor(COLOR_WINDOW) );
}
else if( pManager->IsKindOf(RUNTIME_CLASS(CMFCVisualManagerOfficeXP)) )
{
s_clrBackground = ( ::GetSysColor(COLOR_WINDOW) );
}
else if( pManager->IsKindOf(RUNTIME_CLASS(CMFCVisualManagerWindows)) )
{
s_clrBackground = ( ::GetSysColor(COLOR_WINDOW) );
}
else
{
s_clrBackground = ( ::GetSysColor(COLOR_BTNFACE) );
}
}
CBrush& VisualStyleHelper::GetBackgroundBr()
{
if(s_brBackground.GetSafeHandle())
{
s_brBackground.DeleteObject();
}
DetermineCurrentThemeClr();
s_brBackground.CreateSolidBrush(s_clrBackground);
return s_brBackground;
}
void CColorDlg::DoHVScroll(int nBar, UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
SCROLLINFO scrol;
scrol.cbSize = sizeof(SCROLLINFO);
scrol.fMask = SIF_ALL;
GetScrollInfo(nBar,&scrol);
CRect rect;
GetClientRect(rect);
int minpos = 0;
int maxpos = scrol.nMax - scrol.nPage;
if(maxpos <= minpos)
return;
long* pLastPost;
if (nBar == SB_VERT)
{
pLastPost = &m_ScrollPos.y;
}
else if(nBar == SB_HORZ)
{
pLastPost = &m_ScrollPos.x;
}
else
{
return;
}
long& nRealPos = *pLastPost;
int oldPos = nRealPos;
// Determine the new position of scroll box.
switch (nSBCode)
{
case SB_TOP: // Scroll to far left.
nRealPos = minpos;
break;
case SB_BOTTOM: // Scroll to far right.
nRealPos = maxpos;
break;
case SB_LINEUP: // Scroll left.
nRealPos -= 10;
if (nRealPos < minpos)
nRealPos = minpos;
break;
case SB_LINEDOWN: // Scroll right.
nRealPos += 10;
if (nRealPos > maxpos)
nRealPos = maxpos;
break;
case SB_PAGEUP: // Scroll one page left.
nRealPos -= scrol.nPage;
if (nRealPos < minpos)
nRealPos = minpos;
break;
case SB_PAGEDOWN: // Scroll one page right.
nRealPos += scrol.nPage;
if (nRealPos > maxpos)
nRealPos = maxpos;
break;
case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
nRealPos = nPos; // of the scroll box at the end of the drag operation.
break;
case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is the
nRealPos = nPos; // position that the scroll box has been dragged to.
break;
}
SetScrollPos(nBar, nRealPos);
if (nBar == SB_VERT)
{
ScrollWindow(0, oldPos - nRealPos);
CDialogEx::OnVScroll(nSBCode, nRealPos, pScrollBar);
}
else if(nBar == SB_HORZ)
{
ScrollWindow(oldPos - nRealPos, 0);
CDialogEx::OnHScroll(nSBCode, nRealPos, pScrollBar);
}
}
void CColorDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
DoHVScroll(SB_HORZ, nSBCode, nPos, pScrollBar);
}
void CColorDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
DoHVScroll(SB_VERT, nSBCode, nPos, pScrollBar);
}
void CColorDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
if (m_bNoScroll) return;
if (GetSafeHwnd())
{
if (cy > m_rcOriginalRect.Height())
{
SetScrollPos(SB_VERT, 0);
ScrollWindow(0, m_ScrollPos.y);
m_ScrollPos.y = 0;
}
if (cx > m_rcOriginalRect.Width())
{
SetScrollPos(SB_HORZ, 0);
ScrollWindow(m_ScrollPos.x, 0);
m_ScrollPos.x = 0;
}
}
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL;
si.nMin = 0;
si.nMax = m_rcOriginalRect.Height();
si.nPage = cy;
si.nPos = 0;
SetScrollInfo(SB_VERT, &si, TRUE);
si.nMax = m_rcOriginalRect.Width();
si.nPage = cx;
SetScrollInfo(SB_HORZ, &si, TRUE);
}
// PostMessage(WM_MOUSEWHEEL,(UINT)MAKELONG(nFlags,zDelta),(LPARAM)MAKELONG(pt.x,pt.y));
BOOL CColorDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
BOOL bUp = TRUE;
int nDelta = zDelta;
if(zDelta < 0) {
bUp = FALSE;
nDelta = -nDelta;
}
UINT nWheelScrollLines;
::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
&nWheelScrollLines, 0);
int nLines = (nDelta * nWheelScrollLines) / WHEEL_DELTA;
while(nLines--)
SendMessage(WM_VSCROLL, MAKEWPARAM(bUp ? SB_LINEUP : SB_LINEDOWN, 0), 0);
return CDialogEx::OnMouseWheel(nFlags, zDelta, pt);
}
//void CColorDlg::OnLButtonDown(UINT nFlags, CPoint point)
//{
//
// m_bDragging=TRUE;
// SetCapture();
//
// m_ptDragPoint=point;
//
// SetCursor(m_hCursor2);
// CDialogEx::OnLButtonDown(nFlags, point);
//}
//
//void CColorDlg::OnLButtonUp(UINT nFlags, CPoint point)
//{
// EndDrag();
//
// CDialogEx::OnLButtonUp(nFlags, point);
//}
//
//void CColorDlg::OnMouseMove(UINT nFlags, CPoint point)
//{
// if (m_bDragging)
// {
// int nDelta=m_ptDragPoint.y-point.y;
// m_ptDragPoint=point;
//
// int nNewPos=m_nScrollPos+nDelta;
//
// if (nNewPos<0)
// nNewPos=0;
// else if (nNewPos>m_rcOriginalRect.Height() - m_nCurHeight)
// nNewPos=m_rcOriginalRect.Height() - m_nCurHeight;
//
// nDelta=nNewPos-m_nScrollPos;
// m_nScrollPos=nNewPos;
//
// SetScrollPos(SB_VERT,m_nScrollPos,TRUE);
// ScrollWindow(0,-nDelta);
// }
//
// CDialogEx::OnMouseMove(nFlags, point);
//}
//
//void CColorDlg::OnKillFocus(CWnd* pNewWnd)
//{
// CDialogEx::OnKillFocus(pNewWnd);
//
// EndDrag();
//}
//
//void CColorDlg::EndDrag()
//{
// m_bDragging=FALSE;
// ReleaseCapture();
// SetCursor(m_hCursor1);
//}
//
//BOOL CColorDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
//{
// BOOL bRet=TRUE;
//
// if (nHitTest==HTCLIENT)
// {
// SetCursor(m_hCursor1);
// bRet=FALSE;
// }
// else
// bRet=CDialogEx::OnSetCursor(pWnd,nHitTest,message);
//
// return bRet;
//}
//int CColorDlg::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
//{
// // TODO: 在此添加消息处理程序代码和/或调用默认值
// //SetFocus();
//
// //return MA_ACTIVATE;
//
// return CDialogEx::OnMouseActivate(pDesktopWnd, nHitTest, message);
//}
#29
#pragma once
// CColorDlg
class CColorDlg : public CDialogEx
{
DECLARE_DYNAMIC(CColorDlg)
public:
CColorDlg();
CColorDlg(UINT nIDTemplate, CWnd *pParent = NULL);
virtual ~CColorDlg();
void DoHVScroll(int nBar, UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
void SetNoScroll(BOOL bNoScroll = TRUE) { m_bNoScroll = bNoScroll; }
// 对话框数据
HCURSOR m_hCursor1, m_hCursor2;
// dialog size as you see in the resource view (original size)
CRect m_rcOriginalRect;
// dragging
BOOL m_bDragging;
CPoint m_ptDragPoint;
// actual scroll position
CPoint m_ScrollPos;
BOOL m_bNoScroll;
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
//afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
//afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
//afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//afx_msg void OnKillFocus(CWnd* pNewWnd);
public:
virtual BOOL OnInitDialog();
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
//afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
//afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
};
class VisualStyleHelper
{
public:
static void DetermineCurrentThemeClr();
static CBrush& GetBackgroundBr();
public:
static COLORREF s_clrBackground;
static CBrush s_brBackground;
};
#30
只是背景色变化.
需要改变背景色的时候调用
RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);
需要改变背景色的时候调用
RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);
#31
楼上 是对话框的客户区背景色么 你试试SetBackgroundColor()?
#32
我是要根据你现在的主题能自动变
#33
发现个有趣的 设置了office07的主题后 对话框是不会变化 不过里面的cmfcpropertygridctrl却有主题的改变 哈哈
#34

难道我代码没给全?不是吧..哈哈
#35
呵呵 还没试你的代码