|
i am using onctlcolor message to set the the background color of edit controls.
the problem is that the background only changes background color if there is text in the control and only for the length of the text.
can the background color be changed regardless of what is in the control for data?
thank you
|
|
|
|
|
Sounds like you're using SetBgColor() . Instead (or in addition) create a solid color brush and return that.
Developers that like shiny objects also dig case mods and scratch-and-sniff stickers. Klaus Probst, The Lounge
|
|
|
|
|
no i am using setbkcolor()
this is the onctlcolor
it works the ok but it only changes the color behind the text not all the background of the control. if there is no text the color will not change at all.
when i want the color to change i call Invalidate()
HBRUSH PREFS::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
int nCtrl = pWnd ->GetDlgCtrlID();
switch(nCtrl){
case IDC_BCOLOR:
pDC->SetBkColor(RGB(m_red,m_green,m_blue));
break;
/////////////////////plus more
}
return hbr;
}
|
|
|
|
|
jafrazee wrote:
no i am using setbkcolor()
Sorry, typo (yes i am too lazy to bother checking each post against MSDN before submitting )
What you need to do is this (assume you've added a member to your class of type HBRUSH and named it m_hBrush, since you'll need to delete this when done with it):
HBRUSH PREFS::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
int nCtrl = pWnd->GetDlgCtrlID();
switch (nCtrl)
{
case IDC_BCOLOR:
pDC->SetBkColor(RGB(m_red,m_green,m_blue));
if ( NULL != m_hBrush )
::DeleteObject(m_hBrush);
m_hBrush = ::CreateSolidBrush(RGB(m_red,m_green,m_blue));
hbr = m_hBrush;
break;
}
return hbr;
}
Alternately, you could just keep a handle of a pre-created brush as a class member and return that.
Explanation:
The background color set using SetBkColor() applies to the text only, as you've noticed. In order to color the rest of the background, you need to return a brush of the appropriate color. This is what the code in bold does above. Windows does not delete the brush when it is done with it, so you must remember to do so after the window is destroyed (or before creating and returning a different brush, as shown).
Developers that like shiny objects also dig case mods and scratch-and-sniff stickers. Klaus Probst, The Lounge
|
|
|
|
|
|
Don't forget to invalidate the entire region of the controls to force a paint.
Jeremy L. Falcon
"The One Who Said, 'The One Who Said...'"
<nobr>
Homepage : Feature Article : Sonork = 100.16311
|
|
|
|
|
I know that this is probably simple for most of you guys but as I have just started to program in C++ I haven't figured out how to do this. I was trying to output an integer and pad the blank spaces as zeros. I have not seen anything in C++ that would let me do that in a simple form using the "cout" function. If I am wrong please enlighten me or give me some ideas.
Thanks
Paul_from_Connecticut
|
|
|
|
|
Use setfill just like this:
cout<<setfill('0')<<setw(5)<<100<<endl;
00100
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I have this DLL (non-MFC or anything like that) that does 2 things:
a) loads up an app, passes in some params. Simple, eh? Just call MyApp.exe, pass in the params, good to go. Next part.
b) finds one of the existing instances of MyApp.exe (don't care really which one), and pass in some params.
I'd normally use FindWindow, but since the title of my app changes, I can't search for "MyAppTitle".
Anybody know of any (relatively) simple methods of finding if MyApp.exe is already running?
(MyApp is a MFC-written, dialog-based, multi-instance-allowing app).
Thanks in advance.
|
|
|
|
|
Create a hidden window with a fixed title, and go search it.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
That's a good idea, except (of course there's an "except", eh?) then how do i get the handle to the instance of MyApp that's running, so i can pass it the params i need to pass it?
|
|
|
|
|
Let the hidden window accept the parameters and (if necessary) forward them to the main window.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hey all,
How can I set IE's homepage using C++ code? (Like ICQ does when you install it)
Thanks!
Oz
|
|
|
|
|
This is stored in the registry key "Start Page", under HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank you - but is this path correct for all versions of IE? (4+, actually) - and is it guranteed to remain correct for future versions?
Or - is there some (COM?) API I can call to do it for me?
|
|
|
|
|
In a dialog box if you hit the Enter key the OnOK function override gets called. Or more precisely, in a modal dialog box if you hit the Enter key the OnOK function override gets called.
Why doesn't this work for a modeless dialog box? And what do I need to do to make it happen?
I've used Spy++ to check what messages are being sent when I hit the Enter button, but there's nothing
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
The problem must lie somewhere else. OnOK should be gotten called both for modal and modeless dialogs.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I've tried it out a couple of times (simplified and from scratch).
If the dialog is shown using DoModal then hitting the Enter button calls OnOK. If the dialog is created as modeless and shown using ShowWindow then OnOK doesn't get call, my PC just beeps
I'm writing a Messenger type app. The user types some text into an edit control. When they hit the enter key the message should be sent (Enter triggering the OnOK function to send the message). That way they don't have to use the mouse to click on the send button.
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
Very same app created from scratch and just changing the modal/modeless aspect? This is weird. If the code is short enough you might want to post it here.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I'd love to, but it's commercially sensitive and I'm contractually bound to keep it to myself.
It's not the whole app. It's just a dialog within it.
Is there any other way to trap when the enter button has been pressed while my edit control has focus?
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
Is there any other way to trap when the enter button has been pressed while my edit control has focus?
Yes, something like:
void CMyDlg::OnOK()
{
AfxMessageBox("OnOK called");
...
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
That's the whole problem.
When my dialog is modeless and the focus is on (in this case) an edit control and the user hits the enter key, nothing happens. OnOK does not get called, the PC just beeps.
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
Are you somehow pretranslating messages / using accelerators in your app? That (maybe) could interact with the ENTER key processing.
Also, does this problem show if the focus is on some other control of the modeless dialog?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
It's a dialog that is part of an ActiveX control. That shouldn't make a difference should it?
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
That shouldn't make a difference should it?
Not sure... Try this (if you please): set the main window as the parent of the modeless dialog (instead of the ActiveX control window).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|