Version 1 of MFC Control in Tk toplevel

Updated 2006-05-04 13:37:53

[ author: Sascha Leuthold ]

[link to pic comming today]

UNDER CONSTRUCTION 4 May 2006

Using MFC Controls as Tk widgets and Combining GUI applications developed with Tk and 'native' Windows toolkits gives you an introduction, but it is not really a copy-paste implementation I was always looking for.

I saw this implemented in commercial applications, and asked myself: How did that work?

Somebody could ask, why embedding an MFC-Control into a Tk-toplevel:

  • devide GUI from core implemetation
  • building huge OpenGl or DirectX applications with platform-independent GUI (CAE,CAD,etc.)
  • make use of the impressing Tcl/Tk automation potential, and hide the core implementation
  • etc.

I will show you one complete implementation on the windows platform. It would be great, if somebody would do something similar on Unix/Linux(X11). I used VC++6.0, Tcl/Tk 8.4 and build this successfully on Win98 and WinXP. Maybe MFC and VC++6.0 is out of fashion, but I think it is still a nice topic, and it can result in a nice designed application. And at the end, the Win32-API is older than MFC, so for me, Tk is the real out of date problem in this marriage. This design makes it possible, to build applications for Linux and Windows, with minimum platform-dependence.

[Tk frame in MFC] gives you an implementation on the other direction.

Comments are welcome considering implementation-details and discussions on the subject itselfs (widget embedding).

Is it possible to achieve the same aim easier?


We will end up in a *.exe, that sources a *.tcl.

Features

  • toplevel contains button, frame -container true and a menu
  • frame will contain one CFrameWnd
  • interface of resize to resize the CFrameWnd connected to any toplevel-resize-operation
  • interface and override of exit to make sure, that the application not crashes on closing via exit command

MFCinTk.tcl

 code comming soon

comment

  • mfcContainer -container true, to enable embedding
  • variable mfcContainer, to access via C++, so the name is fixed
  • variable toplevel_id and variable container_id, to access via C++
  • ::mfcintk::CreateToplevel called from C++ during application runup (after sourcing the tcl-file)
  • bind to resize the toplevel, Resize is an interface proc provided by C++ (without the MFC Control would not resize)

Derive CWinApp to host the application/thread/event-loop

CMfCinTk.h

 code comming today

comment

  • ...

CMfCinTk.cpp

 code comming today

comment

  • ...

Derive CFrameWnd, the MFC Control

CMainFrame.h

 code comming today

comment

  • ...

CMainFrame.cpp

 code comming today

comment

  • ...

The implementation is straight forward, but it took some time for me, to make it work. And I'm not so familar with MFC. I did not cut any code out, so you can see everything, e.g. the command-line proccessing. As a side note, I have no tcl installation on my machine. So consider defining tcl_library, and look for some fixed path-names in the code.

  1. During runup the application init's Tcl and Tk
  2. The toplevel pops up after Tk_Init
  3. Than we source the tcl-file with the UI
  4. Now we build a CWnd-child-object into the frame with container -true
  5. Finished

What do you think?


[ Category GUI | Category Windows | Category Example ]