Click here to Skip to main content
15,900,378 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: change background color of dialog Pin
zhiyuan1629-Dec-08 1:43
zhiyuan1629-Dec-08 1:43 
AnswerRe: change background color of dialog Pin
Malli_S29-Dec-08 2:17
Malli_S29-Dec-08 2:17 
GeneralRe: change background color of dialog Pin
zhiyuan1629-Dec-08 17:10
zhiyuan1629-Dec-08 17:10 
GeneralRe: change background color of dialog Pin
Malli_S29-Dec-08 19:09
Malli_S29-Dec-08 19:09 
GeneralRe: change background color of dialog Pin
zhiyuan1629-Dec-08 20:23
zhiyuan1629-Dec-08 20:23 
GeneralRe: change background color of dialog Pin
zhiyuan1629-Dec-08 20:37
zhiyuan1629-Dec-08 20:37 
GeneralRe: change background color of dialog Pin
Malli_S29-Dec-08 21:11
Malli_S29-Dec-08 21:11 
GeneralRe: change background color of dialog Pin
zhiyuan1629-Dec-08 21:26
zhiyuan1629-Dec-08 21:26 
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_MAP
	
	
	ON_BN_CLICKED(IDC_ChangeBKColor, &CMeiTengDlg::OnBnClickedChangebkcolor)
END_MESSAGE_MAP()


// CMeiTengDlg message handlers

BOOL CMeiTengDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	m_objMyBrush.CreateSolidBrush(RGB(255, 255, 255)); // color white brush


	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMeiTengDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMeiTengDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMeiTengDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

BOOL CMeiTengDlg::OnDistroyWindow()
{
	//delete it while distroying the dialog.  
	m_objMyBrush.DeleteObject();
	return CDialog::DestroyWindow(); 
}


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);
}

GeneralRe: change background color of dialog Pin
Malli_S29-Dec-08 22:07
Malli_S29-Dec-08 22:07 
GeneralRe: change background color of dialog Pin
zhiyuan1629-Dec-08 23:24
zhiyuan1629-Dec-08 23:24 
AnswerRe: change background color of dialog Pin
Malli_S29-Dec-08 23:49
Malli_S29-Dec-08 23:49 
GeneralRe: change background color of dialog Pin
zhiyuan1629-Dec-08 23:58
zhiyuan1629-Dec-08 23:58 
AnswerRe: change background color of dialog Pin
Jijo.Raj29-Dec-08 1:22
Jijo.Raj29-Dec-08 1:22 
Questionhow to proceed?? Pin
debonair12345629-Dec-08 0:52
debonair12345629-Dec-08 0:52 
AnswerRe: how to proceed?? Pin
Malli_S29-Dec-08 1:21
Malli_S29-Dec-08 1:21 
GeneralRe: how to proceed?? Pin
debonair12345629-Dec-08 1:38
debonair12345629-Dec-08 1:38 
GeneralRe: how to proceed?? Pin
Malli_S29-Dec-08 2:30
Malli_S29-Dec-08 2:30 
AnswerRe: how to proceed?? Pin
Hamid_RT29-Dec-08 1:34
Hamid_RT29-Dec-08 1:34 
GeneralRe: how to proceed?? Pin
debonair12345629-Dec-08 1:54
debonair12345629-Dec-08 1:54 
GeneralRe: how to proceed?? Pin
ThatsAlok29-Dec-08 21:57
ThatsAlok29-Dec-08 21:57 
GeneralRe: how to proceed?? Pin
debonair12345629-Dec-08 22:56
debonair12345629-Dec-08 22:56 
GeneralRe: how to proceed?? Pin
ThatsAlok30-Dec-08 0:07
ThatsAlok30-Dec-08 0:07 
GeneralRe: how to proceed?? [modified] Pin
debonair12345630-Dec-08 0:52
debonair12345630-Dec-08 0:52 
QuestionWhat wrong with this code? Pin
SNI29-Dec-08 0:50
SNI29-Dec-08 0:50 
GeneralRe: What wrong with this code? Pin
Malli_S29-Dec-08 1:01
Malli_S29-Dec-08 1:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.