Lovesan / doors

MS Windows API from Common Lisp perspective
MIT License
32 stars 5 forks source link

Using doors i want to create an empty window. Is it possible? #5

Open huseyindenli opened 1 week ago

huseyindenli commented 1 week ago

but i get "Unsupported system" during intsllation.

Lovesan commented 6 days ago

@huseyindenli The build is fixed now. You can create a window like this:

(in-package #:cl-user)

(cffi:defcallback (wndproc :convention :stdcall)
    :pointer ((hwnd :pointer)
              (msg :uint)
              (wparam :pointer)
              (lparam :pointer))
  (cond ((= msg #x0002)                 ; WM_DESTROY
         (doors.ui:post-quit-message)
         (cffi:null-pointer))
        (t (cffi:foreign-funcall ("DefWindowProcW" :convention :stdcall
                                                   :library doors:user32)
                                 :pointer hwnd
                                 :uint msg
                                 :pointer wparam
                                 :pointer lparam
                                 :pointer))))

(defun show-window ()
  (let ((class (doors.ui:make-wndclass
                :style '(:vredraw :hredraw :dbl-clks)
                :wndproc (cffi:callback wndproc)
                :cursor (cffi:foreign-funcall ("LoadCursorW" :convention :stdcall
                                                             :library doors:user32)
                                              :pointer (cffi:null-pointer)
                                              :pointer (cffi:make-pointer #x7F00)
                                              :pointer)
                :background (1+ 5)
                :class-name "My class")))
    (doors.ui:register-class class)
    (unwind-protect
         (let ((wnd (doors.ui::create-window*
                     :style* :overlapped-window
                     :class-name "My class"
                     :window-name "Hello"
                     :style '(:overlapped-window :visible))))
           (doors.ui::show-window wnd :show)
           (loop :with msg = (doors.ui:make-msg)
                 :while (doors.ui:get-message msg)
                 :do (doors.ui:translate-message msg)
                     (doors.ui:dispatch-message msg)))
      (doors.ui:unregister-class "My class"))))

However, I haven't touched the lib for ages, and back then it was basically an experiment. You'd be better off with pure CFFI: https://gist.github.com/Lovesan/17007d7571486dd94b6c97588a545a7d

I'm planning to rewrite the library in the future, though