[Pharo-dev] How to listen for windows messages?
phil at highoctane.be
phil at highoctane.be
Tue Feb 28 07:29:53 EST 2017
Pharo is itself a Windows application (under Windows of course).
So Window event loop is picking up the events and transforming them into
You can check this in https://github.com/pharo-project/pharo-vm
LRESULT CALLBACK MainWndProcW(HWND hwnd,
You'll see that we stick a lot of stuff into evt->... in various ways.
There is a default fallback at the end.
/* Unprocessed messages may be processed outside the current
module. If firstMessageHook is non-NULL and returns a non
zero value, the message has been successfully processed */
if((*firstMessageHook)(hwnd, message, wParam, lParam))
So, if firstMessageHook exists, one can do whatever.
Now, a Windows manager may need other stuff and so on.
What you are looking at is how to hook this VM side with more of the
general Windows system.
These hooks are globals, so should be accessible.
/* Message Processing */
/* The last dispatched event. It is used for the event processing
MSG *lastMessage = NULL;
/* The entry to the message hooks called from the window procedure.
If another module requires to process messages by itself, it should
put its message procedure in this place. */
messageHook firstMessageHook = 0;
/* The entry to a pre-message hook. Can be used to intercept any messages
to the squeak main window. Useful for modules that wish to be notified
about certain messages before they are processed. */
messageHook preMessageHook = 0;
Never played with these but any Windows integration is of interest to me.
So, go ahead. Nothing would resist focused work.
Be aware that there is another VM underway with a cleanup of all of this
but this is not released yet.
Keep us posted.
On Tue, Feb 28, 2017 at 9:33 AM, Torsten Bergmann <astares at gmx.de> wrote:
> I guess what you want to achieve will not be an easy task for you if you
are new to programming.
> But it is always good to have a goal and if you have time to learn I'm
pretty sure you will master
> Even when OS-Windows inspire you for automizing tasks in other Windows
processes (like autoit) you
> should not start with my OS-Windows project directly as contributing to
it requires knowledge
> on your side on Smalltalk as well as Win32 C programming.
> First start with learning Smalltalk and Pharo
> - http://files.pharo.org/books/
> - http://pharo.pharocloud.com/pharobooks
> - http://stephane.ducasse.free.fr/FreeBooks.html
> After having an idea about Smalltalk and Pharo you should try to learn
> is Pharos unified foreign function interface and ability to call C DLL's.
> Sideways start learning about the Win32 API and C as this helps to better
> how things are done on the Windows side. There are many, many tutorials
> Try to call or wrap some simple DLL functions on you own first.
> There is a nice and tiny C compiler if you want to try out some C samples
> With this initial knowledge you can try to understand why and how
OS-Windows was done.
> I wrote many tests - just add a breakpoint and run them to debug through
the code to understand.
> Google for the API descriptions of the Win32 functions that are called to
get an understanding
> how Pharo and C get connected.
> Also check how you work with callbacks in UFFI (as this would be required
for a hook).
> If you are then still interested in interception windows messages you
should start reading here
> Primarily one has to wrap SetWindowsHookEx API function and friends and
wrap a good API
> for them in Pharo.
> Hope that helps to get started.
> > Gesendet: Dienstag, 28. Februar 2017 um 06:04 Uhr
> > Von: lw1990 <lukewallace1990 at gmail.com>
> > An: pharo-dev at lists.pharo.org
> > Betreff: [Pharo-dev] How to listen for windows messages?
> > In the OS-Windows package, there exists the ability to use the windows
> > Pharo.
> > This is very powerful, and I intend to add more of the windows api into
> > (it's only partially implemented).
> > This appears to all have been done with DllCalls (FFI calls) so far.
> > A big part of interacting with windows is listening to/intercepting and
> > responding to windows messages.
> > For example, every time a user presses a key on the keyboard, a windows
> > message will happen in the background for that key. If Pharo was aware
> > these messages, then Pharo could do things in response to hotkeys
> > Windows (outside of a pharo window).
> > It would also make reacting to events potentially nicer. Like making a
> > windows-desktop-manager in Pharo that can tell when a new window is
> > by windows (maybe they opened notepad). It would certainly be better
> > infinite loop or timer of 'get active window and compare to last active
> > window and see if it changed'. Instead it would be 'when receive the
> > WM_MESSAGE for new window created, notify Pharo so it can react'.
> > How can I set up a windows message hook in Pharo?
> > Please keep in mind I'm very new to programming, but I work from home
> > have lots of time to learn :-)
> > --
> > View this message in context:
> > Sent from the Pharo Smalltalk Developers mailing list archive at
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Pharo-dev