Click here to Skip to main content
15,890,882 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to implement Ctrl + tab to navigate between tabs in a CTabCtrl Pin
Amrit Agr28-Apr-16 23:21
Amrit Agr28-Apr-16 23:21 
QuestionDoes DestroyWindow Parent CDialog destroy all ChildControls Pin
ForNow27-Apr-16 13:11
ForNow27-Apr-16 13:11 
AnswerRe: Does DestroyWindow Parent CDialog destroy all ChildControls Pin
Richard MacCutchan27-Apr-16 21:45
mveRichard MacCutchan27-Apr-16 21:45 
GeneralRe: Does DestroyWindow Parent CDialog destroy all ChildControls Pin
ForNow28-Apr-16 2:13
ForNow28-Apr-16 2:13 
AnswerRe: Does DestroyWindow Parent CDialog destroy all ChildControls Pin
leon de boer28-Apr-16 1:34
leon de boer28-Apr-16 1:34 
GeneralRe: Does DestroyWindow Parent CDialog destroy all ChildControls Pin
ForNow28-Apr-16 2:16
ForNow28-Apr-16 2:16 
AnswerRe: Does DestroyWindow Parent CDialog destroy all ChildControls Pin
Parthiban.Appuswamy28-Apr-16 3:39
Parthiban.Appuswamy28-Apr-16 3:39 
GeneralRe: Does DestroyWindow Parent CDialog destroy all ChildControls Pin
leon de boer28-Apr-16 4:51
leon de boer28-Apr-16 4:51 
Okay the rules with memory or object allocation and deleting are very simple.

Situation 1:
If the memory/object is used by multiple children windows and/or the parent then you create it in OnCreate (WM_CREATE) on the parent and destroy it on OnDestroy (WM_DESTROY) of the parent. The reason is because multiple children and/or parent are using it and you need it created before any children and disposed of after the children are deleted.

Situation 2:
If the memory/Object is used by ONLY the SINGLE child window EXCLUSIVELY (that is the data belongs really to the child) then you create it on OnCreate (WM_CREATE) of the child and you delete it with the OnDestroy (WM_DESTROY) of the child.

Sometimes people get lazy and just use situation 1 to cover situation 2 but there are traps in that. It is very easy to forget you need something done before the child is created which is in an unrelated block of code in the parent window create function. So generally I would advise against being lazy and using situation 1 to try and cover all situations. Using Situation 2 when it is valid to do so makes your code self contained portable without thinking about it.

Situation 2 is that most often not understood by people. I will give you a simple example I might use on your edit entry, and this is a subclass of the edit I use a lot in programs. OnCreate (WM_CREATE) of the edit box I create a string object. Whenever the user hits enter, I validate the entry via a message call and if its valid put the current value into the string object and then update the edit window to the new value. Why do this ... well because in the edit box handler hitting the "esc" key goes and gets the value from the string object and puts it back it the edit box. It is a return to last valid value function or a simple single step back. If you think about it you could extend the concept to a list and be able to scroll back thru the list of entered values something you might recognize for the entry address input of your web browser. Now the point here is the string object is the edit boxes responsibility to delete so it will do that on it's OnDestroy (WM_DESTROY). Now everything is self contained I can create as many of these edit boxes as I want into a parent and they all look after there own object string.

So basically you need to work out what data is being used where and in this regard it is very similar to thread or task code.
In vino veritas

QuestionHow To Look At GCC C Sources Pin
Frederick J. Harris24-Apr-16 2:22
Frederick J. Harris24-Apr-16 2:22 
AnswerRe: How To Look At GCC C Sources Pin
Richard MacCutchan24-Apr-16 3:02
mveRichard MacCutchan24-Apr-16 3:02 
GeneralRe: How To Look At GCC C Sources Pin
Frederick J. Harris24-Apr-16 4:57
Frederick J. Harris24-Apr-16 4:57 
GeneralRe: How To Look At GCC C Sources Pin
Richard MacCutchan24-Apr-16 5:44
mveRichard MacCutchan24-Apr-16 5:44 
AnswerRe: How To Look At GCC C Sources Pin
Jochen Arndt24-Apr-16 21:32
professionalJochen Arndt24-Apr-16 21:32 
GeneralRe: How To Look At GCC C Sources Pin
Frederick J. Harris24-Apr-16 23:57
Frederick J. Harris24-Apr-16 23:57 
QuestionExchanging data using CSocket Pin
manoharbalu22-Apr-16 22:30
manoharbalu22-Apr-16 22:30 
AnswerRe: Exchanging data using CSocket Pin
Jochen Arndt22-Apr-16 23:30
professionalJochen Arndt22-Apr-16 23:30 
GeneralRe: Exchanging data using CSocket Pin
manoharbalu24-Apr-16 20:23
manoharbalu24-Apr-16 20:23 
GeneralRe: Exchanging data using CSocket Pin
Jochen Arndt24-Apr-16 20:53
professionalJochen Arndt24-Apr-16 20:53 
QuestionAdding UI to an existing console project using windows form Pin
Member 935023722-Apr-16 6:05
Member 935023722-Apr-16 6:05 
AnswerRe: Adding UI to an existing console project using windows form Pin
Richard MacCutchan22-Apr-16 6:47
mveRichard MacCutchan22-Apr-16 6:47 
GeneralRe: Adding UI to an existing console project using windows form Pin
Member 935023725-Apr-16 21:51
Member 935023725-Apr-16 21:51 
AnswerRe: Adding UI to an existing console project using windows form Pin
leon de boer24-Apr-16 15:49
leon de boer24-Apr-16 15:49 
GeneralRe: Adding UI to an existing console project using windows form Pin
Member 935023725-Apr-16 21:55
Member 935023725-Apr-16 21:55 
QuestionCode Blocks giving fatal error of not finding header file when there are seperate class files Pin
Mur250122-Apr-16 3:07
Mur250122-Apr-16 3:07 
SuggestionRe: Code Blocks giving fatal error of not finding header file when there are seperate class files Pin
Richard MacCutchan22-Apr-16 4:15
mveRichard MacCutchan22-Apr-16 4:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.