Lisp HUG Maillist Archive

FindWindow

I'm learning to use the FLI, but I can't get FindWindow to work:


HWND FindWindow(

    LPCTSTR lpClassName,
    LPCTSTR lpWindowName
);

FindWindow("Type32_Main_Window", NULL)

Does anyone have this working?  And then how do you call it since it 
requires a NULL argument?

Thanks in advance!

Bruce.


Re: FindWindow

Bruce,

On Nov 29, 2005, at 10:18 PM, Bruce J. Weimer, MD wrote:

> FindWindow("Type32_Main_Window", NULL)
>
> Does anyone have this working?  And then how do you call it since  
> it requires a NULL argument?

Here is my implementation.

Best,

John


John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL



=====

(fli:define-foreign-function (%find-window-ff "FindWindowW")
     ((class-lpstring :pointer)
      (name-lpstring :pointer))
   :result-type win32:hwnd)

; class or name can be nil
(defun %find-window (class &optional name)
   (cond ((and class name)
          (fli:with-foreign-string (class-ptr c-element-count c-byte- 
count
                                              :external- 
format :unicode) class
            (declare (ignore c-element-count c-byte-count))
          (fli:with-foreign-string (name-ptr n-element-count n-byte- 
count
                                              :external- 
format :unicode) name
            (declare (ignore n-element-count n-byte-count))
            (%find-window-ff class-ptr name-ptr))))
         (class
          (fli:with-foreign-string (class-ptr c-element-count c-byte- 
count
                                              :external- 
format :unicode) class
            (declare (ignore c-element-count c-byte-count))
            (%find-window-ff class-ptr nil)))
         (name
          (fli:with-foreign-string (name-ptr n-element-count n-byte- 
count
                                              :external- 
format :unicode) name
            (declare (ignore n-element-count n-byte-count))
            (%find-window-ff nil name-ptr)))
         (t (error "Class or name must be provided."))))


Re: FindWindow

Hello Bruce,

| I'm learning to use the FLI, but I can't get FindWindow to work:
| 
| 
| HWND FindWindow(
| 
|     LPCTSTR lpClassName,
|     LPCTSTR lpWindowName
| );
| 
| FindWindow("Type32_Main_Window", NULL)
| 
| Does anyone have this working?  And then how do you call it since it
| requires a NULL argument?

Please try something like this:

(fli:define-foreign-function (find-window "FindWindow" :dbcs)
  ((lpClassName (:reference-pass :ef-mb-string))
   (lpWindowName (:reference-pass :ef-mb-string :allow-null t)))
  :result-type win32:hwnd
  :calling-convention :stdcall
  :module "kernel32") ; not sure about module

Though, I would recommend the undocumented win32::find-window-ex as a
substitute of FindWidnow.
--
Sincerely,
Dmitriy Ivanov
lisp.ystok.ru


Updated at: 2020-12-10 08:49 UTC