找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 182|回复: 0

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

[复制链接]

0

主题

0

回帖

26

积分

管理员

积分
26
发表于 2024-2-26 09:27:42 | 显示全部楼层 |阅读模式
  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
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2024-12-28 13:47 , Processed in 0.116551 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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