Click here to Skip to main content
15,898,991 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: winsock servers ... console apps... Pin
Paul M Watt15-May-02 8:02
mentorPaul M Watt15-May-02 8:02 
GeneralRe: winsock servers ... console apps... Pin
Anders Molin15-May-02 8:03
professionalAnders Molin15-May-02 8:03 
GeneralRe: winsock servers ... console apps... Pin
Nemanja Trifunovic15-May-02 8:17
Nemanja Trifunovic15-May-02 8:17 
GeneralRe: winsock servers ... console apps... Pin
Amit Dey15-May-02 10:19
Amit Dey15-May-02 10:19 
Generalpopup menu font sizing Pin
jimNLX15-May-02 7:10
jimNLX15-May-02 7:10 
GeneralRe: popup menu font sizing Pin
Paul M Watt15-May-02 8:12
mentorPaul M Watt15-May-02 8:12 
GeneralOnly if WTL had AfxGetMainWnd Pin
Mike.NET15-May-02 7:13
Mike.NET15-May-02 7:13 
GeneralRe: Only if WTL had AfxGetMainWnd Pin
Paul M Watt15-May-02 7:47
mentorPaul M Watt15-May-02 7:47 
Mike.NET wrote:
Is there such way? Or am I just dreaming

But there are things that you can do to get around this.

When you call this in MFC:

CMainFrame *pFrame = (CMainFrame*)AfxGetMainWnd();

it is returning a pointer to the window that is stored as a member variable inside of the app object.

You could either mimick this behaviour by creating your own app module that derives from CAppModule, and stores this member variable.

Since GetTopLevelWindow only returns a HWND there is no way to cast this handle to a CWindow object without creating a completely new instance of the object. The next best thing that you could do is store a pointer to the CWindow, (or CMainFrame) object in the user data field of the window.

That way you could do this to get the pointer that you are interested in:
HWND hWnd = GetTopLevelWindow();
CMainFrame *mainFrm = dynamic_cast<CMainFrame*>(::GetWindowLong(hWnd, GWL_USERDATA);
if (NULL == mainFrm)
{
    // This window is not of type CMainFrame
    // Do error handling, or dynamic_cast to a CWindow if you are interested.
}
    // This would now be a valid call through your pointer.
mainFrm->MyFunction(...);


Good Luck!


Build a man a fire, and he will be warm for a day
Light a man on fire, and he will be warm for the rest of his life!

GeneralDisplaying Context Sensitive Help Button Without Displaying The Cancel Button in the System Menu Pin
Dean Michaud15-May-02 6:34
Dean Michaud15-May-02 6:34 
GeneralRe: Displaying Context Sensitive Help Button Without Displaying The Cancel Button in the System Menu Pin
Paul M Watt15-May-02 7:05
mentorPaul M Watt15-May-02 7:05 
GeneralRe: Displaying Context Sensitive Help Button Without Displaying The Cancel Button in the System Menu Pin
Dean Michaud15-May-02 7:22
Dean Michaud15-May-02 7:22 
Generalwebbrowser control question Pin
Jason Henderson15-May-02 6:30
Jason Henderson15-May-02 6:30 
GeneralRe: webbrowser control question Pin
Paul M Watt15-May-02 7:19
mentorPaul M Watt15-May-02 7:19 
GeneralPassing PVOID through VARIANT Pin
Hans Ruck15-May-02 6:25
Hans Ruck15-May-02 6:25 
GeneralRe: Passing PVOID through VARIANT Pin
Chris Losinger15-May-02 11:48
professionalChris Losinger15-May-02 11:48 
GeneralProgram only runs within IDE Pin
David Chamberlain15-May-02 6:11
David Chamberlain15-May-02 6:11 
GeneralRe: Program only runs within IDE Pin
Paul M Watt15-May-02 6:18
mentorPaul M Watt15-May-02 6:18 
GeneralRe: Program only runs within IDE Pin
David Chamberlain15-May-02 6:51
David Chamberlain15-May-02 6:51 
GeneralRe: Program only runs within IDE Pin
David Chamberlain15-May-02 7:02
David Chamberlain15-May-02 7:02 
GeneralRe: Program only runs within IDE Pin
Navin15-May-02 6:39
Navin15-May-02 6:39 
GeneralRe: Program only runs within IDE Pin
David Chamberlain15-May-02 6:53
David Chamberlain15-May-02 6:53 
GeneralMaking my own file dialog Pin
Nnamdi Onyeyiri15-May-02 6:03
Nnamdi Onyeyiri15-May-02 6:03 
GeneralRe: Making my own file dialog Pin
Paul M Watt15-May-02 6:13
mentorPaul M Watt15-May-02 6:13 
GeneralRe: Making my own file dialog Pin
Nnamdi Onyeyiri15-May-02 6:17
Nnamdi Onyeyiri15-May-02 6:17 
GeneralRe: Making my own file dialog Pin
Jason Henderson15-May-02 6:23
Jason Henderson15-May-02 6:23 

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.