[求助]这个通过消息的方式加载定制菜单的程序问题出在哪里?
我按照《AutoCAD 2000 ARX 开发技术》第八章的程序,通过消息的方式向AutoCAD发送字符串命令,实现启动AutoCAD 2000并加载定制菜单,源
程序如下:
// StartACAD.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
//函数声明
void sendCommandToAutoCAD(const HWND hWndApp,
const HWND hWndAcad,const LPSTR cmd);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
//下述代码创建并注册应用程序窗口类
char ClassName[]="Start AutoCAD";
WNDCLASS WndClass;
HWND hWndACAD=NULL;
if(!hPrevInstance)
{
memset(&WndClass,0x00,sizeof(WNDCLASS));
WndClass.style=0;
WndClass.lpfnWndProc=(WNDPROC)NULL; //不需要窗口回调函数
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hInstance=hInstance;
WndClass.hIcon=NULL;
WndClass.hCursor=NULL;
WndClass.hbrBackground=NULL;
WndClass.lpszMenuName=NULL;
WndClass.lpszClassName=ClassName;
RegisterClass(&WndClass);
}
//产生应用程序窗口,并返回句柄
HWND hWndApp=CreateWindow(ClassName,"",WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
hWndACAD=FindWindow(NULL,"AutoCAD 2000");
if(hWndACAD)
{
BringWindowToTop(hWndACAD);
ShowWindow(hWndACAD,SW_RESTORE);
}
else
{
//启动AutoCAD 2000并获得其主程序窗口
if(WinExec("C:\\Program Files\\ACAD2000\\ACAD.exe",SW_SHOWNORMAL)<32)
{
MessageBox(NULL,"AutoCAD 2000启动失败","Message",MB_OK);
return FALSE;
}
for(int num=0;num<=100;num++)
{
Sleep(500); //暂停,释放控制权
if((hWndACAD=FindWindow(NULL,"AutoCAD 2000"))!=NULL)
break;
}
}
char cmdString;//命令字符串变量
//设置系统变量FILEDIA
strcpy(cmdString,"(setq IsChanged 1)(if(=(getvar\"FILEDIA\")1)(setvar\"FILEDIA\"0)(setq IsChanged 0))\n");
sendCommandToAutoCAD(hWndApp,hWndACAD,cmdString);
//加载定制菜单
strcpy(cmdString,"MENU\nD:\\Sample.mnc\n");
sendCommandToAutoCAD(hWndApp,hWndACAD,cmdString);
//恢复系统变量FILEDIA
strcpy(cmdString,"(if(=IsChanged 1)(setvar\"FILEDIA\"1))\n");
sendCommandToAutoCAD(hWndApp,hWndACAD,cmdString);
DestroyWindow(hWndApp);
return 0;
}
//该函数向AutoCAD 2000主程序发送字符串命令
void sendCommandToAutoCAD(const HWND hWndApp,
const HWND hWndAcad,const LPSTR cmd)
{
if(!hWndAcad)
return;
COPYDATASTRUCT cmdMsg;
cmdMsg.dwData=(DWORD)1;
cmdMsg.cbData=(DWORD)strlen(cmd)+1;
cmdMsg.lpData=cmd;
SendMessageA(hWndAcad,WM_COPYDATA,(WPARAM)hWndApp,(LPARAM)&cmdMsg);
}
但我运行StartAcad.exe程序后,只启动了cad系统,并未能加载定制菜单(菜单
文件Sample.mnc放在目录D:\下)。下面是cad启动时命令行的显示结果:
Regenerating model.
(setq IsChanged 1)(if(=(getvar"FILEDIA")1)(setvar"FILEDIA"0)(setq IsChanged 0))
0
MENU
D:\Sample.mnc
(if(=IsChanged 1)(setvar"FILEDIA"1))
; error: no function definition: =ISCHANGED
AutoCAD menu utilities loaded.
我不知道问题出在哪里,请大家帮我看看!!!
我想用这种方法实现启动cad时自动运行一脚本语言程序,不知行否?
页:
[1]