GetTopLevelFrame in a dll

Posted on 2006-04-25
Medium Priority
Last Modified: 2013-11-20
i have this problem:
when i call to GetTopLevelFrame from an other module then the one that contains my application's main frame it returns NULL

now, the main frame GetTopLevelFrame should return is located in a dll and used into an simple win app.

i have looked over GetTopLevelFrame implementation in mfc and i can see why it returns NULL (it looks for a CFrameWnd that has no parent and my main frame is empedded into an other window, so it has a parent and its parent is not a CFrameWnd).

does anyone know of a way to make this function work when the main window is located in a dll and this method is called from another module?

Question by:Agarici
LVL 86

Accepted Solution

jkr earned 668 total points
ID: 16538366
Have you tried

CWnd* pWnd = AfxGetMainWnd();

CFrameWnd* pFrame = pWnd->GetTopLevelFrame();

LVL 11

Author Comment

ID: 16538654
first, thank you for the prompt reply

no, i haven;t try your sugestion, and i cant do that, because the call is from a dll which i can not modify

but basically that is what that code does.
let me explain a litle: i am using a third party library
from this library i am trying to create a modal dialog (which is implemented in that 3rd party dll).
GetTopLevelFrame gets called from somewere in DoModal and it returns NULL (i think because my main frame is in a dll and not in the exe module)

LVL 49

Assisted Solution

DanRollins earned 668 total points
ID: 16540022
When you create the modal dialog, are you able to specify its parent?  The constructor for CDialog provides and optional parameter...  So instead of,,,
    CMyDlg dlg;
    CMyDlg dlg( pwndWhateverYouWantToBeTheParentInTheCallToGetTopLevelFrame );

If you are using some other method to construct the CDialog-derived object, please post the code that you are using.

-- Dan
LVL 22

Assisted Solution

mahesh1402 earned 664 total points
ID: 16541459
As suggested by Dan you may try it by setting parent of window explicitly.

You may also use CWnd::SetParent() function for this..

pWnd->SetParent(this); // attach current window as parent or pass whatever parent window handle is.


Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question