|
Hi,
I'm about to spontaneously combust if I can't manage to set the color of one single little button in a dialog. It seems that with OnCtlColor() I can set the color of EVERYTHING EXCEPT my button's foreground. Please help me before I blow!
I know I am missing something probably very simple. Do I need to use OnDrawItem()?
Thank you for any suggestions. I am relatively new (1 year) to MFC so be kind and if possible detailed in your suggestions. Thank you so much.
Here's one of several bits of code I have tried :-
//CBrush is set within OnInitDialog()
m_brush.CreateSolidBrush(RGB(0,0,255)); // Blue brush
....
HBRUSH CTry_button_colorsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
//this works ok - my editbox ends up a nice blue color
if (nCtlColor == CTLCOLOR_EDIT || nCtlColor == CTLCOLOR_MSGBOX )
{
pDC->SelectObject(m_brush);
hbr = this->m_brush;
}
//THIS DOES NOT WORK
if (nCtlColor == CTLCOLOR_BTN)
{
hbr = this->m_brush;
pDC->SetBkColor(RGB(0,0,255));
}
//THIS DOESN'T WORK EITHER
if( pWnd->GetDlgCtrlID() == IDC_MYBUTTON)
{
pDC->SetBkColor(RGB(0,0,255));
pDC->SelectStockObject(WHITE_BRUSH);
}
return hbr;
}
Michael
|
|
|
|
|
You can't change the button colour using OnCtlColor() . You'll have to create an owner-draw button to do this.
michael thomas wrote:
I'm about to spontaneously combust
Don't spend too much time in the sun then...
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
|
If you want to change the color of a dialog button, you have to use owner-draw button. (you can use bitmap buttons) Changing the color through OnCtlColor() will not work for buttons. The following Knowledge Base articles may be of help to you:
ID: Q32685 TITLE: Using the WM_CTLCOLOR Message
ID: Q64328 SAMPLE: Owner-Draw: 3-D Push Button Made from Bitmaps with Text
HPS HwndSpy - GUI developer's aid to visually
locate and inspect windows. For the month of August
only, use coupon code CP-81239 for 30% off.
|
|
|
|
|
Thanks for the help.
Michael
|
|
|
|
|
I have 2 tables in mydatabase "Account" and "Employee"
I want to edit my record but there is a Error messagebox always show
-----------------------------
"Recordset is read-only"
-----------------------------
How can I fix it?
thanks
<br />
<br />
<br />
<br />
IMPLEMENT_DYNAMIC(CAccountSet, CRecordset)<br />
CAccountSet::CAccountSet(CDatabase* pdb)<br />
: CRecordset(pdb)<br />
{<br />
m_ID = _T("");<br />
m_Pass = _T("");<br />
m_Employee_ID = _T("");<br />
m_Permission = 0;<br />
m_nFields = 4;<br />
m_nDefaultType = dynaset;
}<br />
<br />
CString CAccountSet::GetDefaultConnect()<br />
{<br />
return _T("ODBC;DRIVER=Microsoft Access Driver (*.mdb);DBQ=C:\\MyDB.mdb");<br />
}<br />
<br />
CString CAccountSet::GetDefaultSQL()<br />
{<br />
return _T([Account],[Employee]);<br />
}<br />
<br />
void CAccountSet::DoFieldExchange(CFieldExchange* pFX)<br />
{<br />
pFX->SetFieldType(CFieldExchange::outputColumn);<br />
RFX_Text(pFX, _T("[ID]"), m_ID);<br />
RFX_Text(pFX, _T("[Pass]"), m_Pass); <br />
RFX_Long(pFX, _T("[Permission]"), m_Permission); <br />
RFX_Text(pFX, _T("[Employee_ID]"), m_Employee_ID);<br />
}<br />
<br />
<br />
class CChangePassword : public CDialog<br />
{<br />
public:<br />
CChangePassword(CWnd* pParent = NULL);
<br />
CAccountSet m_Set;<br />
.....<br />
}<br />
<br />
<br />
<br />
<br />
void CChangePassword::OnOK() <br />
{<br />
.......<br />
m_Set.m_strFilter = "Account.ID = Employee.Employee_ID";<br />
m_Set.Open(CRecordset::dynaset,<br />
_T( "SELECT ALL Account.ID,Account.Pass,Employee.Permission FROM Account INNER JOIN Employee ON Account.ID=Employee.Empoyee_ID" ),<br />
CRecordset::executeDirect);<br />
<br />
<br />
m_Set.Edit();<br />
m_Set.m_Pass = strNewPass; <br />
<br />
m_Set.Update( ); <br />
m_Set.Requery ();<br />
m_Set.Close();<br />
.....<br />
}
|
|
|
|
|
Hello,
I have a CDialogBar with many run-time-generated progress bar windows on it. I would like to handle the event when the user clicks on one of these progress bars but after trying many message map entries, I cannot seem to find the right way to funnel these messages to any function of mine.
I've tried to simply intercept the ON_WM_LBUTTONDOWN message, but it is only called if the user clicks in the dialog bar EXCEPT for in my progress bar windows.
I can intercept the event in the progress bar class, but I want to handle it in the parent (CDialogBar) class---is there any way to funnel it back to the parent class?
Any ideas/help?
thanks!
JennyP
|
|
|
|
|
If all else fails, intercept it in the progress bar class, and use GetParent()->SendMessage(WM_LBUTTONDOWN, ...) .
HPS HwndSpy - GUI developer's aid to visually
locate and inspect windows. For the month of August
only, use coupon code CP-81239 for 30% off.
|
|
|
|
|
when I use the writestring(); function it works everything but i get one compiler error cannot convert parameter 1 from 'class CTime' to 'const char *' HELP!
[It is possible to represent everything in this universe by using 0 and 1]
I'm going to live forever or die trying.
|
|
|
|
|
Hello,
CTime has many member functions---one is called ".format()" and returns a CString, and I'm sure this CString can easily be converted to a char * type (perhaps by a CString function or a (char *) cast).
cheers,
JennyP
|
|
|
|
|
There are several ways of doing this...
CTime time = CTime::GetCurrentTime();<br />
CStdioFile file;<br />
file.WriteString(time.Format("The time is %x\n"));
or
CString str;<br />
str.Format("The time is %s\n", time.Format("%x"));<br />
file.WriteString(str);
etc...
|
|
|
|
|
Hi,
I'm trying to use a spin control so that when it changes a number in its buddy window, other items in the dialog box are changed (ie. some options are greyed out depending on the value). I am *not* using MFC, just the straight Window API.
Unfortunately, I can't get it to work properly. I read on MSDN that you should use NM_RELEASEDCAPTURE with WM_NOTIFY, and that NM_RELEASEDCAPTURE uses a NMHDR structure - unfortunately, I'm a novice, and this means nothing to me - and all searches for information on NM_RELEASEDCAPTURE elsewhere have turned up blank.
Could somebody please show me a small piece of sample code, showing how to use NM_RElEASEDCAPTURE with WM_NOTIFY?
I tried doing it without NM_RELEASEDCAPTURE like this:
case WM_NOTIFY:
switch(wParam)
{
case IDC_SPIN1:
EnableWindow(ADlgItem,o);
break;
}
break;
This just about worked, but only very, very strangely... If someone could show me the right way to do this I would be really grateful.
Many thanks,
KB
|
|
|
|
|
I had the same need, in a palette editing dialog I wrote. Here are some relevant code snippets:
ON_NOTIFY(UDN_DELTAPOS, IDC_SPINRED, OnDeltaposSpinRed)
...
void CPaletteEdit::OnDeltaposSpinRed(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
*pResult = 0;
int nNewPos = pNMUpDown->iPos + pNMUpDown->iDelta;
if (nNewPos < 0)
{
nNewPos = 0;
*pResult = 1;
}
if (nNewPos > 255)
{
nNewPos = 255;
*pResult = 1;
}
COLORREF cRef = m_rgbMain;
cRef = RGB (nNewPos, GetGValue (cRef), GetBValue (cRef));
m_rgbMain = (cRef);
m_rgbBaby [m_nCurrentColour] = cRef;
m_pPaletteSettings->rgbPalette [m_nCurrentColour] = cRef;
PaletteRefresh ();
}
As this is cut and pasted from my app, the last bit is app specific. m_rgbMain is a colour display
static control that has operator= overloaded.
I hope this helps,
Iain.
|
|
|
|
|
Hi, thanks for your help, I really appreciate it. I think I forgot to mention that I'm a relative novice, and as I'm just using the straight SDK with no MFC, I'm having problems converting your code for use with WM_NOTIFY. Do I create a function similar to your OnDeltaPosSpinRed() function and then somehow call it from WM_NOTIFY?
Sorry if this is a very basic question.
Many thanks,
KB
|
|
|
|
|
My apologies, I just assumed MFC...
In straight Win32, you will need to handle WM_NOTIFY in your MyDlgProc. Then cast lParam to a NMHDR * to get the sub-code.
This is an off the cuff bit of code. Depending on your application, you may want to split this code into sub functions...
INT_PTR CALLBACK MyDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
...
case WM_NOTIFY:
{
NMHDR *nmHdr = (NMHDR *)lParam;
if (!nmHdr) break;
switch (nmHdr->code)
{
...
case UDN_DELTAPOS:
{
NMUPDOWN *ud = (NMUPDOWN *)nmHdr;
e.g. SendDlgItemMessage (hDlg, IDC_OTHERTHING, WM_SOMETHING, ..., ud->iPos);
}
break;
...
}
}
break;
...
}
return 0;
}
This has been a bit of nostalgia for me! I only use SDK only for background apps that are really dinky and lightweight.
Iain.
|
|
|
|
|
Thank you for the help, I really appreciate it - this is really useful. Sorry I didn't reply to thank you earlier, but for some reason I couldn't access the Code Project for the past few days (I'm on a different internet connection now, so maybe it's NTLWorld playing up...).
Anyway, thanks again!
Cheers,
KB
|
|
|
|
|
You're welcome. I couldn't get to CP for a couple of days either.
Glad I could help,
Iain.
|
|
|
|
|
How can I set a toolbar button to display an icon?
Eilzabeth
|
|
|
|
|
Import the Icon u want to set to resource editor of the Workspace.... copy it and paste it on the toolbar button(on which u want to display).....
but framework suports only sizes 16*16 or 32*32
hope this works for u.....
regards
Adi
|
|
|
|
|
I got it. Thank you.
Eilzabeth
|
|
|
|
|
Does anyone know if the Job Object API supports setting up jobs on a remote machine, or if it only works locally? If you have a link that would be great also...TIA
|
|
|
|
|
There appear to be a weird problem here.
I open VS. Build, Run the program. Works fine. Now Build, Run again, and va_arg does not return NULL after the last arg. Now I close VS, open it again. Same process from here.
Anyone had these problems? Or can replicate them? Or fix them?
leppie::AllocCPArticle(Generic DFA State Machine for .NET);
|
|
|
|
|
There's no end-of-list mark with variable argument lists. You've been lucky so far that, sometimes, the next item on the stack has been zero.
You need to either look for a terminator value, or know how many items are in your list (by, for example, passing that as the first argument).
|
|
|
|
|
|
hmm, maybe, but then you'll loose some of the type of comfort that (...) provides. Imagine that before every printf() you have to prepare a linked list of arguments :-/.
But on the other side, the ... parameters doesn't have the type control, so it's some sort of evil
|
|
|
|