昨天尝试了一下把TCL集成到自定制程序里面.
代码如下:(运行之后会有一个windows窗口和tcl console,本意是可以通过tcl console改变窗口内的文字,不过还没写完)
// TCL_APP1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
#include
#include "tcl.h"
#include

/*
int main(int argc, char* argv[])
{
Tcl_Interp * interp;
char *str;
// str = "puts "hello world"";
// str = "puts [regexp a abc] ";
str = (char *)malloc(32);
scanf("%s",str);
interp = Tcl_CreateInterp();
assert(interp);
Tcl_Eval(interp,str);
Tcl_DeleteInterp(interp);
exit(0);
printf("Hello World! ");
return 0;
}*/
HWND hWindow;
DWORD WINAPI mainGUI( LPVOID lp)
{
HMODULE hInstance= 0;
hInstance = GetModuleHandle(NULL);
HWND hWnd; MSG msg;
hWnd = CreateWindow("EDIT", "This window was created from main() and can get messages from the console below.",
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
if (!hWnd) return (1);
*(HWND*)lp = hWnd;
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
while (GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (msg.wParam);
}
int SendMsg(ClientData clientdata,Tcl_Interp *interp,int argc, char *argv[])
{
char szOutput[64] = "Hello World from aj ";
if (NULL == hWindow)
return 1;
if (argc == 2)
{

}
SendMessage(hWindow,WM_SETTEXT, strlen(szOutput), (LPARAM)szOutput);
printf(" asdsad");
return TCL_OK;
}
int main(int argc, char* argv[])
{
DWORD ID;
char szOutput[64];
CreateThread(NULL,0,mainGUI, &hWindow, NULL,&ID);
Tcl_Main(argc, argv, Tcl_AppInit);
return 0;
}

int Tcl_AppInit(Tcl_Interp *interp)
{

if (Tcl_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
Tcl_SetVar (interp, "tcl_interactive", "", TCL_GLOBAL_ONLY);
Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY);
Tcl_CreateCommand(interp,"sendMsg",(Tcl_CmdProc *) SendMsg,(ClientData)NULL,(Tcl_CmdDeleteProc *)NULL);

return TCL_OK;
}
本文介绍了一种将TCL脚本语言集成到自定义应用程序的方法。通过创建Windows窗口和TCL控制台,实现了一个初步框架,允许通过TCL控制台修改窗口中的文本。



被折叠的 条评论
为什么被折叠?



