找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 967|回复: 1

[每日一码] 接受LISP参数,实现文本编辑框

[复制链接]

已领礼包: 1个

财富等级: 恭喜发财

发表于 2021-1-17 11:06:49 | 显示全部楼层 |阅读模式

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

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

×
  1. // (C) Copyright 2002-2005 by Autodesk, Inc.
  2. //
  3. // Permission to use, copy, modify, and distribute this software in
  4. // object code form for any purpose and without fee is hereby granted,
  5. // provided that the above copyright notice appears in all copies and
  6. // that both that copyright notice and the limited warranty and
  7. // restricted rights notice below appear in all supporting
  8. // documentation.
  9. //
  10. // AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
  11. // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
  12. // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
  13. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
  14. // UNINTERRUPTED OR ERROR FREE.
  15. //
  16. // Use, duplication, or disclosure by the U.S. ** is subject to
  17. // restrictions set forth in FAR 52.227-19 (Commercial Computer
  18. // Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
  19. // (Rights in Technical Data and Computer Software), as applicable.
  20. //

  21. //-----------------------------------------------------------------------------
  22. //----- TextBox.cpp : Implementation of TextBox
  23. //-----------------------------------------------------------------------------
  24. #include "StdAfx.h"
  25. #include "resource.h"
  26. #include "TextBox.h"

  27. //-----------------------------------------------------------------------------
  28. IMPLEMENT_DYNAMIC (TextBox, CAcUiDialog)

  29. BEGIN_MESSAGE_MAP(TextBox, CAcUiDialog)
  30.   ON_MESSAGE(WM_ACAD_KEEPFOCUS, OnAcadKeepFocus)
  31. END_MESSAGE_MAP()

  32. //-----------------------------------------------------------------------------
  33. TextBox::TextBox (CWnd *pParent /*=NULL*/, HINSTANCE hInstance /*=NULL*/)
  34. : CAcUiDialog (TextBox::IDD, pParent, hInstance) , m_editBoxString(_T("")) , m_labelString(_T(""))
  35. {
  36. }

  37. //-----------------------------------------------------------------------------
  38. void TextBox::DoDataExchange (CDataExchange *pDX) {
  39.   CAcUiDialog::DoDataExchange (pDX) ;
  40.   DDX_Text(pDX, IDC_EDIT1, m_editBoxString);
  41.   DDX_Text(pDX, IDC_LABEL, m_labelString);
  42.   DDX_Control(pDX, IDC_EDIT1, m_editControl);
  43. }

  44. //-----------------------------------------------------------------------------
  45. //----- Needed for modeless dialogs to keep focus.
  46. //----- Return FALSE to not keep the focus, return TRUE to keep the focus
  47. LRESULT TextBox::OnAcadKeepFocus (WPARAM, LPARAM) {
  48.   return (TRUE) ;
  49. }

  50. //
  51. BOOL TextBox::OnInitDialog()
  52. {
  53.   CAcUiDialog::OnInitDialog();

  54.   //set the caption
  55.   SetWindowText(m_caption);

  56.   //set focus to the editbox
  57.   m_editControl.SetFocus();
  58.   return FALSE;
  59.   // return TRUE unless you set the focus to a control
  60.   // EXCEPTION: OCX Property Pages should return FALSE
  61. }

  62. //-----------------------------------------------------------------------------
  63. #pragma region //DlgTextBox

  64. //(crptextbox "Title" "Label" "Default Text")
  65. int DlgTextBox(void)
  66. {
  67.   LPCTSTR pszCaption;
  68.   LPCTSTR pszLabel;
  69.   LPCTSTR pszText;

  70.   //get args from lisp
  71.   struct resbuf *pArgs = acedGetArgs();

  72.   if (pArgs == NULL)
  73.     return acedRetNil();

  74.   //get caption string
  75.   if (pArgs->restype != RTSTR )
  76. return acedRetNil();

  77.   pszCaption = pArgs->resval.rstring;

  78.   //get label string
  79.   if ((pArgs = pArgs->rbnext) == NULL || pArgs->restype != RTSTR )
  80.   return acedRetNil();

  81.   pszLabel = pArgs->resval.rstring;

  82.   //get the defaul text
  83.   if ((pArgs = pArgs->rbnext) == NULL || pArgs->restype != RTSTR  )
  84.     pszText = _T("");
  85.   else
  86.     pszText = pArgs->resval.rstring;

  87.   ///////Dialog Stuff
  88.   CAcExtensionModule objResOverride;

  89.   TextBox dlg(CWnd::FromHandle(adsw_acadMainWnd()));

  90.   //
  91.   dlg.m_caption = pszCaption;
  92.   dlg.m_editBoxString = pszText;
  93.   dlg.m_labelString = pszLabel;

  94.   int m_dlgResult = dlg.DoModal();

  95.   if ( m_dlgResult != IDOK )
  96.    return acedRetNil();
  97.   else
  98.     pszText = dlg.m_editBoxString;

  99.   //
  100.   if ( _tcslen(pszText) == 0 )
  101.     return acedRetNil();

  102.   acedRetStr(pszText);
  103.   return (RSRSLT) ;
  104. }
  105. #pragma endregion

  106. #pragma region //DlgIntBox

  107. //(crpintbox "Title" "Label" 12)
  108. int DlgIntBox(void)
  109. {
  110.   LPCTSTR pszCaption;
  111.   LPCTSTR pszLabel;
  112.   LPCTSTR pszIntText;
  113.   ACHAR buf[256] = {0};

  114.   int iInt;

  115.   //
  116.   struct resbuf *pArgs = acedGetArgs() ;

  117.   if (pArgs == NULL)
  118.     return acedRetNil();

  119.   //
  120.   if (pArgs->restype != RTSTR )
  121.    return acedRetNil();
  122.   else
  123.     pszCaption = pArgs->resval.rstring;

  124.   //
  125.   if ((pArgs = pArgs->rbnext) == NULL || pArgs->restype != RTSTR )
  126.     return acedRetNil();
  127.   else
  128.     pszLabel = pArgs->resval.rstring;

  129.   //
  130.   if ((pArgs = pArgs->rbnext) != NULL )
  131.   {
  132.     if (pArgs->restype == RTSHORT)
  133.       pszIntText = _itot(pArgs->resval.rint , buf, 10);
  134.     else if (pArgs->restype == RTLONG)
  135.       pszIntText = _itot(pArgs->resval.rlong ,buf, 10);
  136.     else if (pArgs->restype == RTREAL)
  137.       pszIntText = _itot((int)pArgs->resval.rreal , buf, 10);
  138.     else
  139.       pszIntText = _T("");
  140.   }
  141.   else
  142.   {
  143.     pszIntText = _T("");
  144.   }

  145.   ///////Dialog Stuff
  146.   CAcExtensionModule objResOverride;

  147.   //
  148.   TextBox dlg(CWnd::FromHandle(adsw_acadMainWnd()));

  149.   //
  150.   dlg.m_caption = pszCaption;
  151.   dlg.m_labelString = pszLabel;
  152.   dlg.m_editBoxString = pszIntText;

  153.   //
  154.   int m_dlgResult = dlg.DoModal();

  155.   //
  156.   if ( m_dlgResult != IDOK )
  157.    return acedRetNil();
  158.   else
  159.     pszIntText = dlg.m_editBoxString;

  160.   if ( _tcslen(pszIntText) == 0 )
  161.     return acedRetNil();

  162.   //
  163.   iInt = _ttoi(pszIntText);
  164.   //
  165.   acedRetInt(iInt);
  166.   return (RSRSLT) ;
  167. }
  168. #pragma endregion

  169. #pragma region //DlgRealBox
  170. //(crprealbox "Title" "Label" 12.23)
  171. int DlgRealBox(void)
  172. {
  173.   LPCTSTR pszCaption;
  174.   LPCTSTR pszLabel;
  175.   LPCTSTR pszRealText;
  176.   ACHAR buf[256];

  177.   double dReal;
  178.   //
  179.   struct resbuf *pArgs = acedGetArgs() ;

  180.   if (pArgs == NULL)
  181.    return acedRetNil();


  182.   //
  183.   if (pArgs->restype != RTSTR )
  184.    return acedRetNil();

  185.   pszCaption =  pArgs->resval.rstring;

  186.   //
  187.   if ((pArgs = pArgs->rbnext) == NULL || pArgs->restype != RTSTR )
  188.     return acedRetNil();

  189.   pszLabel = pArgs->resval.rstring;

  190.   //
  191.   if ((pArgs = pArgs->rbnext) != NULL)
  192.   {
  193.     if (pArgs->restype == RTREAL )
  194.       _stprintf(buf , _T("%0.2f") , (double)pArgs->resval.rreal );
  195.     else if (pArgs->restype == RTLONG)
  196.       _stprintf(buf, _T("%0.2f") ,  (double)pArgs->resval.rlong );
  197.     else if (pArgs->restype == RTSHORT)
  198.       _stprintf( buf , _T("%0.2f") ,(double)pArgs->resval.rint );
  199.     else
  200.       buf[0] = '\0';
  201.   }
  202.   else
  203.     buf[0] = '\0';

  204.   pszRealText = buf;

  205.   ///////Dialog Stuff
  206.   CAcExtensionModule objResOverride;

  207.   //
  208.   TextBox dlg(CWnd::FromHandle(adsw_acadMainWnd()));

  209.   //
  210.   dlg.m_caption = pszCaption;
  211.   dlg.m_labelString = pszLabel;
  212.   dlg.m_editBoxString = pszRealText;

  213.   //
  214.   int m_dlgResult = dlg.DoModal();
  215.   if ( m_dlgResult != IDOK )
  216.    return acedRetNil();
  217.   else
  218.     pszRealText = dlg.m_editBoxString;

  219.   //
  220.   if ( _tcslen(pszRealText) == 0 )
  221.     return acedRetNil();

  222.   //
  223.   dReal = _tstof(pszRealText);

  224.   //
  225.   acedRetReal(dReal);
  226.   return (RSRSLT) ;
  227. }
  228. #pragma endregion



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

已领礼包: 3个

财富等级: 恭喜发财

发表于 2022-9-20 22:21:59 | 显示全部楼层
版主大大太厉害了,谢谢
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-4-26 18:35 , Processed in 0.350995 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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