How to get the parent structure as Spy++ gives it?









up vote
2
down vote

favorite












In our code, a C++ class that is derived from CMDIChildWnd is instantiated and its Create() function is called, which is actually CMDIChildWnd::Create(). The 5th parameter pParentWnd is being set to a CMDIFrameWnd object. This in turn (within the MFC code) sets up a CREATESTRUCT object, sets it's hwndParent to that parameter and then calls PreCreateWindow() with that object passed as one of the parameters.



However, when going up the parent window list using CWnd::GetParent() (original) GetAncestor(hwnd, GA_PARENT) (just a try, since the original didn't work and this code is 20+ years old) and even GetWindow(hwnd, GW_OWNER) just to see if it was setting the window's owner for some reason. In each case, I do not see the handle which is associated with the CMDIFrameWnd object. Instead, the parent shown is the desktop, and owner is NULL.



Using Spy++, it shows what I was expecting. How would I get the layout given by Spy++ programmatically?










share|improve this question



















  • 1




    AfxGetMainWnd() should return the main frame window. CMDIChildWnd is usually passed to CMultiDocTemplate, I am not familiar with the usage you are describing.
    – Barmak Shemirani
    Nov 12 at 7:44











  • Use Spy++ to see the true window hierarchy. That will reflect the relationship without any code in between, that may or may not do something to be helpful.
    – IInspectable
    Nov 12 at 10:11










  • @IInspectable, I have used spy++, and it shows what I want to see, but how do I get that answer in code?
    – Adrian
    Nov 12 at 15:03











  • @BarmakShemirani, I'm not looking for the root CMDIFrameWnd. I'm looking for the one that is the parent to a particular CMDIChildWnd. We have some CMDIFrameWnd which are parented to other CMDIFrameWnd windows.
    – Adrian
    Nov 12 at 16:07










  • MDI is odd, it comes with its own API. See if Multiple Document Interface has the answers you are looking for.
    – IInspectable
    Nov 12 at 16:20














up vote
2
down vote

favorite












In our code, a C++ class that is derived from CMDIChildWnd is instantiated and its Create() function is called, which is actually CMDIChildWnd::Create(). The 5th parameter pParentWnd is being set to a CMDIFrameWnd object. This in turn (within the MFC code) sets up a CREATESTRUCT object, sets it's hwndParent to that parameter and then calls PreCreateWindow() with that object passed as one of the parameters.



However, when going up the parent window list using CWnd::GetParent() (original) GetAncestor(hwnd, GA_PARENT) (just a try, since the original didn't work and this code is 20+ years old) and even GetWindow(hwnd, GW_OWNER) just to see if it was setting the window's owner for some reason. In each case, I do not see the handle which is associated with the CMDIFrameWnd object. Instead, the parent shown is the desktop, and owner is NULL.



Using Spy++, it shows what I was expecting. How would I get the layout given by Spy++ programmatically?










share|improve this question



















  • 1




    AfxGetMainWnd() should return the main frame window. CMDIChildWnd is usually passed to CMultiDocTemplate, I am not familiar with the usage you are describing.
    – Barmak Shemirani
    Nov 12 at 7:44











  • Use Spy++ to see the true window hierarchy. That will reflect the relationship without any code in between, that may or may not do something to be helpful.
    – IInspectable
    Nov 12 at 10:11










  • @IInspectable, I have used spy++, and it shows what I want to see, but how do I get that answer in code?
    – Adrian
    Nov 12 at 15:03











  • @BarmakShemirani, I'm not looking for the root CMDIFrameWnd. I'm looking for the one that is the parent to a particular CMDIChildWnd. We have some CMDIFrameWnd which are parented to other CMDIFrameWnd windows.
    – Adrian
    Nov 12 at 16:07










  • MDI is odd, it comes with its own API. See if Multiple Document Interface has the answers you are looking for.
    – IInspectable
    Nov 12 at 16:20












up vote
2
down vote

favorite









up vote
2
down vote

favorite











In our code, a C++ class that is derived from CMDIChildWnd is instantiated and its Create() function is called, which is actually CMDIChildWnd::Create(). The 5th parameter pParentWnd is being set to a CMDIFrameWnd object. This in turn (within the MFC code) sets up a CREATESTRUCT object, sets it's hwndParent to that parameter and then calls PreCreateWindow() with that object passed as one of the parameters.



However, when going up the parent window list using CWnd::GetParent() (original) GetAncestor(hwnd, GA_PARENT) (just a try, since the original didn't work and this code is 20+ years old) and even GetWindow(hwnd, GW_OWNER) just to see if it was setting the window's owner for some reason. In each case, I do not see the handle which is associated with the CMDIFrameWnd object. Instead, the parent shown is the desktop, and owner is NULL.



Using Spy++, it shows what I was expecting. How would I get the layout given by Spy++ programmatically?










share|improve this question















In our code, a C++ class that is derived from CMDIChildWnd is instantiated and its Create() function is called, which is actually CMDIChildWnd::Create(). The 5th parameter pParentWnd is being set to a CMDIFrameWnd object. This in turn (within the MFC code) sets up a CREATESTRUCT object, sets it's hwndParent to that parameter and then calls PreCreateWindow() with that object passed as one of the parameters.



However, when going up the parent window list using CWnd::GetParent() (original) GetAncestor(hwnd, GA_PARENT) (just a try, since the original didn't work and this code is 20+ years old) and even GetWindow(hwnd, GW_OWNER) just to see if it was setting the window's owner for some reason. In each case, I do not see the handle which is associated with the CMDIFrameWnd object. Instead, the parent shown is the desktop, and owner is NULL.



Using Spy++, it shows what I was expecting. How would I get the layout given by Spy++ programmatically?







windows winapi mfc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 21:58

























asked Nov 12 at 5:10









Adrian

3,89922057




3,89922057







  • 1




    AfxGetMainWnd() should return the main frame window. CMDIChildWnd is usually passed to CMultiDocTemplate, I am not familiar with the usage you are describing.
    – Barmak Shemirani
    Nov 12 at 7:44











  • Use Spy++ to see the true window hierarchy. That will reflect the relationship without any code in between, that may or may not do something to be helpful.
    – IInspectable
    Nov 12 at 10:11










  • @IInspectable, I have used spy++, and it shows what I want to see, but how do I get that answer in code?
    – Adrian
    Nov 12 at 15:03











  • @BarmakShemirani, I'm not looking for the root CMDIFrameWnd. I'm looking for the one that is the parent to a particular CMDIChildWnd. We have some CMDIFrameWnd which are parented to other CMDIFrameWnd windows.
    – Adrian
    Nov 12 at 16:07










  • MDI is odd, it comes with its own API. See if Multiple Document Interface has the answers you are looking for.
    – IInspectable
    Nov 12 at 16:20












  • 1




    AfxGetMainWnd() should return the main frame window. CMDIChildWnd is usually passed to CMultiDocTemplate, I am not familiar with the usage you are describing.
    – Barmak Shemirani
    Nov 12 at 7:44











  • Use Spy++ to see the true window hierarchy. That will reflect the relationship without any code in between, that may or may not do something to be helpful.
    – IInspectable
    Nov 12 at 10:11










  • @IInspectable, I have used spy++, and it shows what I want to see, but how do I get that answer in code?
    – Adrian
    Nov 12 at 15:03











  • @BarmakShemirani, I'm not looking for the root CMDIFrameWnd. I'm looking for the one that is the parent to a particular CMDIChildWnd. We have some CMDIFrameWnd which are parented to other CMDIFrameWnd windows.
    – Adrian
    Nov 12 at 16:07










  • MDI is odd, it comes with its own API. See if Multiple Document Interface has the answers you are looking for.
    – IInspectable
    Nov 12 at 16:20







1




1




AfxGetMainWnd() should return the main frame window. CMDIChildWnd is usually passed to CMultiDocTemplate, I am not familiar with the usage you are describing.
– Barmak Shemirani
Nov 12 at 7:44





AfxGetMainWnd() should return the main frame window. CMDIChildWnd is usually passed to CMultiDocTemplate, I am not familiar with the usage you are describing.
– Barmak Shemirani
Nov 12 at 7:44













Use Spy++ to see the true window hierarchy. That will reflect the relationship without any code in between, that may or may not do something to be helpful.
– IInspectable
Nov 12 at 10:11




Use Spy++ to see the true window hierarchy. That will reflect the relationship without any code in between, that may or may not do something to be helpful.
– IInspectable
Nov 12 at 10:11












@IInspectable, I have used spy++, and it shows what I want to see, but how do I get that answer in code?
– Adrian
Nov 12 at 15:03





@IInspectable, I have used spy++, and it shows what I want to see, but how do I get that answer in code?
– Adrian
Nov 12 at 15:03













@BarmakShemirani, I'm not looking for the root CMDIFrameWnd. I'm looking for the one that is the parent to a particular CMDIChildWnd. We have some CMDIFrameWnd which are parented to other CMDIFrameWnd windows.
– Adrian
Nov 12 at 16:07




@BarmakShemirani, I'm not looking for the root CMDIFrameWnd. I'm looking for the one that is the parent to a particular CMDIChildWnd. We have some CMDIFrameWnd which are parented to other CMDIFrameWnd windows.
– Adrian
Nov 12 at 16:07












MDI is odd, it comes with its own API. See if Multiple Document Interface has the answers you are looking for.
– IInspectable
Nov 12 at 16:20




MDI is odd, it comes with its own API. See if Multiple Document Interface has the answers you are looking for.
– IInspectable
Nov 12 at 16:20












1 Answer
1






active

oldest

votes

















up vote
0
down vote













In MDI interface CMDIChildWnd is usually passed to CMultiDocTemplate, then we create a new window through CDocManager::OnFileNew, that in turn calls CFrameWnd::LoadFrame which passes NULL for child window's parent (at least in VS 2017)



We usually don't call mdi_child->Create directly, unless we initialize everything else manually. Perhaps you mean the base class CMDIChildWnd::Create is called, or you are able to override it.



In child window,



::GetAncestor(m_hWnd, GA_ROOT) or ::GetAncestor(m_hWnd, GA_ROOTOWNER)



Should return a reference to the main frame, otherwise use AfxGetMainWnd()






share|improve this answer




















  • Unfortunately, I didn't write this code. It is 5+ years old and I've been here only 3. mdi_child->Create() was called by our code. We are not loading a new file. We're generating a frame to be used by a Chromium CEF window. What sort of things would be initialized manually?
    – Adrian
    Nov 12 at 22:08











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256240%2fhow-to-get-the-parent-structure-as-spy-gives-it%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













In MDI interface CMDIChildWnd is usually passed to CMultiDocTemplate, then we create a new window through CDocManager::OnFileNew, that in turn calls CFrameWnd::LoadFrame which passes NULL for child window's parent (at least in VS 2017)



We usually don't call mdi_child->Create directly, unless we initialize everything else manually. Perhaps you mean the base class CMDIChildWnd::Create is called, or you are able to override it.



In child window,



::GetAncestor(m_hWnd, GA_ROOT) or ::GetAncestor(m_hWnd, GA_ROOTOWNER)



Should return a reference to the main frame, otherwise use AfxGetMainWnd()






share|improve this answer




















  • Unfortunately, I didn't write this code. It is 5+ years old and I've been here only 3. mdi_child->Create() was called by our code. We are not loading a new file. We're generating a frame to be used by a Chromium CEF window. What sort of things would be initialized manually?
    – Adrian
    Nov 12 at 22:08















up vote
0
down vote













In MDI interface CMDIChildWnd is usually passed to CMultiDocTemplate, then we create a new window through CDocManager::OnFileNew, that in turn calls CFrameWnd::LoadFrame which passes NULL for child window's parent (at least in VS 2017)



We usually don't call mdi_child->Create directly, unless we initialize everything else manually. Perhaps you mean the base class CMDIChildWnd::Create is called, or you are able to override it.



In child window,



::GetAncestor(m_hWnd, GA_ROOT) or ::GetAncestor(m_hWnd, GA_ROOTOWNER)



Should return a reference to the main frame, otherwise use AfxGetMainWnd()






share|improve this answer




















  • Unfortunately, I didn't write this code. It is 5+ years old and I've been here only 3. mdi_child->Create() was called by our code. We are not loading a new file. We're generating a frame to be used by a Chromium CEF window. What sort of things would be initialized manually?
    – Adrian
    Nov 12 at 22:08













up vote
0
down vote










up vote
0
down vote









In MDI interface CMDIChildWnd is usually passed to CMultiDocTemplate, then we create a new window through CDocManager::OnFileNew, that in turn calls CFrameWnd::LoadFrame which passes NULL for child window's parent (at least in VS 2017)



We usually don't call mdi_child->Create directly, unless we initialize everything else manually. Perhaps you mean the base class CMDIChildWnd::Create is called, or you are able to override it.



In child window,



::GetAncestor(m_hWnd, GA_ROOT) or ::GetAncestor(m_hWnd, GA_ROOTOWNER)



Should return a reference to the main frame, otherwise use AfxGetMainWnd()






share|improve this answer












In MDI interface CMDIChildWnd is usually passed to CMultiDocTemplate, then we create a new window through CDocManager::OnFileNew, that in turn calls CFrameWnd::LoadFrame which passes NULL for child window's parent (at least in VS 2017)



We usually don't call mdi_child->Create directly, unless we initialize everything else manually. Perhaps you mean the base class CMDIChildWnd::Create is called, or you are able to override it.



In child window,



::GetAncestor(m_hWnd, GA_ROOT) or ::GetAncestor(m_hWnd, GA_ROOTOWNER)



Should return a reference to the main frame, otherwise use AfxGetMainWnd()







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 at 21:58









Barmak Shemirani

20.7k42045




20.7k42045











  • Unfortunately, I didn't write this code. It is 5+ years old and I've been here only 3. mdi_child->Create() was called by our code. We are not loading a new file. We're generating a frame to be used by a Chromium CEF window. What sort of things would be initialized manually?
    – Adrian
    Nov 12 at 22:08

















  • Unfortunately, I didn't write this code. It is 5+ years old and I've been here only 3. mdi_child->Create() was called by our code. We are not loading a new file. We're generating a frame to be used by a Chromium CEF window. What sort of things would be initialized manually?
    – Adrian
    Nov 12 at 22:08
















Unfortunately, I didn't write this code. It is 5+ years old and I've been here only 3. mdi_child->Create() was called by our code. We are not loading a new file. We're generating a frame to be used by a Chromium CEF window. What sort of things would be initialized manually?
– Adrian
Nov 12 at 22:08





Unfortunately, I didn't write this code. It is 5+ years old and I've been here only 3. mdi_child->Create() was called by our code. We are not loading a new file. We're generating a frame to be used by a Chromium CEF window. What sort of things would be initialized manually?
– Adrian
Nov 12 at 22:08


















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256240%2fhow-to-get-the-parent-structure-as-spy-gives-it%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党