明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1729|回复: 19

[函数] 常用交互式消息框MsgBox 和输入框EditBox

[复制链接]
发表于 2021-12-14 19:22 | 显示全部楼层 |阅读模式
本帖最后由 asen 于 2021-12-20 08:38 编辑

自己使用的两个通用函数, 现和大家分享.


MsgBox 消息框

EditBox 输入框


  1. ; 消息,按钮( OK,OKCancel,Yes,YesNo,YesNoCancel ),默认选中的按钮(Yes,No,Cancel),标题;
  2. (defun MsgBox(Msg Buttons DefBt Title / FP CANCEL DEFBT1 DEFBT2 DEFBT3 DEFBTC DEFBTN DEFBTY FL FP HEIGHT I I-J ID J NO STD WIDTH YES ~CANCEL ~NO ~YES )
  3.       (setq ~yes nil ~no nil ~cancel nil)
  4.     (cond ((wcmatch buttons "*OK*") (setq yes "OK"  ~yes "确定"))
  5.           ((wcmatch buttons "*Yes*") (setq yes "Yes" ~yes "是"))
  6.     )
  7.     (if (wcmatch  buttons "*No*") (setq no "No"  ~no "否"))
  8.     (if (wcmatch  buttons "*Cancel*") (setq cancel "Cancel" ~cancel "取消"))

  9.     (setq DefBtY "" DefBtN "" DefBtC "")
  10.       (cond ((= DefBt "Yes") (setq DefBtY "is_default=true;"))
  11.           ((= DefBt "No") (setq DefBtN "is_default=true;"))
  12.           ((= DefBt "Cancel") (setq DefBtC "is_default=true;"))
  13.     )
  14.       (setq Msg (strcat "\n" Msg "\n\n"))
  15.       ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16.     (setq i -1 height 0 width 0)
  17.       (while (setq i (vl-string-search "\n" Msg (1+ (setq j i))))
  18.         (if (> (setq i-j (- i j)) 50)  (setq height (+ height 1 (fix (/ i-j 50.0)))))
  19.         (setq width (max width (- i j))  height (1+ height))
  20.     )
  21.       ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22.       (setq fp (vl-filename-mktemp "~HGCAD.dcl"))
  23.       (if (not (setq fl (open fp "w")))(exit))
  24.        (write-line (strcat "MsgBox:dialog{label=" title "; :column{")  fl)
  25.       (write-line (strcat ":row{spacer_1;:text_part{key=\"msg\";width=" (itoa (min width 50)) ";height=" (itoa height) ";}}") fl)
  26.        (write-line ":row{spacer_1;" fl)
  27.        (if ~yes (write-line (strcat ":cancel_button{label=" ~yes ";key=\"yes\";width=10;" DefBtY "}") fl))
  28.        (if ~no (write-line (strcat ":cancel_button{label=" ~no  ";key=\"no\";width=10;" DefBtN "}") fl))
  29.        (if ~cancel (write-line (strcat ":cancel_button{label=" ~cancel ";key=\"cancel\";width=10;" DefBtC "}") fl) )
  30.        (write-line "spacer_1;}}}" fl)
  31.       (close fl)
  32.       
  33.     (setq std 0 id (load_dialog fp))
  34.     (new_dialog "MsgBox" id)
  35.     (set_tile "msg" msg)  
  36.     (if ~yes (action_tile "yes" "(done_dialog 1)"))
  37.     (if ~no  (action_tile "no" "(done_dialog 2)"))
  38.     (if ~cancel (action_tile "cancel" "(done_dialog 3)"))
  39.     (setq std (start_dialog))
  40.     (unload_dialog id)
  41.     (vl-file-delete fp)


  42.       (cond ((= std 1) yes)
  43.           ((= std 2) no)
  44.           ((= std 3) cancel)
  45.     )
  46.   
  47. )

  48. ; 消息,输入框默认值,标题  
  49. (defun EditBox(Msg Edit Title /  FL FP ID RTEDIT STD )
  50.       ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  51.       (setq Msg (strcat " " Msg " "))
  52.       (setq fp (vl-filename-mktemp "~HGCAD.dcl"))
  53.       (if (not (setq fl (open fp "w")))(exit))
  54.        (write-line (strcat "EditBox:dialog{label=" title "; initial_focus = \"edit\";:column{")  fl)
  55.       (write-line (strcat "spacer_1;:text_part{key=\"msg\";width=" (itoa (strlen msg)) ";}") fl)
  56.       (write-line ":edit_box {key=\"edit\";}" fl)
  57.        (write-line ":row{spacer_1;}" fl)
  58.        (write-line ":row{spacer_1;" fl)
  59.        (write-line ":cancel_button{label=\"确定\";key=\"OK\";width=8;is_default=true;}" fl)
  60.        (write-line "spacer_1; :cancel_button{label=\"取消\";key=\"cancel\";width=8;}" fl)
  61.        (write-line "spacer_1;}}}" fl)
  62.       (close fl)
  63.       
  64.     (setq std 0 id (load_dialog fp))
  65.     (new_dialog "EditBox" id)
  66.     (set_tile "msg" Msg)
  67.     (set_tile "edit" Edit)  
  68.     (action_tile "OK" "(setq Rtedit (get_tile \"edit\"))(done_dialog 1)")
  69.     (action_tile "cancel" "(done_dialog 2)")
  70.     (setq std (start_dialog))
  71.     (unload_dialog id)
  72.     (vl-file-delete fp)

  73.       (cond ((= std 1) Rtedit)
  74.           ((= std 2) "")
  75.     )
  76. )

  77. (defun C:n ()

  78. (setq ret (MsgBox "是否继续操作?" "YesNo" "No" "提示"))

  79. (setq ret (EditBox "请输入数值" "123" "输入"))

  80. )




测试:

(setq ret (MsgBox "是否继续操作?" "YesNo" "No" "提示"))
(setq ret (EditBox "请输入数值" "123" "输入"))


本帖子中包含更多资源

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

x

评分

参与人数 5明经币 +5 收起 理由
yanshengjiang + 1 东西很好。没花钱买,评分送个币 哈哈
baitang36 + 1
tigcat + 1 很给力!
USER2128 + 1 赞一个!
bssurvey + 1 赞一个!

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2021-12-19 12:51 | 显示全部楼层
mokson 发表于 2021-12-16 08:17
需要安装 OpenDCL 库吗?

你都是论坛长老了还在问这个问题,你都学了些什么?
 楼主| 发表于 2021-12-15 21:41 | 显示全部楼层
xiongyuer 发表于 2021-12-15 21:41
editbox可以做多个输入box吗

可以, 你参考源码
发表于 2022-6-23 11:47 | 显示全部楼层
两个程序很适用,感谢分享。另外输入框能不能加入回车也可以确定呢?
发表于 2021-12-15 07:12 来自手机 | 显示全部楼层
建议加个point参数
发表于 2021-12-15 08:23 | 显示全部楼层
雾草好牛批哦
发表于 2021-12-15 09:10 来自手机 | 显示全部楼层
不错 一直想写 没写出来
发表于 2021-12-15 09:27 | 显示全部楼层
对 ET 有依赖
 楼主| 发表于 2021-12-15 21:36 | 显示全部楼层

没有依赖, vl
发表于 2021-12-15 21:41 | 显示全部楼层
editbox可以做多个输入box吗
发表于 2021-12-16 08:17 | 显示全部楼层
需要安装 OpenDCL 库吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-3 12:27 , Processed in 2.584126 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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