|
Try
return (HBRUSH)GetStockObject(NULL_BRUSH);
instead of
return hbr;
Steve S
|
|
|
|
|
if you donot like 'stock object' try this . It should work.
LOGBRUSH lb;
lb.lbStyle = BS_HOLLOW;
return CreateBrushIndirect(&lb);
|
|
|
|
|
if you dont like using 'stock objects', try using this
It should work
LOGBRUSH lb;
lb.lbStyle = BS_HOLLOW;
CreateBrushIndirect(&lb);
|
|
|
|
|
Problem with non-stock object approach is that you may inadvertently leak GDI objects, unless you track them in the parent CDialog.
Another approach would be to derive from CStatic, use message reflection so that the object handles it's own WM_CTLCOLORSTATIC, and returns a singleton hollow brush.
The stock object null/hollow brush could be used there too, and you'd use control variables to associated dialog members to the appropriate control(s).
Steve S
|
|
|
|
|
Beter if you explain ...
Code that work:
hbr = NULL;
{
if( CTLCOLOR_STATIC == nCtlColor )
{
hbr = (HBRUSH)GetStockObject( HOLLOW_BRUSH );
pDC->SetBkMode( TRANSPARENT );
}
else
{
hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
return hbr;
}
thanks you for response.
|
|
|
|
|
Hi All,
I would like to know whether there is any API provided by the
Windows OS for packet filtering dynamically. Usually we can configure this
from the Control Panel Settings, but it needs restart. Is there any method
to do it without any restart needed.
Thanks.
Learning is a never ending process of Life.
|
|
|
|
|
what is the architecture of MAPI?
I use SIMPLE MAPI in my c++ client program..
is there any necessity to install! MAPI for this purpose in my computer??how do i do it iff i have to install MAPI??
ranjani
|
|
|
|
|
Hi All,
I have a silly question about radio buttons that seems pretty simple but yet i can't get to work.
I have a dialog with 2 radio buttons to allow the user to select one of two choices. I initially set one as default using CheckRadioButton(IDC_B1, IDC_B2, IDC_B1) . I want my program to remember which one is selected by the user, so that if they open the dialog again through a pull down menu it will select the same one as the user selected before.
can someone tell me how to do this exactly, i don't know what i am doing wrong.
Thanks for your help.
|
|
|
|
|
Short answer: The button can't do it for you. You need to retrieve the current value and save it. Then use that value when you re-create it.
If you want to have it remember between sessions, you would save that in the regisitry (HKEY_CURRENT_USER PLEASE!).
tim
Founder, TMurgent Technologies
www.tmurgent.com
tmangan@tmurgent.com
|
|
|
|
|
Thank you for your help.
I am very new to programming...I tried to do that, but with no success. (Or at least I thought i was doing that)
Can someone tell me how to save these values and then use them to re-create the buttons. I tried to make a control variable with the classwizard, but MFC doesn't let me make a control value for radio buttons.
PLEASE help...i need to get this done soon.
all help is appreciated.
|
|
|
|
|
Unless the radio button has the WS_GROUP style, ClassWizard will not allow you create a control variable for it.
Now the "tricky" part. You can have one control variable represent the entire group of radio buttons, or you can have one control variable for each radio button in the group. There are pros and cons to both.
To use the registry, you can use the registry API (RegOpenKeyEx() , RegQueryValueEx() , RegSetValueEx() ), or the CRegKey class.
|
|
|
|
|
Thanks for the help David.
What would you recommend in my situation. To have one for the group or one for each. I have such little experience with programming that I do not know which route to take.
I am still confused to how i can use it to have it check the radio buttons when the user brings up the menu item again. I keep gettng an assertion failure.
I do not need the settings to be saved for the next session. I just need it for when the app is run once.
thanks in advance.
|
|
|
|
|
Jay Hova wrote:
What would you recommend in my situation. To have one for the group or one for each. I have such little experience with programming that I do not know which route to take.
I am still confused to how i can use it to have it check the radio buttons when the user brings up the menu item again. I keep gettng an assertion failure.
Let's operate on the premise that one variable represents the entire group (two radio buttons in your case). If this variable is 0, then the first radio button in the group will be checked. If this variable is 1, then the second radio button in the group will be checked. See the pattern? If this value is set in the dialog's constructor, nothing else needs to be done. If this value is set in the dialog's OnInitDialog() method, a call to UpdateData(FALSE) will be needed.
Read here for some more details:
http://flounder.com/getdlgitem.htm#Radio%20button%20variables
Jay Hova wrote:
I do not need the settings to be saved for the next session. I just need it for when the app is run once.
Then the owner of the dialog instance should store the value. Is this an SDI or an MDI application?
|
|
|
|
|
David,
Thanks for your help....
I am going to read that site you provided now.
Going by what you wrote, can i check the radio button using SetCheck? I tried just setting the variable equal to one and it doesn't check either one....
Sorry for being so slow with this.
Its a MDI app btw.
many thanks...
|
|
|
|
|
Jay Hova wrote:
Going by what you wrote, can i check the radio button using SetCheck?
Yes, this assumes that you have one control variable per radio button. In the dialog's OnInitDialog() method, you'd have something like:
The m_first_radio_button and m_second_radio_button variables are of type CButton, not integer
if (0 == some_variable)
m_first_radio_button.SetCheck(BST_CHECKED);
else if (1 == some_variable)
m_second_radio_button.SetCheck(BST_CHECKED);
else
ASSERT(FALSE);
Jay Hova wrote:
I tried just setting the variable equal to one and it doesn't check either one....
This sounds like an entry is missing from the dialog's DoDataExchange() method, or you set the value in the wrong location.
|
|
|
|
|
David,
That is exactly as i was doing it in the OnInitDialog....
Perhaps I am doing something incorrect in the OnOk. How would i get the which one is selected by the user?
thanks again for all your help and patience with a mechanical engineer with no wit to program.
|
|
|
|
|
Jay Hova wrote:
Perhaps I am doing something incorrect in the OnOk. How would i get the which one is selected by the user?
if (xxx.GetCheck() == BST_CHECKED)
...
|
|
|
|
|
This is what i have in OnOk():
if(m_Screen_Radio.GetCheck() == BST_CHECKED)
m_SendTo = 0;
else
m_SendTo = 1;
where m_SendTo is a member variable of type int and m_Screen_Radio is CButton
|
|
|
|
|
What you've shown should work. Does it?
Now in the code that instantiates the dialog object, you'll need something like:
CMyDialog dlg;
dlg.m_SendTo = m_SendTo;
if (dlg.DoModal() == IDOK)
m_SendTo = dlg.m_SendTo;
Make sense?
|
|
|
|
|
I get an assertion failure with that code that I had....
You lost me however with what you wrote. I don't understand it. Where should I put that code? Please clarify if you can.
Many many thanks.
|
|
|
|
|
Jay Hova wrote:
I get an assertion failure with that code that I had....
See my previous comment about DoDataExchange() . Even though you have a CButton control variable, there must be an entry in DoDataExchange() for it. To verify, note the file/line of the fired assertion. If you then look at that code, it will most likely look something like:
ASSERT(::IsWindow(m_hWnd));
which means there is no window associated with the variable.
Jay Hova wrote:
You lost me however with what you wrote. I don't understand it. Where should I put that code? Please clarify if you can.
You previously mentioned that the dialog was being displayed as the result of a menu selection. I assume you already have a call to DoModal() in there. Correct?
|
|
|
|
|
I tried to implement the code you wrote, but i get an error saying that m_SendTo is an undeclared identifier.
The assertion failure is in afxwin2.inl on line 588....
Thanks again for your help.
Your patience is amazing!
|
|
|
|
|
Jay Hova wrote:
I tried to implement the code you wrote, but i get an error saying that m_SendTo is an undeclared identifier.
Right. You'll need to add this member variable to the appropriate class.
Jay Hova wrote:
The assertion failure is in afxwin2.inl on line 588....
As I predicted:
_AFXWIN_INLINE int CButton::GetCheck() const
{ ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, BM_GETCHECK, 0, 0); }
|
|
|
|
|
David,
Sorry that you have to spoon feed me through this. I feel like such a moron because I can not grasp this concept. I really appreciate your help.
What do i have to put in DoDataExchange? Also by adding the member variable to the other cpp file, won't it over write the existing data in m_SendTo?
Thanks.
|
|
|
|
|
Jay Hova wrote:
Sorry that you have to spoon feed me through this. I feel like such a moron because I can not grasp this concept. I really appreciate your help.
Not a problem. The first few applications are always the hardest.
Jay Hova wrote:
What do i have to put in DoDataExchange? Also by adding the member variable to the other cpp file, won't it over write the existing data in m_SendTo?
I've never had to manaully add anything to DoDataExchange() . ClassWizard does it all for me (hint: use CW to create the member and control variables). By looking at that function, however, you can get a feel for what MFC might be doing.
Jay Hova wrote:
Also by adding the member variable to the other cpp file, won't it over write the existing data in m_SendTo?
I'm not quite sure I understand what you are asking here. Care to elaborate?
|
|
|
|