How to set parent for my wxDialog to a non-wxWindow

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Slack
In need of some credit
In need of some credit
Posts: 1
Joined: Fri Aug 11, 2006 7:47 pm

How to set parent for my wxDialog to a non-wxWindow

Post by Slack » Fri Aug 11, 2006 7:50 pm

Under windows, I'm attempting to spawn a wxdialog in an environment where the parent window of the application is not wxWidgets controlled.

So where wxDialog wants a wxWindow* for its parent, is it possible to set my parent from a standard msw 'window'.

Thanks

james.chengguangwang
Knows some wx things
Knows some wx things
Posts: 38
Joined: Wed Aug 02, 2006 4:59 am

Topic review

Post by james.chengguangwang » Sat Aug 12, 2006 5:37 am

HI,

I don't know whether the parent window of the application you use is a ms standard CWnd class, if so, I think you can solve the problems as follows:

Code: Select all

// extern "C" so we don't need a DEF file 

// This is the function to be called from the host app 
extern "C" DLLFUNCTIONS_API void DLLFunction(HWND handle) 
{ 
// Create a dummy wxWindow so we can use the HWND passed from the 
// host application 

        wxWindow win; 
        win.SetHWND((WXHWND)handle); 
        win.Enable(false); 

        wxDialog dlg(&win, -1, wxT("wxDialog in DLL"), wxDefaultPosition, wxSize(150,150)); 
        wxButton b(&dlg, 123,wxT("Press me please")); 
        dlg.ShowModal(); 

// Clean up else the caller can't use its window 
        win.Enable(true); 
        win.SetHWND(0); 
} 
Maybe this can help you,please try it once.

DavidHart
Site Admin
Site Admin
Posts: 3885
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart » Sat Aug 12, 2006 9:22 am

Hi,

The easy answer is to use NULL. From the wxDialog::wxDialog doc: "parent can be NULL, a frame or another dialog box."

Regards,

David

cpp
I live to help wx-kind
I live to help wx-kind
Posts: 195
Joined: Wed Sep 28, 2005 9:42 pm

Post by cpp » Sun Aug 13, 2006 12:39 am

I think he means to use a parent from another application, if so, im not shure if the Windows API Function CreateWindowsEx allows passing an HWND from another process. If it does, then the first thing you need is to get the HWND from the window you desire as parent, and somehow "assign it"to a wxWidgets::wxWindow class, so you can pass the expected wxWindow to the Create function of the child window. (im not shure if this can be done?)

Just a clarification: CWnd
Hier Kommt die Sonne...

james.chengguangwang
Knows some wx things
Knows some wx things
Posts: 38
Joined: Wed Aug 02, 2006 4:59 am

Post by james.chengguangwang » Tue Aug 29, 2006 9:23 am

Hi All,

But when I use the NULL to create the wxDialog, the program will be crashed when creating the dialog obiect, can you resolve it? or do you have some good method to deal with it? thanks.

regards,
James

Post Reply