Page 1 of 1
[SOLVE]How to use the fifth parameter in SetWindowCallback()
Posted: Mon Apr 26, 2010 3:30 am
by avatar
From the manual, it is allowed to optionally set the fifth window call back parameter "#Window"
SetWindowCallback(@ProcedureName() [, #Window])
How can I retrieve this information from the Call back function?
Code: Select all
Procedure WinCallback(hWnd, uMsg, wParam, lParam)
debug str(#Window) ; <----------------------------------- ERROR
If uMsg = #WM_SIZE
Select wParam
Case #SIZE_MINIMIZED
Debug "Window was minimized"
Case #SIZE_RESTORED
Debug "Window was restored"
Case #SIZE_MAXIMIZED
Debug "Window was maximized"
EndSelect
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
If OpenWindow(123, 0, 0, 200, 100, "Messages", #PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget)
SetWindowCallback(@WinCallback(),123) ; activate the callback
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
EndIf
Re: How to use the fifth parameter in SetWindowCallback()?
Posted: Mon Apr 26, 2010 4:32 am
by idle
you need to use the hwnd of the window number
Code: Select all
Procedure WinCallback(hWnd, uMsg, wParam, lParam)
Debug Str(hwnd) ; your window is the hwnd
If uMsg = #WM_SIZE
Select wParam
Case #SIZE_MINIMIZED
Debug "Window was minimized"
Case #SIZE_RESTORED
Debug "Window was restored"
Case #SIZE_MAXIMIZED
Debug "Window was maximized"
EndSelect
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
If OpenWindow(123, 0, 0, 200, 100, "Messages", #PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget)
hwnd = WindowID(123) ;get the hwnd for the window
Debug "Window handle=" + Str(hwnd)
SetWindowCallback(@WinCallback(),123) ; activate the callback for the window number 123
;it uses the windowID / hwnd for processing in the callback
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
EndIf
Re: How to use the fifth parameter in SetWindowCallback()?
Posted: Mon Apr 26, 2010 4:51 am
by avatar
Thank for the help
Re: How to use the fifth parameter in SetWindowCallback()?
Posted: Mon Apr 26, 2010 4:58 am
by netmaestro
There are a maximum of two parameters to the SetWindowCallback() function. The first is a code pointer, the address of a procedure that you designate to function as a Window Callback. The OS will call this procedure, passing it every message that is intended for the window. That procedure always has four parameters: handle, message, wparam and lparam. Handle is the hWnd, message is the Windows message, and WParam is a four-byte value often consisting of two WORD values, one high-order and one low-order. Hence the name wParam (word-parameter). LParam is usually one LONG value, hence the name lParam. The fact that Windows will often pass one LONG in wParam and two WORDs in lparam shouldn't serve to confuse you; that's just their schizophrenia talking. Probably brought about by all the caffeine in those free sodas at the MS compound. The optional second parameter in SetWindowCallback() is a window number, the one you specified when you created the window (or the one returned to you by #PB_Any if you went that route). You only pass this if you have several windows in your program, any of which may be active at any given time, and you want the callback only set up for a specific window. Ignoring the others, yes. But so what? Scr** them. What have those windows ever done for you?
Re: [SOLVE]How to use the fifth parameter in SetWindowCallba
Posted: Mon Apr 26, 2010 5:53 am
by avatar
Thanks netmeastro for the detailed explanation.
Yes, I want to have more than one window opened.
The window ID (in my example, 123) can be very helpful if I can identify it within the call back procedure.
When I pass the fifth parameter to the call back procedure, how can I retrieve it from within the call back procedure?
Re: [SOLVE]How to use the fifth parameter in SetWindowCallba
Posted: Mon Apr 26, 2010 5:57 am
by netmaestro
how can I retrieve it from within the call back procedure?
If hwnd = WindowID(<number>)
.. [ ]
EndIf
But if you passed the optional #window parameter, you can be sure that the only hwnd dealt with in the callback will be the one you passed. Messages for the others won't go to the callback.
Re: [SOLVE]How to use the fifth parameter in SetWindowCallba
Posted: Mon Apr 26, 2010 6:07 am
by avatar
Thanks Bullfrog
I am thinking similar method as yours