|
John R. Shaw wrote: Do not allocate an object and delete an object in the same function, unless you have to
Why? That's a perfectly normal thing to do, especially when the object in question has some runtime-determined characteristic (e.g. a non-trivial constructor). It's appropriate if you don't need the object for the entire life of the function. Also, if the object is large, you tend to get better working set behavior if you allocate it from the heap rather than the stack.
Software Zen: delete this;
|
|
|
|
|
Gary R. Wheeler wrote: Why?
It is like doing this:
char* buffer = new char[32];
when you should be doing this:
char buffer[32];
The allocation in this case is not a normal thing to do.
Another example:
class MyClass
{
int n1,n2;
public:
......
};
void MyFunc1()
{
MyClass* mc = new MyClass;
......
delete mc;
}
void MyFunc2()
{
MyClass mc;
......
}
Gary R. Wheeler wrote: It's appropriate if you don't need the object for the entire life of the function.
Insted of allocating it, you can use scoping. The pratice of using scoping to limit an objects life time is common and is used in the MFC library its self.
void MyFunc()
{
......
{
MyClass mc;
......
}
......
}
When you allocate unnecessarily, you introduce one more factor that can go wrong.
INTP
Every thing is relative...
|
|
|
|
|
|
jblau wrote: illegal delete expression: managed type 'System::Collections::Hashtable' does not have a destructor defined
OK, that shows that you're creating a managed object. Don't delete it, the CLR garbage collector will take care of that for you. The reason you don't need __gc in the declaration is the compiler infers it from the context - Hashtable is a managed object so __gc is the only possibility.
Yes, this is confusing and it's the main reason why the MC++ syntax was replaced with C++/CLI in VC8.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
"That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas."
-- Buffy
|
|
|
|
|
Thanks for all of the helpful information.
As I understand it now, the way my project is setup, the hashtable is a managed object, so I can't delete it mannualy, (as I get errors when I try).
So my follow up question is this: If I store an object that was declared with a NEW, and store it in the hashtable, do I need to go back through the hashtable and delete those objects, or does the managed code do that as well?
Example:
MyObject *tempObject = new MyObject;
Hashtable *hashObjects = new Hashtable;
hashObjects->Add(key, tempObject);
So if I store several tempObjects in my hashtable, do I need to traverse through the hashtable and DELETE the tempObjects, or does the garbage collector handle this as well as the hashtable itself?
If I do need to delete them, will a call to hashObjects->clear(); delete the objects?
Thanks,
Jody Blau
-- modified at 15:53 Sunday 1st January, 2006
|
|
|
|
|
Try posting this as a new question in the forum so that others can also look at it.
-Prakash
|
|
|
|
|
I create a button at runtime using CButton.Create() function. The button looks fine until it is clicked the first time. From then on the black rectangle around the button becomes slightly wider and does not go away with releasing the button.
It's cosmetic problem only, subtle but annoying nevertheless.
I suspect it's something to do with window-style and extended-window-style but I had no success so far.
Thanks in advance for your suggestions.
spiritofklanawa
|
|
|
|
|
Could it be focus rectangle drawn to the Button, Did you try taking the focus off the button, like pressing the Tab button.
-Prakash
|
|
|
|
|
If you are trying to use a push button, then make sure you put style as BS_PUSHBUTTON.
You can also try, SetState(FALSE);, which will remove any highlighting
|
|
|
|
|
The extra-dark border marks the default button. If more than one button has the BS_DEFPUSHBUTTON style, that will muck up the dialog manager and buttons will be drawn incorrectly.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
Laugh it up, fuzzball.
|
|
|
|
|
that was it ! I just added a line of code in the BN_CLICKED message handler to remove the "BS_DEFPUSHBUTTON" style. The trouble was that multiple buttons showed this dark outline which looked goofy.
Thanks
|
|
|
|
|
I have a MFC MDI App, to which i have added new CDialog. Now when i pop-up the new dialog from MDI and use the controls in it, it will be using the main thread of the MDI App.
I wanted to make this new dialog run on a new thread, so that all controls in it will run on new thread and the MDI will have its main thread always free from dialog. Can anyone tell me how to do this?
Thanks
|
|
|
|
|
You need to create a UI Thread in MFC, check CWinThread for more info. You can then start your dialog in this thread.
-Prakash
|
|
|
|
|
do u have an idea of getting the filename from the handle returned by the FirstFindChangeNotification.
RabiaAslam
|
|
|
|
|
FindFirst/NextChangeNotification() don't work on files, they watch entire directories. You have to figure out on your own what changed.
You can use ReadDirectoryChangesW() to get more details change details.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|
how to load an application developed in MFC in system tray of the windows taskbar.
RabiaAslam
|
|
|
|
|
|
RabiaAslam wrote: how to load an application developed in MFC in system tray of the windows taskbar.
http://www.codeproject.com/shell/CTrayIcon.asp[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
I would like to implement a custom caption bar with CLose, Min and Help buttons. The framework does not allow this. Any suggestions
Dave Regan
|
|
|
|
|
in WM_NCPAINT to draw it your self.
if you want different shape of caption bar, you need to draw more.
includeh10
|
|
|
|
|
Thanks for the reply.
I have hooked my CMainFrame wnd in line with a project by Paul DiLascia. In the new window process I am responding to several messages. I found that in order to display the correct tooltips I had to trap WM_NCHITTEST and where it was over my new Minimize button (original Maximize button position) return HTMINBUTTON instead. However when my new Minimize button is pressed, my new Help button is overwritten with a pressed Minimize button.
It all appears to be happening in the Default window proc.
Dave Regan
|
|
|
|
|
I'm constantly moving my laptop around to different networks, and at each place I need to change the static IP settings. I'm writing a little utility to store my various configurations and set the appropriate one when needed.
Right now I'm changing the IP settings from a batch file with the "netsh interface ip set..." command. Obviously, this is an ugly way to do it, but it works. This also makes it more difficult to add/edit my various listings.
I'm looking for a more elegant solution... and suggestions?
Thanks for any help -mutty
|
|
|
|
|
netswitcher
Google it to find downloads
My blogs:
http://blog.joycode.com/jiangsheng
http://blog.csdn.net/jiangsheng
http://bloglines.com/public/jiangsheng
Command what is yours
Conquer what is not
---Kane
|
|
|
|
|
netswitcher does much more than I need... and it also defeats the purpose of doing it myself.
|
|
|
|
|
Using VC6 on Win2K:
Given the following code:
DWORD dwFlags = OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ENABLESIZING;
CString sFile = _T("");
CFileDialog dlg(TRUE, "rc", NULL, dwFlags, "Resource Files (*.rc)|*.rc||");
if (IDOK == dlg.DoModal())
{
sFile = dlg.GetFolderPath();
}
The dialog displays, and allows me to select a file, but it asserts when I click OK.
The code is very simple and straightforward, but I get a debug assert in dlg.GetFolderPath() claiming the hwnd for the dialog is NULL. Can anyone tell me what I missed or did wrong?
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|