PDA

View Full Version : Callbacks for user defined controls & menuitems



ReneMiner
05-09-2020, 17:54
Many - not all- controls provide a syntax as


Control Add xxx,[...],Style,ExStyle, Call EventHandler


Where Eventhandler is the callback functions name that will handle events of that control.

Some- as ListView or Viewport offer already to assign a NAME to the controls so its simple and not necessary to append
"Call Eventhandler" explicitely because f.e."myListview_OnCallback" allows to handle the events in dedicated functions that only have to dimension local variables for the current CBCTL.

Sadly its not possible to filter the callback on a menuitem that it would allow to connect a function instantly on creation to handle
all events for that item and menu events are handled within the parenting dialog which leads to long "ladders" of


CallBack Function MainWndProc()

Local <a bunch of variables but only a few are needed to handle the current event>
Local <many of the variables are unused and only to be ready for another controls event>

Static <requires additional conditional clauses mostly because this>
Static <callback handles multiple events of different controls>

select case message
case messageX
select case object
case objectY
select case ...



Situation so far...

now questions:



...
Menu Add String hDlg, hMenu, "text", %IDM_myMenuItem, %MF_Enabled

-no controls name that will enable "_OnCallback" nor call-syntax to assign a function to it-

How can a apply a functions name to handle events for this menuitem only?
How to tell thinBasic to call a dedicated callback function for this menuitem?

José Roca
05-09-2020, 21:17
> How can a apply a functions name to handle events for this menuitem only?
> How to tell thinBasic to call a dedicated callback function for this menuitem?

You can't. A menu item is not a control. The only control is the menu, that manages an array of menu items, each of which is an structure holding relevant information, which does not include a pointer for a callback function.

ReneMiner
10-09-2020, 14:40
>
You can't.


okay that sounds better than that i was hoping for.
So actually it only a static aligned to top of window that has to be clicked (%WM_Command) and from then it manages it by itself to measure to which "imaginary item" the next click will go? So wow- i can completely design the menubar-control by myself as soon i trapped the message that tells me the very first click onto the menubar occured open/draw and focussing and even different controls from that what the menus usually would offer is completely up to me?

So i can draw it completely from scratch which allows even controls that are not designed yet?

Would it equire some flag for Style as %SS_OWNERDRAW or %SS_USERITEM to set and the callback of the static (myMenubar-control, a label na lang) will receive a message that says:
"Hey, you, wanna be a programmer? Then now direct me to how shall your user-defined control be drawn? I need instructions!"

What would the callback message be, that i have to wait for? %WM_Paint | %WM_USER? any other that is known to be used in cases like this?

What i see from thinbasic-help is no automated message that says OnPaint - the "Callback Function myMenubar.OnPaint()" would probably not get fired automatic -

Can gdi draw simply on top of the windows surface and cover (full or partially) existing controls or - as in some cases menu-dropdowns exceed the size of a window: were it a good idea to draw directly on the desktop ?