找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1451|回复: 0

ActiveX/VBA 技术通讯-1999年12月

[复制链接]

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-1-3 20:56:06 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
ActiveX/VBA Technical Newsletter - December 1999  
This document is part of    AutoCAD VB(A) Newsletter Archive     



/Note: the URLs in this posting may be broken into several lines by the
transmission media. Please make sure that you have the full URL before
trying to access it./

/Note: Have you missed a Newsletter issue? Visit our Newsletter archive at
the following URL:/

http://adn.autodesk.com/techsupp/docs/newsletters.htm

  

Dear AutoCAD ActiveX/VBA Developer,

Table of Contents
=================
(1) Zero Doc State and ActiveX
(2) New or Updated Solutions
  

(1) Zero Doc State and ActiveX
==============================

Question

I'm writing an ActiveX out-of-proc client app. I know that IAcadDocuments
exposes Add() and Open() methods. But when Acad is in the zero doc state, I
can get to the IAcadDocuments interface thus I can't programmatically call Add()
or Open().

How do I workaround this problem?

Answer

What you mentioned is true. When Acad is in the zero doc state, you can only
have access to IAcadApplication interface but not other objects down the
hierarchy.

As you have probably noticed that when Acad is in the zero doc state, there
is a file menu with which you can still open or create a new dwg.

What we can do here is to simulate that programmatically as if the user has
clicked the file new or file open menu items (ID_FILE_NEW and ID_FILE_OPEN
respectively).

HWND HWND_ACAD; // acad main frame window's handle

// create a new dwg
if(FindAcadFrameWnd() == TRUE)
      ::SendMessage(HWND_ACAD, WM_COMMAND, LOWORD(ID_FILE_NEW), NULL);

// open an exist dwg
if(FindAcadFrameWnd() == TRUE)
      ::SendMessage(HWND_ACAD, WM_COMMAND, LOWORD(ID_FILE_OPEN), NULL);

// the following code snippets are all
// for finding the Acad's window on the desktop
CString GetWindowTitle(HWND &hwnd)
{
      char s[256];
      if (!::GetWindowText(hwnd, s, sizeof(s)))
              return "";                // ignore empty titles
      else
              return s;
}

void SendCmdToAcad(CString& cmd)
{
      COPYDATASTRUCT cmdMsg;
      cmdMsg.dwData = (DWORD)1;
      cmdMsg.cbData = (DWORD)_tcslen(cmd) + 1;
      cmdMsg.lpData = cmd.GetBuffer(cmd.GetLength()+1) ;
      SendMessage(HWND_ACAD, WM_COPYDATA, NULL, (LPARAM)&cmdMsg);
}

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
      CString title = GetWindowTitle(hwnd);
      if(title == "")
              return TRUE;
      if(title.Find("AutoCAD") != -1)
      {
              HWND_ACAD = hwnd;
              return FALSE;
      }
      else
              return TRUE;
}

BOOL FindAcadFrameWnd()
{
      if(EnumWindows((WNDENUMPROC) EnumWindowsProc, NULL) == FALSE)
              return TRUE;
      else
              return FALSE;
}

-------------------------------------------------------------------

Question

When Acad is in the zero doc state, In my ARX app, I tried to use
ads_queueexpr("(command \"_QUIT\")"); to quit acad, it did not work.
SendMessage() with the same string can't do it either.

Also, when I want to the same thing from an ActiveX client app,
SendMessage()
with the quit string above didn't work.

How do I close the Acad window (quit, exit Acad) when it is at a zero doc
state?

Answer

When Acad is in the zero doc state, it will not accept any command line
commands
because the command line window doesn't exist. Thus any request for closing
the
Acad window, has to be sent to the Acad main frame window.

In you ARX app, the following line of code will close Acad. It may ask you
to
save your VBA macro if you have the VBA IDE window open.

::SendMessage(adsw_acadMainWnd(), WM_CLOSE, NULL, NULL);

In an ActiveX client app, even that IAcadApplication has a method Quit(), it
doesn't work when there is no document. So you'll need to use SendMessage().
The
only difference here is that you don't have the Acad main frame handle.
You'll
need to use some Win32 functions to achieve that, as shown below.

// a global variable for your client project
HWND HWND_ACAD;

CString GetWindowTitle(HWND &hwnd)
{
     char s[256];
     if (!::GetWindowText(hwnd, s, sizeof(s)))
             return ""; // ignore empty titles
     else
             return s;
}

void SendCmdToAcad(CString& cmd)
{
     COPYDATASTRUCT cmdMsg;
     cmdMsg.dwData = (DWORD)1;
     cmdMsg.cbData = (DWORD)_tcslen(cmd) + 1;
     cmdMsg.lpData = cmd.GetBuffer(cmd.GetLength()+1) ;
     SendMessage(HWND_ACAD, WM_COPYDATA, NULL, (LPARAM)&cmdMsg);
}

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
     CString title = GetWindowTitle(hwnd);
     if(title == "")
             return TRUE;
     if(title.Find("AutoCAD") != -1)
     {
             HWND_ACAD = hwnd;
             return FALSE;
     }
     else
             // to keep the loop going
             return TRUE;

}

BOOL FindAcadFrameWnd()
{
     if(EnumWindows((WNDENUMPROC) EnumWindowsProc, NULL) == FALSE)
             return TRUE;
     else
             return FALSE;
}
  

(2) New or Updated Solutions
============================

DETERMINE PRODUCT FROM DESIGN 2000 FAMILY
/cgi-bin/solution.pl?SID=46582

HOW CAN I CALL VBA FUNCTIONS THAT HAVE ARGUMENTS
/cgi-bin/solution.pl?SID=46019

REPLACE OPEN/INSERT/SAVE SCRIPT WITH ACTIVEX CODE
/cgi-bin/solution.pl?SID=45466

ADD ENTITIES INTO LAYOUT2
/cgi-bin/solution.pl?SID=45318

HOW TO AVOID THE SAVE DRAWING DIALOG BOX AFTER A SAVEAS WHEN QUITING
/cgi-bin/solution.pl?SID=45308

SET THE PAPER SIZE OF A LAYOUT
/cgi-bin/solution.pl?SID=45278

MAKING A VB FORM AS IF IT IS A CHILD WINDOW OF ACAD
/cgi-bin/solution.pl?SID=45175
  

-----------------------------------------------------------------------------
To subscribe or unsubscribe, go to
http://adn.autodesk.com/techsupp/docs/newsletters.htm
-----------------------------------------------------------------------------

     You received this message as a result of your registration
     on the ADN List Server subscription page.  If you no longer wish
     to receive these messages, read the next section, How to use this
     mailing list.

     How to use this mailing list:

     You may unsubscribe from this e-mail newsletter, or subscribe to
     a variety of other informative e-mail newsletters, by returning
     to the ADN List Server subscription page at
       http://adn.autodesk.com/techsupp/docs/newsletters.htm
     and changing your subscription preferences.

     Alternatively, from the subscribed account you can send an e-mail to
     <Majordomo-partnersys@autodesk.com> with the following command in the
     body of your email message:

     unsubscribe <list-name>

     ----------------------------------------------------------------------

     Autodesk Developer Network (ADN) information and events:

     For information on all ADN topics, please visit:
       http://www.autodesk.com/adn

     ----------------------------------------------------------------------

     THIS DOCUMENT IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY.  The
     information contained in this document represents the current view of
     Autodesk Inc. on the issues discussed as of the date of publication.
     Because Autodesk must respond to change in market conditions, it
     should not be interpreted to be a commitment on the part of Autodesk
     and Autodesk cannot guarantee the accuracy of any information
     presented after the date of publication.
     INFORMATION PROVIDED IN THIS DOCUMENT IS PROVIDED 'AS IS' WITHOUT
     WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT
     LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
     PARTICULAR PURPOSE AND FREEDOM FROM INFRINGEMENT.
     The user assumes the entire risk as to the accuracy and the use of
     this document. This  document may be copied and distributed subject to
     the following conditions:
     1.   All text must be copied without modification and all pages must
          be included
     2.   All copies must contain Autodesk's copyright notice and any other
          notices provided therein
     3.   This document may not be distributed for profit

     ----------------------------------------------------------------------
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-12-5 03:04 , Processed in 0.390304 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表