Author Topic: Create a message box  (Read 15670 times)

0 Members and 1 Guest are viewing this topic.

Chris

  • Swamp Rat
  • Posts: 547
Create a message box
« on: July 17, 2009, 04:35:01 PM »
2010 no longer comes with vba, I have a message box that I have been using for sometime that I got somewhere from someone.  Because vba is no longer with AutoCAD (and I dont want to deal with the hastle of downloading the addon for everyone) I need to rewrite the messagebox so I can use it without any vba code.  Possibly a dcl or something.  any suggestions are appreciated.
Code: [Select]
(defun dwpMsgBox (Title   Message     MsgBoxType  Icon
      /   iicon       imsgboxtype oldvar
      result   strmessage  strtitle
     )
      (vl-load-com)
      (setq oldvar (getvar "USERI1"))
      (setvar "USERI1" 0)
      (setq strTitle title
    strMessage
     Message
    iIcon Icon
    iMsgBoxType
     MsgBoxType
      ) ;_ end of setq
      (vla-eval acadobject
(strcat "ThisDrawing.SetVariable \"USERI1\", "
"MsgBox \(\""
strMessage
"\","
(itoa (+ iIcon iMsgBoxType))
",\""
strTitle
"\"\)"
) ;_ end of strcat
      ) ;_ end of vla-eval
      (setq result (GETVAR "USERI1"))
      (SETVAR "USERI1" oldvar)
      result
    ) ;_ end of defun
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Create a message box
« Reply #1 on: July 17, 2009, 04:55:14 PM »
Hi,

Does this work ?

EDIT: added (vl-load-com) and corrected `Bbuttons' to `buttons'

Code: [Select]
;;; MsgBox (Patrick_35)
;;;
;;; Val buttons
;;; 0   vlax-vbOKOnly
;;; 1   vlax-vbOKCancel
;;; 2   vlax-vbAbortRetryIgnore
;;; 3   vlax-vbYesNoCancel
;;; 4   vlax-vbYesNo
;;; 5   vlax-vbRetryCancel
;;; 16  vlax-vbKatakana
;;; 32  vlax-vbQuestion
;;; 48  vlax-vbExclamation
;;; 64  vlax-vbInformation
;;;
;;; Val return
;;; 1   OK
;;; 2   Cancel
;;; 3   Abort
;;; 4   Retry
;;; 5   Ignor
;;; 6   Yes
;;; 7   No

(defun MsgBox (title buttons message time / return WshShell)
  (setq WshShell (vlax-create-object "WScript.Shell"))
  (setq return (vlax-invoke
  WshShell
  'Popup
  message
  time
  title
  (itoa buttons)
)
  )
  (vlax-release-object WshShell)
  return
)
« Last Edit: July 20, 2009, 01:34:43 PM by gile »
Speaking English as a French Frog

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Create a message box
« Reply #2 on: July 17, 2009, 05:11:09 PM »
May need to add this:
Code: [Select]
(vl-load-com)
What are valid entries for [time]
« Last Edit: July 17, 2009, 05:20:07 PM by CAB »
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Create a message box
« Reply #3 on: July 17, 2009, 05:20:41 PM »
So the original MsgBox routine will not work in 2010? $%*&
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Create a message box
« Reply #4 on: July 17, 2009, 05:32:05 PM »
How about this One for 2010?

Code: [Select]
;;--------------------------------------------------------
;; MsgBox(prompt[, buttons][, title][, helpfile, context])
;; Buttons:
;; vbOKOnly    0 Display OK button only.
;; vbOKCancel    1 Display OK and Cancel buttons.
;; vbAbortRetryIgnore    2 Display Abort, Retry, and Ignore buttons.
;; vbYesNoCancel    3 Display Yes, No, and Cancel buttons.
;; vbYesNo    4 Display Yes and No buttons.
;; vbRetryCancel    5 Display Retry and Cancel buttons.
;; vbCritical   16 Display Critical Message icon.
;; vbQuestion   32 Display Warning Query icon.
;; vbExclamation   48 Display Warning Message icon.
;; vbInformation   64 Display Information Message icon.
;; vbDefaultButton1    0 First button is default.
;; vbDefaultButton2  256 Second button is default.
;; vbDefaultButton3  512 Third button is default.
;; vbDefaultButton4  768 Fourth button is default.
;; vbApplicationModal    0 Application modal; the user must respond to the
;; message box before continuing work in the current application.
;; vbSystemModal 4096 System modal; all applications are suspended until the
;; user responds to the message box.

;; Revised (01-27-03) thanks to Ed Jobe's contribution about snagging the return value.

(defun MsgBox (Title Buttons Message / useri1 value)
  (vl-load-com)
  (or *acad* (setq *acad* (vlax-get-acad-object)))
  (setq useri1 (getvar "useri1"))
  (acad-push-dbmod)
  (vla-eval
    *acad*
    (strcat
      "ThisDrawing.SetVariable \"USERI1\","
      "MsgBox (\""
      Message
      "\","
      (itoa Buttons)
      ",\""
      Title
      "\")"
    )
  )
  (setq value (getvar "useri1"))
  (setvar "useri1" useri1)
  (acad-pop-dbmod)
  value
)
;; (MsgBox "Title" 4 "Message")
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Create a message box
« Reply #5 on: July 17, 2009, 05:41:12 PM »
What about using:
 http://www.en.na.mcneel.com/doslib.htm

Code: [Select]
(defun ARCH:QUESTION  (LN1 LN2 LN3 LN4 / txmsg buttons)
  (setq LN0 "Confirmation to Proceed :\n\n")
  (setq txmsg (strcat LN0 LN1 LN2 LN3 LN4))
  (setq buttons (list "Yes" "No"))
  (dos_msgboxex
    txmsg
    ;;" Arch : Program    Question ?"
    (strcat " Arch Program" " : Question ?")
    buttons
    4))
;;;(ARCH:QUESTION "First Line\n" "Second Line\n" "Third Line\n" "Fourth Line\n")
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Create a message box
« Reply #6 on: July 17, 2009, 05:52:01 PM »
Quote
What are valid entries for [time]

time have to be a number (integer or real), if it's greater than 0, the box automaticaly closes after about 1+ time seconds. If it's set to 0 the box won't close while the user closes it by clicking a button.

Another way should be the attached DLL.
Four LISP functions are defined whith .NET:
gc-getfiledlg (gc-getfiledlg title directory filter [multiple])
Returns a list of full pathe(s) it allows a multiple files selection if 'multiple' is specified and not nil)
ex: (getfiles "Select files" "C:\\" "Drawing (*.dwg)|*.dwg|All (*.*)|*.*" T)

gc-getfolderdlg (gc-getfolderdlg message [new])
Returns the full path of the selected (or created) folder
ex: (getfolder "Choose or create a folder" T)

gc-inputbox (gc-inputbox title message [default])
Returns a string (user input)
ex: (inputbox "Qizz" "Question 1 :\nHow old is the Captain ?" "58")

gc-messagebox (gc-messagebox title message [button [icon]])
Returns an integer (see integer codes above), if specified, button and icon requires an integer as above.
ex: (gc-messagebox "Alert" "The file yet exists\nDo you want to replace it ?" 4 48)

The ZIP file countains the DLL and source codes.
Error messages displayed on command line are in French :evil:

« Last Edit: July 19, 2009, 01:17:45 PM by gile »
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Create a message box
« Reply #7 on: July 19, 2009, 12:27:53 PM »
Here's a (poor) english translated version.
« Last Edit: July 19, 2009, 03:33:12 PM by gile »
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Create a message box
« Reply #8 on: July 20, 2009, 01:39:34 PM »
Chris, or someone else, can you say if the routine posted in reply 2 (using WshShell activeX) works on  AutoCAD 2010 without the VBA module, please ?
Speaking English as a French Frog

Chris

  • Swamp Rat
  • Posts: 547
Re: Create a message box
« Reply #9 on: July 20, 2009, 04:48:29 PM »
Chris, or someone else, can you say if the routine posted in reply 2 (using WshShell activeX) works on  AutoCAD 2010 without the VBA module, please ?
Reply 2 works great, just had to get the formatting correct
« Last Edit: July 20, 2009, 04:52:03 PM by Chris »
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

GDF

  • Water Moccasin
  • Posts: 2081
Re: Create a message box
« Reply #10 on: July 22, 2009, 02:45:32 PM »
Chris, or someone else, can you say if the routine posted in reply 2 (using WshShell activeX) works on  AutoCAD 2010 without the VBA module, please ?
Reply 2 works great, just had to get the formatting correct

I get an error with the following (what am I doing wrong?):

(MsgBox "Title" 2 "Message Here" 2)
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Create a message box
« Reply #11 on: July 22, 2009, 02:47:47 PM »
Chris, or someone else, can you say if the routine posted in reply 2 (using WshShell activeX) works on  AutoCAD 2010 without the VBA module, please ?
Reply 2 works great, just had to get the formatting correct

I get an error with the following (what am I doing wrong?):

(MsgBox "Title" 2 "Message Here" 2)
I forgot to modify Bbuttons. works now. Thanks for sharing it.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Create a message box
« Reply #12 on: July 23, 2009, 12:09:47 AM »
My DCL solution. Needs testing. 8-)

[Old Code Removed, see later post]
« Last Edit: July 23, 2009, 11:42:16 AM by CAB »
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

taner

  • Guest
Re: Create a message box
« Reply #13 on: July 23, 2009, 01:57:53 AM »
牛人啊!佩服!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Create a message box
« Reply #14 on: July 23, 2009, 08:42:16 AM »
Thanks Tanner, I hope to improve it some.
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.