대문 최근에 바뀐 글 새소식 찾기 하우투 문제 제안

WThirtyTwoMsgBox

최근 편집

요약: Material from ElispCookbook

변경됨:

< === What? ===
< When the error- or message-functions in emacs on w32 is not enough for you.
< === The code ===
< http://groups.google.com/groups?q=w32-msgbox

(으)로

> === Multi-line message box ===
> (defun multiline-message-box (msg)
> "display a multiline message box on Windows.
> According to bug #11138, when passing a message with newlines to
> `message-box' on Windows, the rendered message-box appears all on
> one line.
> This function can work around that problem.
> "
> (flet ((ok (&optional p1 &rest args) t))
> (let ((parts (split-string msg "\n"))
> (menu-1 (make-sparse-keymap "Attention"))
> c)
> (define-key menu-1 [menu-1-ok-event]
> `(menu-item ,(purecopy "OK")
> ok
> :keys ""))
> (define-key menu-1 [separator-1] menu-bar-separator)
> ;; add lines in reverse order
> (setq c (length parts))
> (while (> c 0)
> (setq c (1- c))
> (define-key menu-1 (vector (intern (format "menu-1-fake-event-%d" c)))
> `(menu-item ,(purecopy (nth c parts))
> nil
> :keys ""
> :enable t)))
> (x-popup-menu t menu-1))))
> === Messagebox via Powershell ===
> The built-in message-box fn on Windows is [http://thread.gmane.org/gmane.emacs.bugs/58385/focus=58393 sort of broken], and it's also
> not particularly beautiful or functional either. This fn allows you to
> pop a message box using Powershell, which is builtin to all Windows.
> (defun msgbox-via-powershell (format-string &rest args)
> "display a message box via powershell and Windows Forms.
> "
> (flet ((rris (a1 a2 s) (replace-regexp-in-string a1 a2 s)))
> (let ((msg (format format-string args)))
> (let ((powershell-exe (concat
> (getenv "windir")
> "\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"))
> (ps-cmd
> (concat "[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');"
> "[Windows.Forms.MessageBox]::Show("
> (mapconcat '(lambda (elt)
> (rris (char-to-string 34)
> (char-to-string 39)
> (pp-to-string
> (rris (char-to-string 34)
> "'+[char]0x0022+'"
> (rris (char-to-string 39)
> "'+[char]0x0027+'"
> elt)
> ))))
> (split-string msg "\n" nil)
> "+[char]0x000D+")
> ",'Message from Emacs',"
> "[Windows.Forms.MessageBoxButtons]::OK,"
> "[Windows.Forms.MessageBoxIcon]::Information)"))
> shell-command)
> (setq shell-command
> (format "%s -Command %s"
> powershell-exe
> (concat "\"& {" ps-cmd "}\"")))
> (shell-command-on-region (point) (point)
> shell-command
> nil nil nil)))))
> == W32-MSGBOX ==
> For when
the error- or message-functions in emacs on w32 is not enough for you.
> * http://groups.google.com/groups?q=w32-msgbox

삭제됨:

< === Prerequisites ===

삭제됨:

< === Test it ===


Multi-line message box

    (defun multiline-message-box (msg)
      "display a multiline message box on Windows.
        According to bug #11138, when passing a message with newlines to
        `message-box' on Windows, the rendered message-box appears all on
        one line.
        This function can work around that problem.
        "
      (flet ((ok (&optional p1 &rest args) t))
        (let ((parts (split-string msg "\n"))
              (menu-1 (make-sparse-keymap "Attention"))
              c)
          (define-key menu-1 [menu-1-ok-event]
            `(menu-item ,(purecopy "OK")
                        ok
                        :keys ""))
          (define-key menu-1 [separator-1] menu-bar-separator)
          ;; add lines in reverse order
          (setq c (length parts))
          (while (> c 0)
            (setq c (1- c))
            (define-key menu-1 (vector (intern (format "menu-1-fake-event-%d" c)))
              `(menu-item ,(purecopy (nth c parts))
                          nil
                          :keys ""
                          :enable t)))
          (x-popup-menu t menu-1))))

Messagebox via Powershell

The built-in message-box fn on Windows is sort of broken, and it’s also not particularly beautiful or functional either. This fn allows you to pop a message box using Powershell, which is builtin to all Windows.

    (defun msgbox-via-powershell (format-string &rest args)
      "display a message box via powershell and Windows Forms.
    "
      (flet ((rris (a1 a2 s) (replace-regexp-in-string a1 a2 s)))
        (let ((msg (format format-string args)))
          (let ((powershell-exe  (concat
                                  (getenv "windir")
                                  "\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"))
                (ps-cmd
                 (concat "[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');"
                         "[Windows.Forms.MessageBox]::Show("
                         (mapconcat '(lambda (elt)
                                       (rris (char-to-string 34)
                                             (char-to-string 39)
                                             (pp-to-string
                                              (rris (char-to-string 34)
                                                    "'+[char]0x0022+'"
                                                    (rris (char-to-string 39)
                                                          "'+[char]0x0027+'"
                                                          elt)
                                                    ))))
                                    (split-string msg "\n" nil)
                                    "+[char]0x000D+")
                         ",'Message from Emacs',"
                         "[Windows.Forms.MessageBoxButtons]::OK,"
                         "[Windows.Forms.MessageBoxIcon]::Information)"))
                shell-command)
            (setq shell-command
                  (format "%s -Command %s"
                          powershell-exe
                          (concat "\"& {" ps-cmd "}\"")))
            (shell-command-on-region (point) (point)
                                     shell-command
                                     nil nil nil)))))

W32-MSGBOX

For when the error- or message-functions in emacs on w32 is not enough for you.

The latest version is 0.3 and was posted 2004-02-24, around 170.00 CET.

Test it with:

 M-: (w32-msgbox "Message" "Title" 'vb-yes-no-cancel 'vb-question 'vb-default-button-2 t)

CategoryWThirtyTwo