5.30 SendMessageCallback don't work

Just starting out? Need help? Post your questions and find answers here.
bizdon
User
User
Posts: 12
Joined: Wed Jun 22, 2011 6:49 pm

5.30 SendMessageCallback don't work

Post by bizdon »

code:

Code: Select all

Procedure WndProc(hWnd,msg,wParam,lparam) 
If hWnd = WindowID(0) 
    Select msg 
      Case #WM_LBUTTONDOWN
        ReleaseCapture_()
        SendMessage_(hWnd,#WM_SYSCOMMAND,#SC_MOVE|#HTCAPTION,0)
      Case #WM_COMMAND
               If wParam= 1+#PB_EventType_LeftClick<<16
           SendMessageCallback_(hWnd,#PB_Event_CloseWindow,0,0,@WndProc(),0)
               EndIf
          EndSelect 
  EndIf 
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure 
OpenWindow(0,0,0,300,300,"qwe",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget(1,220,260,55,25,"exit")
SetWindowCallback(@WndProc()) 
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

when I click the button "exit" the program is not completed. In v5.20 and earlier versions, everything worked. Why?
Thank you!
Last edited by bizdon on Wed Aug 06, 2014 10:58 am, edited 2 times in total.
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: 5.30 SendMessageCallback don't work

Post by Fred »

I don't know what you want to do, but you should use PostEvent() if you want to send a PB event to the queue.
bizdon
User
User
Posts: 12
Joined: Wed Jun 22, 2011 6:49 pm

Re: 5.30 SendMessageCallback don't work

Post by bizdon »

Yes, it works: PostEvent(#PB_Event_CloseWindow)
But only in v5.30! In v5.20 and earlier versions don't work.
Maybe I misused the function SendMessageCallback...
It is necessary to use PostMessage_(hWnd,#PB_Event_CloseWindow,0,0) - it works in all versions
The purpose of this reception is working with functions PB and easy access to the message queue window
bizdon
User
User
Posts: 12
Joined: Wed Jun 22, 2011 6:49 pm

Re: 5.30 SendMessageCallback don't work

Post by bizdon »

Sorry for my English.

Code: Select all

Procedure WndProc(hWnd,msg,wParam,lparam)
If hWnd = WindowID(0)
    Select msg
      Case #WM_LBUTTONDOWN
        ReleaseCapture_()
        SendMessage_(hWnd,#WM_SYSCOMMAND,#SC_MOVE|#HTCAPTION,0)
      Case #WM_COMMAND
               If wParam= 1+#PB_EventType_LeftClick<<16
; PostMessage_(WindowID(0),#PB_Event_CloseWindow,0,0)   ;WORKS!
; SendMessage_(WindowID(0),#PB_Event_CloseWindow,0,0)    ;DOES Not WORK!
; SendMessageCallback_(WindowID(0),#PB_Event_CloseWindow,0,0,@WndProc(),0)   ;DOES Not WORK!
; SendNotifyMessage_(WindowID(0),#PB_Event_CloseWindow,0,0)   ;DOES Not WORK!
               EndIf
          EndSelect
  EndIf
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
OpenWindow(0,0,0,300,300,"qwe",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget(1,220,260,55,25,"exit")
SetWindowCallback(@WndProc())
Repeat:
    Event=WaitWindowEvent()
    gadget=EventGadget()
    If Event=#PB_Event_Gadget And gadget=1
PostMessage_(WindowID(0),#PB_Event_CloseWindow,0,0)  ;WORKS!
; SendMessage_(WindowID(0),#PB_Event_CloseWindow,0,0)   ;DOES Not WORK!
; SendMessageCallback_(WindowID(0),#PB_Event_CloseWindow,0,0,@WndProc(),0)   ;;DOES Not WORK!
; SendNotifyMessage_(WindowID(0),#PB_Event_CloseWindow,0,0)              ;;DOES Not WORK!
      EndIf   
Until  Event=#PB_Event_CloseWindow
I think in at v5.30/5.22 don't work asynchronous messages in the queue. In v5.20 and earlier versions everything is fine.
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: 5.30 SendMessageCallback don't work

Post by Fred »

Once again, you should not assume than using an API to send private PB message will always work or be future proof. If you need such, the only reliable way is to use PostEvent().
User avatar
Bisonte
Addict
Addict
Posts: 1320
Joined: Tue Oct 09, 2007 2:15 am

Re: 5.30 SendMessageCallback don't work

Post by Bisonte »

Fred means :
If you use API functions, you have to use API - Events !!! (in your case above #WM_CLOSE)
If you use PB Events, you have to use PostEvent()
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
bizdon
User
User
Posts: 12
Joined: Wed Jun 22, 2011 6:49 pm

Re: 5.30 SendMessageCallback don't work

Post by bizdon »

Bisonte
Thank you! Actually, everything is simple. But these changes occurred from version 5.20. In the certificate is not written. I did not realize it himself.
Post Reply