|
Hello,
I am working an a SDI MFC application and I don't know what is realy what is the best to do when I will close the application
AfxGetApp()->m_pMainWnd->PostMessage(WM_CLOSE,0,0);
or
exit(0);
Thank you !
AutreChien
|
|
|
|
|
hi,
Use ::PostQuitMessage(0) for SDI or MDI.
::OnOK() for a Dialog.
Good Luck.
Uday kiran
|
|
|
|
|
|
I am learning Win32API programming. I do not use MFC. Now I have created a class which creates a Window of the Static class. Lets call the class CStatic . This class creates a Static Window and has all the functionalities that a normal Static control has. My problem begins when I use the class.
As long as I use the class like CStatic m_Static there is no problem but when I create an instance of the class using CStatic* m_pStatic = new CStatic() , I start running into confusions. Isn't it necessary to use delete m_pStatic to remove the object from memory or will m_pStatic->DestroyWindow() do the same thing?
When I try
m_pStatic->DestroyWindow()
delete m_pStatic
I get an error? Does the object get removed if I simply use the DestroyWindow() function? The DestroyWindow() function in turn just calls the WIN32API DestroyWindow() .
From what I reason, CStatic* m_pStatic = new CStatic() creates an object of CStatic in memory and m_pStatic->Create() in turn creates another object for the Window. So I have two objects in memory, one of my class and one belonging to the Window. Am I right? or is my whole concept wrong? If I am correct then a call to DestroyWindow should only delete the Window object and not the object of my class. Isn't it? Then now come when I try to delete m_pStatic after a call to Destroywindow , it throws an exception.
Can anyone explain.
---
Hakuna-Matada
It means no worries for the rest of your days...
It's our problem free, Philosophy
<marquee behavior="alternate" scrollamount="5" scrolldelay="50">
|
|
|
|
|
Hakuna-Matada wrote: From what I reason, CStatic* m_pStatic = new CStatic() creates an object of CStatic in memory and m_pStatic->Create() in turn creates another object for the Window. So I have two objects in memory, one of my class and one belonging to the Window. Am I right?
Yes more or less. In fact, the call to the WINAPI Create function doesn't really 'create' an object in memory like you would do with new. But still, you have to call DestroyWindow afterwards. And then of course delete the object you allocated with new.
Hakuna-Matada wrote: Then now come when I try to delete m_pStatic after a call to Destroywindow, it throws an exception.
You probably did something wrong in your code. Show the destructot of your class. And explain also exactly what you did. It is impossible to say without having more information.
|
|
|
|
|
Thanks for your input. It was indeed a flaw in my code. But I have another situation now.
CStatic* m_pStatic = new CStatic();<br />
m_pStatic->Create();
Lets say I register for the CStatic Window's Close Event. Now when the Window is closed by clicking on the close button, when do I delete m_pStatic ?
---
Hakuna-Matada
It means no worries for the rest of your days...
It's our problem free, Philosophy
<marquee behavior="alternate" scrollamount="5" scrolldelay="50">
|
|
|
|
|
As I can see by your code, m_pStatic is not a member of any class and its scope is probably limited to the function where it has been declared. Am I right or is your code different ?
In that case, you will lose track of your pointer and won't be able to delete it anymore (resulting in a memory leak).
I have some suggestions:
1) first, instead of forcing the user to call DestroyWindow from your control, why don't you simply put it in the destructor of your class ? So like that it will be called automatically when your class is destroyed.
2) try to avoid using dynamic allocation when it is not necessary (like in this case, you don't really need to allocate the control dynamically, I am right ?)
3) make all your controls member of the class in which they are used. This way, they will be destroyed when the parent class is destroyed and you don't need to have some headache because they are going out of scope whe nyou don't want (remember that when it goes out of scope, the object is destroyed and so its destructor is also called).
Hope this helps
|
|
|
|
|
Hi Guys,
Can anyone plz help me by giving some source code for sample CMap applications. It will be very useful for me.
Regards
Velayudhan
Thanks in Advance
Velayudhan
|
|
|
|
|
Do you mean samples using CMap ? I recommend using std::map instead. I know there are plenty of samples for that on the web and IMO, the public interface makes a lot more sense than CMap does.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
hi,
CMap is used for (Key Name --> Key Values). // It is MFC Class.
Please Study the MSDN which gives a Neat explation and how to use.
// In order to Use STL class.
use std::map(...) // which is complicated. First Approach is MFC.
Go to Google and search CMap you will get number of Examples.
Uday kiran
|
|
|
|
|
velayudhan_raj wrote: Can anyone plz help me by giving some source code for sample CMap applications.
void main( void )
{
CMap <int, int, CString, CString> mapZIP;
mapZIP.SetAt(73001, "Albert");
mapZIP.SetAt(73002, "Alex");
mapZIP.SetAt(73003, "Edmond");
mapZIP.SetAt(73004, "Amber");
mapZIP.SetAt(73005, "Anadarko");
mapZIP.SetAt(73006, "Apache");
mapZIP.SetAt(73007, "Arcadia");
CString strCity;
mapZIP.Lookup(73006, strCity);
}
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi,
Is there anyway I can make the hidden statusbar visible in Windows Explorer ?
I am writing a shell extension and I have the IShellBrowser interface pointer. My extension shows everything in the status bar and if the user turns-off the visibility, I will be in trouble.
So I would like to show the statusbar even if its hidden before when the user navigates to my extension.
I will appreciate any help or pointers to solve this.
Thanks
Jugs
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
XMinds
|
|
|
|
|
Jagadeesh VN wrote: if the user turns-off the visibility, I will be in trouble.
what kind of trouble it is?
Does IShellBrowser::GetControlWindow in combination to IShellBrowser::SendControlMsg help you.
|
|
|
|
|
what is the diff between UDP&TCP proocals?how to create a UDP client network application?
which api i have to use?in VC++ plz give me the sugetions.
|
|
|
|
|
tcp calls to a particuliar computer, when udp doesn't.
take this for example :
TCP : you call someone by the phone... you know its phone number, and you know who gonna answer
UDP : you talk to the crowd. no matter how many of them is listenning, you're just sending your "stream" of talks...
seeing the picture ?
|
|
|
|
|
toxcct wrote: TCP : you call someone by the phone... you know its phone number, and you know who gonna answer
UDP : you talk to the crowd. no matter how many of them is listenning, you're just sending your "stream" of talks...
seeing the picture ?
plz tell me how to create a UDP application.
-- modified at 4:39 Thursday 24th August, 2006
|
|
|
|
|
ramanand_bulusu wrote: plz tell me how to create a UDP application
this is not the original question, and no, i can't. google is your friend (and codeproject also !). did you bother search them first ?
|
|
|
|
|
ramanand_bulusu wrote: Re: networking
This is not the networking forum.
ramanand_bulusu wrote: diff between UDP&TCP protocols
See here
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
i am using a combobox and the current selection is displayed in its edit control. After clicking the dropdown button of the combo box, if the user does not select any of the items in the listbox of the combo box, then how to display the previously selected item in the edit control of the combo box.
Thanks...
vijay
|
|
|
|
|
You will have to store the index of the previously selected item in some variable. If the user does not select anything you can show the same item that was being displayed earlier using this index.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Hi,
I think you need a member variable where you save yor last selection, initialising with CB_ERR (nothing selected) Wenn you clicking the dropdown button you ask if (getCurSel() == CB_ERR) if its TRUE you call SetCurSel(yourVar)
yummi
|
|
|
|
|
thanks... i am new to this and so finding it a bit hard.
vijay
|
|
|
|
|
hi,
If you doesnt select the ComboBox then the Index value is always -1
so
if(cmb.getCurSel()== -1) //Nothing but CB_ERR.
{
cmb.setCurSel(previous index value);
}
Think clever.
Uday kiran
|
|
|
|
|
You need to a variable for same previous state,do you have this variable?
|
|
|
|