Le Soldat Inconnu wrote:First point :
I can't use CallBack because my code is a library (Build with TailBite)
Why there is a problem with callbacks ? I use it...
(e.g. a Canvasgadget with Callback to draw automatic hoover, selected etc.
to handle it like a normal PB ButtonGadget.)
Edit : I made a small example - "tailbited" with 1.49 and PB5.11x86 Windows
The Lib:
Code: Select all
EnableExplicit
;
#mUI_PROP_DEFCALLBACK = "mUI:DefCallBack"
;
Enumeration #PB_Event_FirstCustomValue
#mUI_Event_LButtonDown
#mUI_Event_MButtonDown
#mUI_Event_RButtonDown
#mUI_Event_LButtonUp
#mUI_Event_MButtonUp
#mUI_Event_RButtonUp
EndEnumeration
;
Structure mUI_callbackdata_struct
Window.i
OldProc.i
ExtraData.i
EndStructure
;
ProcedureDLL mUI_TestLibrary_Init()
;Ressources
EndProcedure
ProcedureDLL mUI_TestLibrary_End()
;FreeRessources
EndProcedure
; private
Procedure private_mUI_WindowCallBack(hWnd, uMsg, wParam, lParam)
Protected OldProc
Protected *p.mUI_callbackdata_struct
*p = GetProp_(hWnd, #mUI_PROP_DEFCALLBACK)
If Not *p : ProcedureReturn 0 : EndIf
OldProc = *p\OldProc
Select uMsg
Case #WM_NCDESTROY
RemoveProp_(hWnd, #mUI_PROP_DEFCALLBACK)
FreeMemory(*p)
Case #WM_LBUTTONDOWN
PostEvent(#mUI_Event_LButtonDown, *p\Window, 0)
Case #WM_MBUTTONDOWN
PostEvent(#mUI_Event_MButtonDown, *p\Window, 0)
Case #WM_RBUTTONDOWN
PostEvent(#mUI_Event_RButtonDown, *p\Window, 0)
Case #WM_LBUTTONUP
PostEvent(#mUI_Event_LButtonUp, *p\Window, 0)
Case #WM_MBUTTONUP
PostEvent(#mUI_Event_MButtonUp, *p\Window, 0)
Case #WM_RBUTTONUP
PostEvent(#mUI_Event_RButtonUp, *p\Window, 0)
EndSelect
If OldProc
ProcedureReturn CallWindowProc_(OldProc, hWnd, uMsg, wParam, lParam)
Else
ProcedureReturn 0
EndIf
EndProcedure
Procedure private_mUI_RegisterWindow(Window)
Protected *p.mUI_callbackdata_struct = AllocateMemory(SizeOf(mUI_callbackdata_struct))
If Not *p : ProcedureReturn #False : EndIf
InitializeStructure(*p, mUI_callbackdata_struct)
If IsWindow(Window)
*p\OldProc = SetWindowLongPtr_(WindowID(Window), #GWLP_WNDPROC, @private_mUI_WindowCallBack())
*p\Window = Window
*p\ExtraData = 0
SetProp_(WindowID(Window), #mUI_PROP_DEFCALLBACK, *p)
ProcedureReturn *p
EndIf
FreeMemory(*p)
ProcedureReturn #False
EndProcedure
Procedure private_mUI_OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title$, Flags = #PB_Window_SystemMenu, ParentID = 0)
Protected Result = #False
If IsWindow_(ParentID)
Result = OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title$, Flags, ParentID)
Else
Result = OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title$, Flags)
EndIf
If Window = #PB_Any : Window = Result : EndIf
If IsWindow(Window)
private_mUI_RegisterWindow(Window)
EndIf
ProcedureReturn Result
EndProcedure
; public
ProcedureDLL PmUI_OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title$)
ProcedureReturn private_mUI_OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title$, #PB_Window_SystemMenu, 0)
EndProcedure
ProcedureDLL PmUI_OpenWindow2(Window, x, y, InnerWidth, InnerHeight, Title$, Flags)
ProcedureReturn private_mUI_OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title$, Flags, 0)
EndProcedure
ProcedureDLL PmUI_OpenWindow3(Window, x, y, InnerWidth, InnerHeight, Title$, Flags, ParentID)
ProcedureReturn private_mUI_OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title$, Flags, ParentID)
EndProcedure
The Resident
Code: Select all
Enumeration #PB_Event_FirstCustomValue
#mUI_Event_LButtonDown
#mUI_Event_MButtonDown
#mUI_Event_RButtonDown
#mUI_Event_LButtonUp
#mUI_Event_MButtonUp
#mUI_Event_RButtonUp
EndEnumeration
;
Macro OpenWindow
PmUI_OpenWindow
EndMacro
the example
Code: Select all
OpenWindow(0,200,300,800,600,"TestWindow")
ButtonGadget(0,10,10,100,30, "It works")
Repeat
Event = WaitWindowEvent(25)
Select Event
Case #mUI_Event_LButtonDown
Debug "WM_LBUTTONDOWN"
Case #mUI_Event_LButtonUp
Debug "WM_LBUTTONUP"
Case #PB_Event_Gadget
If EventGadget() = 0
Debug "ButtonGadget"
EndIf
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit > 0
And with the macro in the residentfile, a user that use the lib, don't remark it...