Click here to Skip to main content
14,768,146 members
Home » Discussions » C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to implement Ctrl + tab to navigate between tabs in a CTabCtrl Pin
Amrit Agr29-Apr-16 0:21
MemberAmrit Agr29-Apr-16 0:21 
QuestionDoes DestroyWindow Parent CDialog destroy all ChildControls Pin
ForNow27-Apr-16 14:11
MemberForNow27-Apr-16 14:11 
AnswerRe: Does DestroyWindow Parent CDialog destroy all ChildControls Pin
Richard MacCutchan27-Apr-16 22:45
mveRichard MacCutchan27-Apr-16 22:45 
GeneralRe: Does DestroyWindow Parent CDialog destroy all ChildControls Pin
ForNow28-Apr-16 3:13
MemberForNow28-Apr-16 3:13 
AnswerRe: Does DestroyWindow Parent CDialog destroy all ChildControls Pin
leon de boer28-Apr-16 2:34
Memberleon de boer28-Apr-16 2:34 
GeneralRe: Does DestroyWindow Parent CDialog destroy all ChildControls Pin
ForNow28-Apr-16 3:16
MemberForNow28-Apr-16 3:16 
AnswerRe: Does DestroyWindow Parent CDialog destroy all ChildControls Pin
Parthiban.Appuswamy28-Apr-16 4:39
MemberParthiban.Appuswamy28-Apr-16 4:39 
GeneralRe: Does DestroyWindow Parent CDialog destroy all ChildControls Pin
leon de boer28-Apr-16 5:51
Memberleon de boer28-Apr-16 5: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 3:22
MemberFrederick J. Harris24-Apr-16 3:22 
AnswerRe: How To Look At GCC C Sources Pin
Richard MacCutchan24-Apr-16 4:02
mveRichard MacCutchan24-Apr-16 4:02 
GeneralRe: How To Look At GCC C Sources Pin
Frederick J. Harris24-Apr-16 5:57
MemberFrederick J. Harris24-Apr-16 5:57 
GeneralRe: How To Look At GCC C Sources Pin
Richard MacCutchan24-Apr-16 6:44
mveRichard MacCutchan24-Apr-16 6:44 
AnswerRe: How To Look At GCC C Sources Pin
Jochen Arndt24-Apr-16 22:32
professionalJochen Arndt24-Apr-16 22:32 
GeneralRe: How To Look At GCC C Sources Pin
Frederick J. Harris25-Apr-16 0:57
MemberFrederick J. Harris25-Apr-16 0:57 
QuestionExchanging data using CSocket Pin
manoharbalu22-Apr-16 23:30
Membermanoharbalu22-Apr-16 23:30 
AnswerRe: Exchanging data using CSocket Pin
Jochen Arndt23-Apr-16 0:30
professionalJochen Arndt23-Apr-16 0:30 
GeneralRe: Exchanging data using CSocket Pin
manoharbalu24-Apr-16 21:23
Membermanoharbalu24-Apr-16 21:23 
GeneralRe: Exchanging data using CSocket Pin
Jochen Arndt24-Apr-16 21:53
professionalJochen Arndt24-Apr-16 21:53 
QuestionAdding UI to an existing console project using windows form Pin
Member 935023722-Apr-16 7:05
MemberMember 935023722-Apr-16 7:05 
AnswerRe: Adding UI to an existing console project using windows form Pin
Richard MacCutchan22-Apr-16 7:47
mveRichard MacCutchan22-Apr-16 7:47 
GeneralRe: Adding UI to an existing console project using windows form Pin
Member 935023725-Apr-16 22:51
MemberMember 935023725-Apr-16 22:51 
AnswerRe: Adding UI to an existing console project using windows form Pin
leon de boer24-Apr-16 16:49
Memberleon de boer24-Apr-16 16:49 
GeneralRe: Adding UI to an existing console project using windows form Pin
Member 935023725-Apr-16 22:55
MemberMember 935023725-Apr-16 22:55 
QuestionCode Blocks giving fatal error of not finding header file when there are seperate class files Pin
Mur250122-Apr-16 4:07
MemberMur250122-Apr-16 4:07 
SuggestionRe: Code Blocks giving fatal error of not finding header file when there are seperate class files Pin
Richard MacCutchan22-Apr-16 5:15
mveRichard MacCutchan22-Apr-16 5: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.