CTkView - a C++ class for embedding Tk in MFC viewsThe idea of embedding Tk in MFC windows always seemed very enticing but information was sparse and contradictory - on a scale between "very easy" and "not yet possible". The only thing for it was to have a go and lo, it wasn't that hard after all.CTkView is a C++ class which can be used in MFC SDI or MDI applications. An instance of CTkView hosts an embedded Tk toplevel widget and performs some management chores for the widget so that it can size, update and react correctly to Windows events. Here is where you can download source and binaries for CTkView. (~45K) Description
TKVIEW.EXE
TCLSRVR.TCL
REMCON.TCL
You will need a correctly installed TCL80 setup and the MFC DLLs to get all this to work. The sources compile with VC++ 5.0 How to use 1) First start tkview.exe. It initializes an embedded TCL interpreter and sources the script tclsrvr.tcl. This creates a listening socket within tkview.exe which can be used to "inject" scripts from outside into the programm. The programm then opens a view with an embedded Tk toplevel called .tk1. You can open further Tk views with the file/new menu option 2) Start wish80 with remcon.tcl as its argument, press the connect button and start issuing commands against the Tk window named .tk1. Press Ctrl-E or the Eval button to evaluate the highlighted text in the tkview interpreter. If no text is highlighted, then the current line is evaluated. Each new view which is opened is created with an embedded Tk toplevel widget. They are named .tk1, .tk2 etc By using these widget names you can pack child widgets into the MFC views It seems that most things work as one would expect. The windows size and update correctly, the widgets are active for mouse and keyboard input. However this has not been exhaustively tested and there will probably be some issues which need to be dealt with. I would appreciate any and all feedback from people who test or use this code. Good Luck ============================
int Tcl_Eval (Tcl_Interp* interp, const char* script) instead of int Tcl_Eval (Tcl_Interp* interp, char* script) The insertion of "const" does no harm to TCL (and requires no recompilation of the TCL DLLs) but does allow the VC++ compiler to cast from CString to char* without complaining. This was a convenience for me since I use CStrings extensively. Sorry if anyone tripped up on that ============================
|