Version 0 of Using MFC Controls as Tk widgets

Updated 2002-07-12 13:20:32

I wrote a C++ class that allows the use of any MFC based Windows control as a pseudo Tk widget. The class is based on a proprietary library so I cannot disclose the source code, but it was pretty straightforward, and makes only minimal use of Tk's internals.

Here's some code to get the CWnd* for a Tk widget: (Path is a char* with the widget path name, or NULL for get the application's main window):

     Tk_Window const tkmainwin = Tk_MainWindow(interp);
     if (tkmainwin==NULL)
             return NULL;

     Tk_Window const tkwin = Path==NULL
             ? tkmainwin
             : Tk_NameToWindow(interp,Path,tkmainwin);
     if (tkwin==NULL)
             return NULL;

     Tk_MakeWindowExist(tkwin);
     Window const window = Tk_WindowId(tkwin);