把TCL集成到自己的程序裏

昨天嘗試了一下把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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章