Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dialog Boxes, Help. Please.

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Upon reading data from database onto a readonly dialog box, fonts seems light, can someone pls help me and tell me how i can change edit boxes on a dialog box, to highlight fonts, and how i can change certain font colour in edit boxes.
Please, Please Help
 
Thanks Mat for the link, look intresting tried it but did not work, could understand code as far as OnInitiaDialog();
andthere after its confusing.
Because i have DoDataExchange on my dialog box, can not work out code on the link.

Tried code
m_ItemName // handle for ItemName Edit Box;
SetTextColor(m_ItemName,bluecolor); // Member variable
declared as on "html link"

cannot convert CString to HDC_ error

Can some please help, or tel me if there is another way of doing this...

thanks.
 

basically, you have to override the OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)method to change the color
in this method,
you can check if your edit control(with ID "IDC_EDIT1")asks for color,
if (nCtlColor == CTLCOLOR_EDIT && pWnd->GetDlgCtrlID()== IDC_EDIT1){
pDC->SetBkColor(RGB(0,0,255)); // change the background color of text to BLUE
pDC->SetTextColor(RGB(255,0,0)); // change the text color to RED
}

 
I am sure i am doing something wrong here or something i am not suppose to , please help.

my code looks like one below....

// in dialog partdetails.h header file.

bool OnCtlColor(CDC* pDC,CWnd* pWnd, UINT nCtlColor);


// in my dialog partdetails.cpp file

void CPartDetails::DoDataExchange(CDataExchange* pDX )
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPartDetails)
DDX_Text(pDX, IDC_PART_CODE, m_PDPartCode);
}

// color function decl.

bool CPartDetails::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if (nCtlColor == CTLCOLOR_EDIT && pWnd->GetDlgCtrlID()==IDC_PART_CODE)
{ pDC->SetBkColor(RGB(0,0,255));
pDC->SetTextColor(RGB(255,0,0));
}
return true;
}

// original code with switch statment to enable disable buttons.

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

//background colours decl.

m_redcolor = RGB(255,0,0); //red
m_bluecolor = RGB(0,0,255); //Blue
m_textcolor = RGB(255,255,255); //White
m_bluebrush.CreateSolidBrush(m_bluecolor); //blue background
m_redbrush.CreateSolidBrush(m_redcolor); //red background

switch(m_dlgType)
{

case DLG_DETAILS:
default:
{
// need to fill color to edit box and change font color.
// ERROR does not work, requires parameters
//doing something wrong................

OnCtlColor();
break;
}
}


return TRUE;
}
 
OnCtlColor is the handler of WM_CTLCOLOR windows messages, you can let classwizard to generate this function for you. or put
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
into the //{{AFX_MSG(CPartDetails)
//}}AFX_MSG block of the head file.
notice OnCtlColor has return type HBRUSH.
 
I am sorry mat, but i am getting this...

my header file now has as you said above and have remove bool funtion from header file.

and the CPP file now a has function and bool function from above removed.

HBRUSH CPartDetails::OnCtlColor(..................)
{
HBRUSH hbr;
if (nCtlColor == CTLCOLOR_EDIT && pWnd->GetDlgCtrlID()==IDC_PART_CODE)
{ pDC->SetBkColor(RGB(0,0,255));
pDC->SetTextColor(RGB(255,0,0));
}
return hbr;
}

I assum this funtion paints and changes the text box?

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

//background colours decl.

m_redcolor = RGB(255,0,0); //red
m_bluecolor = RGB(0,0,255); //Blue
m_textcolor = RGB(255,255,255); //White
m_bluebrush.CreateSolidBrush(m_bluecolor); //blue background
m_redbrush.CreateSolidBrush(m_redcolor); //red background

switch(m_dlgType)
{

case DLG_DETAILS:
default:
{

*********How can i call the function here to do the paint**
*******PLS HELP.**********************Need parameters**
OnCtlColor();
break;
}
}


return TRUE;
}

 
Don't call OnCtlColor in your OnInitDialog(). The system will call it automatically.
It should work.
 
probably got my wrong because it doesn't work..
any sugestions,
I have my edit boxes as read only could this be the problem?
 
Yes, if the edit box is read only, it does not work.
Instead I think you can use static text box. the code in OnCtlcolor looks like,
HBRUSH CTestDlgDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

if (nCtlColor == CTLCOLOR_STATIC && pWnd->GetDlgCtrlID() == IDC_PART_CODE){
pDC->SetBkColor(RGB(0,0,255));
pDC->SetTextColor(RGB(255,0,0));
}
return hbr;
}
if you really need edit box with read-only property, I think you have to derive a class from CEdit and override OnPaint().
 
Mat, I think there is somthing missing, i think the function is not called up, i tried it by adding a new static box to dialog box, and it still did not work..

I need a Edit box because it can handle COlecurrance variable while Static boxes can only handle CString and possible with Read only so that user is not allowed to delete any details.

As long as i can get the Fonts in different colour OR Bold so that is readable in a readonly Edit box, and possible increase Font Size in some Edit Boxes where neccessories.

There must be another way of doing this, a much easier way..

Help would be much appreciated..
 
use the very code of my last post for the read-only edit box. I tested it and it worked. The reason is that read-only edit box is somehow changed to static text box.
 
jfhuanh, I think you have something ectra in your program thats missing in my program.

Just created a new project with a test dialog box with one edit box and following code in appropiate files.

header file

:protected:

// Generated message map functions
//{{AFX_MSG(CCDlgcolor)

virtual BOOL OnInitDialog();

afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);

// NOTE: the ClassWizard will add member functions here
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
CBrush m_redbrush,m_bluebrush;
COLORREF m_redcolor,m_bluecolor,m_textcolor;


};

CPP DIALOG FILE.

HBRUSH CCDlgcolor::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC,pWnd,nCtlColor);

if (nCtlColor == CTLCOLOR_EDIT && pWnd->GetDlgCtrlID() == IDC_EDCOLOR )
{
pDC->SetBkColor(RGB(0,0,255));
pDC->SetTextColor(RGB(255,0,0));
}

return hbr;
}

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

return true;

}

The dialog appears BUT NO BK COLOR NOR FONT COLOR
presume your code looks the same.
could i be missing headder file.
I am sure the Function OnCtlColor is not called up....
I am using VC++5.0 , could this be the problem.

pls.pls.help.


 
Tried with CTLCOLOR_STATIC with edit box, still nothing, there is still somthing i am missing out.
I am going to go mad.
Is your working code same as mine, i am surpise your code is working,
I am sure function is not called up!!!!!

any thing else that i should try.Hlp.


 
I just found out that the function OnCtlColor is not called upon dialog initial.
I tested it by passing value to the edit box in the OnInitDialog, with UpdateDate(FALSE) and it work, it printed what i wanted but upon doing the same in OnCtlColor function no text appeared in the edit box.
Did you use Wizard to generate your OnCtlcolor handler!!
I typed my in as you said!!
missing somthing else somewhere...
 
I create a clean code for you, you can check that. There is a read-only edit box with ID IDC_EDIT1 in the dialog. "test1" is displayed in the edit box.

// test.h
class CTestDlg : public CDialog
{
// Construction
public:
CTestDlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data
//{{AFX_DATA(CTestDlg)
enum { IDD = IDD_TEST_DIALOG };
CString m_Value;
//}}AFX_DATA

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

// Implementation
protected:

// Generated message map functions
//{{AFX_MSG(CTestDlg)
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};


// test.cpp
CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestDlg)
m_Value = _T("test1");
//}}AFX_DATA_INIT
}

void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestDlg)
DDX_Text(pDX, IDC_EDIT1, m_Value);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
//{{AFX_MSG_MAP(CTestDlg)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()


HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

if (nCtlColor == CTLCOLOR_STATIC && pWnd->GetDlgCtrlID() == IDC_EDIT1){
pDC->SetBkColor(RGB(0,0,255));
pDC->SetTextColor(RGB(255,0,0));
}
return hbr;
}

maybe you didn't add ON_WM_CTLCOLOR() in your MESSAGE_MAP
 
Mat, code looks the same, but it looks like using wizard to create OnCtlcolor() handler, it probably add extra code somwhere that i am missing because it still doesn't work.

mat can you tel me how you created the handler.
much appreciated.
 
from the menu view->classWizard, you can get a MFC classwizard dialog box. select the first tab "message Maps".
In the "ObjectIDs" listbox select you test dialog. Then select WM_CTLCOLOR in the "messages" list box. Double click it, the system will create the handler for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top