Click here to Skip to main content
15,915,164 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: I think that works.... Pin
ns28-Jan-03 9:45
ns28-Jan-03 9:45 
GeneralRe: I think that works.... Pin
ns28-Jan-03 9:50
ns28-Jan-03 9:50 
GeneralThe SDK in question.... Pin
ns28-Jan-03 10:47
ns28-Jan-03 10:47 
GeneralRe: The SDK in question.... Pin
Michael Dunn28-Jan-03 15:49
sitebuilderMichael Dunn28-Jan-03 15:49 
GeneralOpenDocumentFile Pin
Dov Sherman28-Jan-03 6:25
Dov Sherman28-Jan-03 6:25 
GeneralRe: OpenDocumentFile Pin
Roger Allen29-Jan-03 1:35
Roger Allen29-Jan-03 1:35 
GeneralRe: OpenDocumentFile Pin
Dov Sherman29-Jan-03 6:40
Dov Sherman29-Jan-03 6:40 
GeneralOnPaint( ) -- how do I Pin
john john mackey28-Jan-03 5:31
john john mackey28-Jan-03 5:31 
Please help.

I created a dialog app that contains a picture control which acts like a button.

The picture control (IDC_MODEL_COLOR) will bring up the common dialog CColorDialog and allows the user to select an RGB color. This color will then repaint the picture control to show the user the color that was selected.

My problem is in initialization and the odd case of toggling focus between my app and another window on the desktop.

Initialization Problem:
The correct color of IDC_MODEL_COLOR is not displayed when my dialog appears.
(See code for constructor and OnInitDialog() below and the visual at
http://www.dlowracing.org/mmedia/Dialog_Black.gif 3kb
http://www.dlowracing.org/mmedia/Dialog_Red.gif 3kb -- what should be)

Toggle Problem:
When I change focus between my dialog app and another window on the screen, without moving either window, the picture control is not repainted. For example, if part of
IDC_MODEL_COLOR is covered by another window and I toggle focus between the two (Without moving either window), the part that was covered is not repainted.
(See http://www.dlowracing.org/mmedia/CColorDialog_.gif 9kb)


Below is the code that supports my dialog based app.

Thank you for your help.
Johnny



/////////////////////////////////////////////////////////////////////////////
// CColorTestDlg dialog --- ColorTestDlg.h

class CColorTestDlg : public CDialog
{
// Construction
public:
CColorTestDlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data
//{{AFX_DATA(CColorTestDlg)
enum { IDD = IDD_COLORTEST_DIALOG };
CEdit m_edit_red;
CEdit m_edit_green;
CEdit m_edit_blue;
int m_red;
int m_green;
int m_blue;
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CColorTestDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

public:
void SetModelColorSwatch(COLORREF rgbColor);

private:
COLORREF m_ModelColor;
CRect m_ModelColorSwatch;

// Implementation
protected:
HICON m_hIcon;

// Generated message map functions
//{{AFX_MSG(CColorTestDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnModelColor();
afx_msg void OnKillFocusBlue();
afx_msg void OnKillFocusGreen();
afx_msg void OnKillFocusRed();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};



/////////////////////////////////////////////////////////////////////////////
// CColorTestDlg dialog --- ColorTestDlg.cpp

CColorTestDlg::CColorTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CColorTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CColorTestDlg)
m_red = 255;
m_green = 0;
m_blue = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

// IDC_MODEL_COLOR properties: Rectangle, Black, Sunken, Notify

m_ModelColor = RGB(255,0,0); // Initialize to RED
}

void CColorTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CColorTestDlg)
DDX_Control(pDX, IDC_EDIT_RED, m_edit_red);
DDX_Control(pDX, IDC_EDIT_GREEN, m_edit_green);
DDX_Control(pDX, IDC_EDIT_BLUE, m_edit_blue);
DDX_Text(pDX, IDC_EDIT_BLUE, m_blue);
DDX_Text(pDX, IDC_EDIT_GREEN, m_green);
DDX_Text(pDX, IDC_EDIT_RED, m_red);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CColorTestDlg, CDialog)
//{{AFX_MSG_MAP(CColorTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_MODEL_COLOR, OnModelColor)
ON_EN_KILLFOCUS(IDC_EDIT_BLUE, OnKillFocusBlue)
ON_EN_KILLFOCUS(IDC_EDIT_GREEN, OnKillFocusGreen)
ON_EN_KILLFOCUS(IDC_EDIT_RED, OnKillFocusRed)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CColorTestDlg message handlers

BOOL CColorTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();

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

SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here

// Calculate true location of the color swatch
// Get a pointer to CWnd
CWnd* pModelColor = GetDlgItem(IDC_MODEL_COLOR);
// Find its location on screen
pModelColor->GetWindowRect(&m_ModelColorSwatch);
// Store client coordinates
ScreenToClient(&m_ModelColorSwatch);
m_ModelColorSwatch.DeflateRect(2, 2, 1, 1);

return TRUE;
}

void CColorTestDlg::OnPaint()
{
SetModelColorSwatch(m_ModelColor);

if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (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();
}
}

void CColorTestDlg::OnModelColor()
{
CColorDialog dlg(m_ModelColor, CC_FULLOPEN);

if (dlg.DoModal() == IDOK)
{
// update the parent's color variables
m_ModelColor = dlg.GetColor();

CBrush swatch;
swatch.CreateSolidBrush(m_ModelColor);
CClientDC dc(this);
dc.FillRect(&m_ModelColorSwatch, &swatch);
}
}

// update the color swatch with the RGB color value
void CColorTestDlg::SetModelColorSwatch(COLORREF rgbColor)
{
CBrush swatch;
swatch.CreateSolidBrush(rgbColor);
CClientDC dc(this);
dc.FillRect(&m_ModelColorSwatch, &swatch);
}
GeneralRe: OnPaint( ) -- how do I Pin
john john mackey28-Jan-03 6:20
john john mackey28-Jan-03 6:20 
QuestionIs it possible to insert a new line (\n) in a tool tip? Pin
Luis E. Cuadrado28-Jan-03 5:22
Luis E. Cuadrado28-Jan-03 5:22 
AnswerRe: Is it possible to insert a new line (\n) in a tool tip? Pin
will138328-Jan-03 5:29
will138328-Jan-03 5:29 
AnswerRe: Is it possible to insert a new line (\n) in a tool tip? Pin
PJ Arends28-Jan-03 7:39
professionalPJ Arends28-Jan-03 7:39 
AnswerRe: Is it possible to insert a new line (\n) in a tool tip? Pin
Luis E. Cuadrado28-Jan-03 8:00
Luis E. Cuadrado28-Jan-03 8:00 
GeneralMessage Propagation (MFC related) Pin
will138328-Jan-03 5:06
will138328-Jan-03 5:06 
GeneralLogin Screen Pin
ClemenceD28-Jan-03 5:04
ClemenceD28-Jan-03 5:04 
Generaltarget a global security group c++ Pin
Member 13661828-Jan-03 4:39
Member 13661828-Jan-03 4:39 
GeneralRe: target a global security group c++ Pin
Abbas_Riazi28-Jan-03 4:59
professionalAbbas_Riazi28-Jan-03 4:59 
GeneralRe: target a global security group c++ Pin
Member 13661828-Jan-03 5:08
Member 13661828-Jan-03 5:08 
GeneralRe: target a global security group c++ Pin
Rickard Andersson2028-Jan-03 10:47
Rickard Andersson2028-Jan-03 10:47 
GeneralSite Administration Pin
Abbas_Riazi28-Jan-03 4:35
professionalAbbas_Riazi28-Jan-03 4:35 
GeneralRe: Site Administration Pin
#realJSOP28-Jan-03 4:55
professional#realJSOP28-Jan-03 4:55 
GeneralRe: Site Administration Pin
Abbas_Riazi28-Jan-03 5:02
professionalAbbas_Riazi28-Jan-03 5:02 
Questionhow to disable button on CDlgBar? Pin
gjun lee28-Jan-03 4:03
gjun lee28-Jan-03 4:03 
AnswerRe: how to disable button on CDlgBar? Pin
Rage28-Jan-03 4:16
professionalRage28-Jan-03 4:16 
GeneralRe: how to disable button on CDlgBar? Pin
gjun lee28-Jan-03 5:01
gjun lee28-Jan-03 5: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.