|
Thanks for your comments.
I know that the placement ot the vtbl is implementation dependant (thanks to painful experiences with Mac). I am still a bit unclear about non-virtual member functions, however. I assume that they are not replicated in every object instance? Is there a separate pointer like the vtbl for them?
Could you help me to become a better C++ programmer?
Cheers
/moliate
|
|
|
|
|
moliate wrote:
I am still a bit unclear about non-virtual member functions, however. I assume that they are not replicated in every object instance? Is there a separate pointer like the vtbl for them?
IIRC, neither virtual or "normal" member functions are replicated for every instance of a object. The old idea of "one copy of code, multiple copies of data" comes to mind.
Yes, if the object contains virtual methods, then each instance of the object gets a copy of it's vtable . This is needed for polymorphism. But it is just the vtable that is in the memory layout of the object, not the code for the functions themselves. That code still exists in one place, and the vtable is used to get to them.
moliate wrote:
Could you help me to become a better C++ programmer?
That is what this site is (supposed to be) for! :P
(Note, I used "object" above instead of "class" because both classes and structs can contain member functions...)
Peace!
-=- James.
|
|
|
|
|
Since almost everyone interested in CodeProject already has a version of Visual C++, why does CodeProject only offer the non-upgrade version of Visual Studio.net for $799?
The upgrade price for Visual Studio.net, professional version, is $195.99 after rebate, from Programmers Paradise.
|
|
|
|
|
No responses to this post leads me to believe that the Code Project $799 offer for the non-upgrade version of Visual Studio.net is not what we need. Most of us want to UPGRADE to Visual Studio.net. The $195.99 offer from Programers Paradise may be the best deal,
|
|
|
|
|
I'm using VC++ 6.0 and when I add a Tab Control onto my Dialog box in the resource editor, the form will no longer load. I was wondering if anyone had any idea as to how I can remedy this so that my form will load with the Tab Control on it?
thx
Quinn
|
|
|
|
|
Make sure InitCommonControlsEx() has been called to initialize the tab control.
Developers that like shiny objects also dig case mods and scratch-and-sniff stickers. Klaus Probst, The Lounge
|
|
|
|
|
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
|
|
|
|