I've added the following code to my windows app:-
function mywin.WM_LBUTTONDOWN(wParam, lParam)
local x, y = splitsigned(lParam)
When I click the mouse, the value for x is correct, but the y value is always zero.
Mouse messages are already decoded, so just do:
function mywin:on_lbutton_down(x, y, buttons) ... end
The decoders are in mouse.lua and the mappings between WM_* names and handler names are in basewindowclass.lua (see __wm_handler_names).
Bit of background:
winapi is made of two layers: a procedural layer which mimics the Windows API itself and an OOP layer (
*class.lua). All the API/ABI cruft is removed in the procedural layer (this includes message decoding -- the winapi.WM table contains all the decoders), but the actual routing of messages to their destination window and decoding them at runtime is done in the OOP layer in basewindowclass.lua.
Basically all WNDPROCs of all windows are set to point to a single callback in MessageRouter. Through a mapping of HWND->Window-object the destination window of the message is found and the window's __handle_message() method is called. The window then does the decoding and dispatching of messages like this:
function BaseWindow:__handle_message(WM, wParam, lParam) --look for a low-level handler self:WM_*() local handler = self[WM_NAMES[WM]] if handler then local ret = handler(self, DecodeMessage(WM, wParam, lParam)) if ret ~= nil then return ret end end --look for a hi-level handler self:on_*() local handler = self[self.__wm_handler_names[WM]] if handler then local ret = handler(self, DecodeMessage(WM, wParam, lParam)) if ret ~= nil then return ret end end return self:__default_proc(WM, wParam, lParam) end
DecodeMessagelooks for a decoder in the WM table (in your case the decoder for
__wm_handler_nameslooks for a friendly handler name so that you can bind to
on_lbutton_downinstead of to
WM_LBUTTONDOWN(either one works).
I swear I'm going to add proper docs for all of this someday :)
Documenting winapi will be a huge task; I don't blame you for putting it off :)
Check this out:
It's not much but it's a start. Let me know if you find it useful (or not).
It's a great start!
The usage examples are particularly useful ( for instance the one for windowclass ) as they point me in the right direction and help enormously in making sense of the detailed documentation.
FYI - The links in your last post don't work for me. They take me to a "NOT FOUND" page. For some reason they take me to:-
Great. I'll put in more hours into this then.
I know about the links, it's a bug in nodebb (the forum platform), I'll fix it ASAP.