change background color of dialog
-
Dear all how to change the background color of dialog, i have done some code below, pls help me to check, however i couldn't change the background color after i picked the color. thanks.
void CMeiTengDlg::OnBnClickedChangebkcolor()
{
// TODO: Add your control notification handler code here
CColorDialog dlg;
if (dlg.DoModal() == IDOK)
COLORREF color=dlg.GetColor();
//change my background color of dialog code here}
-
Dear all how to change the background color of dialog, i have done some code below, pls help me to check, however i couldn't change the background color after i picked the color. thanks.
void CMeiTengDlg::OnBnClickedChangebkcolor()
{
// TODO: Add your control notification handler code here
CColorDialog dlg;
if (dlg.DoModal() == IDOK)
COLORREF color=dlg.GetColor();
//change my background color of dialog code here}
-
Dear all how to change the background color of dialog, i have done some code below, pls help me to check, however i couldn't change the background color after i picked the color. thanks.
void CMeiTengDlg::OnBnClickedChangebkcolor()
{
// TODO: Add your control notification handler code here
CColorDialog dlg;
if (dlg.DoModal() == IDOK)
COLORREF color=dlg.GetColor();
//change my background color of dialog code here}
-
thanks, malli i would like to use this way what i mentioned in the previous post. how can i achieve it? thanks a lot.
-
Delete the old brush and update the brush color by creating the new one
m_brush.CreateSolidBrush(RGB(255, 255, 255));
with the selected color.
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:****thanks malli don't understand well, i wanna change different color for different person, when someone click change background color. so i need a changbackground(COLORREF color), don't how to write down it. thanks. could you help me. thanks. i tried your that way, just can change once.
-
thanks malli don't understand well, i wanna change different color for different person, when someone click change background color. so i need a changbackground(COLORREF color), don't how to write down it. thanks. could you help me. thanks. i tried your that way, just can change once.
I hope following code snippet will help you. I've not included the details in depth. Just try it out.
class CMeiTengDlg: public CDialog
{
...
//Add the member variable.
protected:
CBrush m_objMyBrush;...
};BOOL CMyDlg::OnInitDialog()
{
...
//initialize it with default brush color (back color)
m_objMyBrush.CreateSolidBrush(RGB(255, 255, 255)); // color white brush
...
}BOOL CMyDlg::DistroyWindow()
{
//delete it while distroying the dialog.
m_objMyBrush.DeleteObject();
}HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
/*
** No need to do this!
**
** HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
*//*
** Return your brush.
*/
return m_objMyBrush;
}void CMeiTengDlg::OnBnClickedChangebkcolor()
{
// TODO: Add your control notification handler code here
CColorDialog dlg;
if (dlg.DoModal() == IDOK)
COLORREF color=dlg.GetColor();
//change my background color of dialog code here
changbackground(color);
}//probably this is what you were searching for
void CMeiTengDlg::changbackground(COLORREF color)
{
//change the brush color
m_objMyBrush.DeleteObject();
m_objMyBrush.CreateSolidBrush( color );
Invalidate(TRUE);
}[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:**** -
I hope following code snippet will help you. I've not included the details in depth. Just try it out.
class CMeiTengDlg: public CDialog
{
...
//Add the member variable.
protected:
CBrush m_objMyBrush;...
};BOOL CMyDlg::OnInitDialog()
{
...
//initialize it with default brush color (back color)
m_objMyBrush.CreateSolidBrush(RGB(255, 255, 255)); // color white brush
...
}BOOL CMyDlg::DistroyWindow()
{
//delete it while distroying the dialog.
m_objMyBrush.DeleteObject();
}HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
/*
** No need to do this!
**
** HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
*//*
** Return your brush.
*/
return m_objMyBrush;
}void CMeiTengDlg::OnBnClickedChangebkcolor()
{
// TODO: Add your control notification handler code here
CColorDialog dlg;
if (dlg.DoModal() == IDOK)
COLORREF color=dlg.GetColor();
//change my background color of dialog code here
changbackground(color);
}//probably this is what you were searching for
void CMeiTengDlg::changbackground(COLORREF color)
{
//change the brush color
m_objMyBrush.DeleteObject();
m_objMyBrush.CreateSolidBrush( color );
Invalidate(TRUE);
}[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:****thanks Malli i want to confirm i just wanna change my CMeiTengDlg background color, what mentioned above is CMyDlg, CAboutDlg, so i no need to add one class, right? so i followed your idea, but after compiled, one error is
c:\documents and settings\zhiyuan li\desktop\meiteng\meiteng\meitengdlg.cpp(163) : error C4716: 'CMeiTengDlg::DistroyWindow' : must return a value Build log was saved at "file://c:\Documents and Settings\ZhiYuan Li\Desktop\MeiTeng\MeiTeng\Debug\BuildLog.htm" MeiTeng - 1 error(s), 0 warning(s)
by the way,could i get your email, and keep in touch. thanks. -
thanks Malli i want to confirm i just wanna change my CMeiTengDlg background color, what mentioned above is CMyDlg, CAboutDlg, so i no need to add one class, right? so i followed your idea, but after compiled, one error is
c:\documents and settings\zhiyuan li\desktop\meiteng\meiteng\meitengdlg.cpp(163) : error C4716: 'CMeiTengDlg::DistroyWindow' : must return a value Build log was saved at "file://c:\Documents and Settings\ZhiYuan Li\Desktop\MeiTeng\MeiTeng\Debug\BuildLog.htm" MeiTeng - 1 error(s), 0 warning(s)
by the way,could i get your email, and keep in touch. thanks.Sorry Zhiyuan16, I forgot to replace the CMyDls with your dialog class name. And you should return value from DestroyWindow function. I had deleted rest of the code (and put ....) considering you'd put the required one. For details have a look at here[^]
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:**** -
Sorry Zhiyuan16, I forgot to replace the CMyDls with your dialog class name. And you should return value from DestroyWindow function. I had deleted rest of the code (and put ....) considering you'd put the required one. For details have a look at here[^]
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:**** -
thanks Malli comiling had no problem, but still no color change of background after i chose different color. where is problem, Malli? thanks
dear Malli could you help me to check is it right below: thanks a lot
BOOL CMeiTengDlg::OnDestroyWindow() { //delete it while distroying the dialog. m_objMyBrush.DeleteObject(); return TRUE; } HBRUSH CMeiTengDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { return m_objMyBrush; } void CMeiTengDlg::SetBackgroundColor(COLORREF color) { m_objMyBrush.DeleteObject(); m_objMyBrush.CreateSolidBrush( color ); //redraw Invalidate(TRUE); } void CMeiTengDlg::OnBnClickedChangebkcolor() { // TODO: Add your control notification handler code here CColorDialog dlg; if (dlg.DoModal() == IDOK) color=dlg.GetColor(); //change my background color of dialog code here SetBackgroundColor(color); }
-
dear Malli could you help me to check is it right below: thanks a lot
BOOL CMeiTengDlg::OnDestroyWindow() { //delete it while distroying the dialog. m_objMyBrush.DeleteObject(); return TRUE; } HBRUSH CMeiTengDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { return m_objMyBrush; } void CMeiTengDlg::SetBackgroundColor(COLORREF color) { m_objMyBrush.DeleteObject(); m_objMyBrush.CreateSolidBrush( color ); //redraw Invalidate(TRUE); } void CMeiTengDlg::OnBnClickedChangebkcolor() { // TODO: Add your control notification handler code here CColorDialog dlg; if (dlg.DoModal() == IDOK) color=dlg.GetColor(); //change my background color of dialog code here SetBackgroundColor(color); }
The above code worked for me (only 'color' variable I found missing). Do you have any overlapping control on your dialog ? And I think you should call return CDialog::DestroyWindow(); in your dialog's DistroyWindow();
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:**** -
The above code worked for me (only 'color' variable I found missing). Do you have any overlapping control on your dialog ? And I think you should call return CDialog::DestroyWindow(); in your dialog's DistroyWindow();
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:****no other control.. Malli could you check for me the following my dialog .h and .cpp files thanks. CMeiTengDlg.h file
// MeiTengDlg.h : header file
//#pragma once
#include "afxwin.h"// CMeiTengDlg dialog
class CMeiTengDlg : public CDialog
{
// Construction
public:
CMeiTengDlg(CWnd* pParent = NULL); // standard constructor
void SetBackgroundColor(COLORREF color);// Dialog Data
enum { IDD = IDD_MEITENG_DIALOG };protected: virtual void DoDataExchange(CDataExchange\* pDX); // DDX/DDV support
// Implementation
protected:
HICON m_hIcon;
//CBrush m_brush;
//COLORREF m_crBackGnd;
CBrush m_objMyBrush;
COLORREF color;// Generated message map functions virtual BOOL OnInitDialog(); virtual BOOL OnDistroyWindow(); afx\_msg void OnSysCommand(UINT nID, LPARAM lParam); afx\_msg void OnPaint(); afx\_msg HCURSOR OnQueryDragIcon(); afx\_msg HBRUSH OnCtlColor(CDC\* pDC, CWnd\* pWnd, UINT nCtlColor); DECLARE\_MESSAGE\_MAP()
public:
CComboBox m\_pComboBox; //afx\_msg HBRUSH OnCtlColor(CDC\* pDC, CWnd\* pWnd, UINT nCtlColor); afx\_msg void OnBnClickedChangebkcolor();
};
CMeiTengDlg.cpp file
// MeiTengDlg.cpp : implementation file
//#include "stdafx.h"
#include "MeiTeng.h"
#include "MeiTengDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#endif// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();// Dialog Data
enum { IDD = IDD_ABOUTBOX };protected: virtual void DoDataExchange(CDataExchange\* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()// CMeiTengDlg dialog
CMeiTengDlg::CMeiTengDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMeiTengDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}void CMeiTengDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_BITMAP, m_pComboBox);
// DDX_Control(pDX, IDC_Enjoystatic, m_pEnjoyStatic);
}BEGIN_MESSAGE_MAP(CMeiTengDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAPON\_BN\_CLICKED(IDC\_ChangeBKColor, &CMeiTengDlg::OnBnClickedChangebkcolor)
END_MESSAGE_MAP()
// CMeiTengDlg message handlers
BOOL CMeiTengDlg::OnInitDialog()
-
no other control.. Malli could you check for me the following my dialog .h and .cpp files thanks. CMeiTengDlg.h file
// MeiTengDlg.h : header file
//#pragma once
#include "afxwin.h"// CMeiTengDlg dialog
class CMeiTengDlg : public CDialog
{
// Construction
public:
CMeiTengDlg(CWnd* pParent = NULL); // standard constructor
void SetBackgroundColor(COLORREF color);// Dialog Data
enum { IDD = IDD_MEITENG_DIALOG };protected: virtual void DoDataExchange(CDataExchange\* pDX); // DDX/DDV support
// Implementation
protected:
HICON m_hIcon;
//CBrush m_brush;
//COLORREF m_crBackGnd;
CBrush m_objMyBrush;
COLORREF color;// Generated message map functions virtual BOOL OnInitDialog(); virtual BOOL OnDistroyWindow(); afx\_msg void OnSysCommand(UINT nID, LPARAM lParam); afx\_msg void OnPaint(); afx\_msg HCURSOR OnQueryDragIcon(); afx\_msg HBRUSH OnCtlColor(CDC\* pDC, CWnd\* pWnd, UINT nCtlColor); DECLARE\_MESSAGE\_MAP()
public:
CComboBox m\_pComboBox; //afx\_msg HBRUSH OnCtlColor(CDC\* pDC, CWnd\* pWnd, UINT nCtlColor); afx\_msg void OnBnClickedChangebkcolor();
};
CMeiTengDlg.cpp file
// MeiTengDlg.cpp : implementation file
//#include "stdafx.h"
#include "MeiTeng.h"
#include "MeiTengDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#endif// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();// Dialog Data
enum { IDD = IDD_ABOUTBOX };protected: virtual void DoDataExchange(CDataExchange\* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()// CMeiTengDlg dialog
CMeiTengDlg::CMeiTengDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMeiTengDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}void CMeiTengDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_BITMAP, m_pComboBox);
// DDX_Control(pDX, IDC_Enjoystatic, m_pEnjoyStatic);
}BEGIN_MESSAGE_MAP(CMeiTengDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAPON\_BN\_CLICKED(IDC\_ChangeBKColor, &CMeiTengDlg::OnBnClickedChangebkcolor)
END_MESSAGE_MAP()
// CMeiTengDlg message handlers
BOOL CMeiTengDlg::OnInitDialog()
-
ON_WM_CTLCOLOR() is missing in your message map. I hope you've added OnCtlColor handler manually.
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:**** -
thanks malli now is ok. i have one more question here: in my dialog, i have several buttons, when i changed the background color, but dun chanaged the buttons' color, how can i can change the buttons' color after i choose different color. thanks
-
I think this[^] would help you.
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:****thanks, malli i have 3 radio buttons and one common button now, for 3 radio buttons, one is change background color, one is play music, last one is browse photoes, so when i check anyone radio button, and my that common button will show correspoding content what the radio button contains. thanks a lot.i searched online, but my pc and connection are slow, counldn't find. thanks.