Setcapture_() changed? - With example

Just starting out? Need help? Post your questions and find answers here.
eriansa
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Mar 17, 2004 12:31 am
Contact:

Setcapture_() changed? - With example

Post by eriansa »

In the readme.html there is following :

"Mouse is automatically released in windowed mode when the window loose focus"

Could this explain why setcapture_() api isn't working anymore?

In a MDI app. with more than 1 child, the eventwindow() returns different windowID's when there a setcapture_() active on 1 of the child windows.

Does this make sense?

Click On the black rectangle (ImageGadget) and move the mouse.
Once the capture is released and you move over the gadget, I get an event =14002 in PB4, while this event is not reported in PB3...


Code: Select all

Enumeration
  #win0
  #win1
  #win2
EndEnumeration
#Version=3
CompilerIf #Version=3
  OpenWindow(#win0,0,0,600,400,#PB_Window_SystemMenu,"Main")
  OpenWindow(#win1,0,50,250,150,#PB_Window_BorderLess,"CH-1");,WindowID(#win0))
  ;SetWindowColor(#win1,RGB(255,0,0))
  OpenWindow(#win2,300,50,250,150,#PB_Window_BorderLess,"CH-2");,WindowID(#win0))
  ;SetWindowColor(#win2,RGB(0,0,255))
CompilerEndIf
CompilerIf #Version=4
  OpenWindow(#win0,0,0,600,400,"Main",#PB_Window_SystemMenu)
  OpenWindow(#win1,0,50,250,150,"CH-1",#PB_Window_BorderLess);,WindowID(#win0))
  SetWindowColor(#win1,RGB(255,0,0))
  OpenWindow(#win2,300,50,250,150,"CH-2",#PB_Window_BorderLess);,WindowID(#win0))
  SetWindowColor(#win2,RGB(0,0,255))
CompilerEndIf

CreateImage(0,30,20)
CreateGadgetList(WindowID(#win1))
CompilerIf #Version=3
  ImageGadget(0,110,65,30,20,UseImage(0))
CompilerElse
  ImageGadget(0,110,65,30,20,ImageID(0))
CompilerEndIf
Repeat
  Ev=WaitWindowEvent()
  CompilerIf #Version=3
    hWin=EventWindowID()
  CompilerElse
    hWin=EventWindow()
  CompilerEndIf
 
  Select Ev 
    Case #PB_Event_Gadget
      SetCapture_(WindowID(#win1))
      showcursor_(#False) 
      outputdebugstring_("OnGadget : " + Str(EventType()))
    Case #WM_LBUTTONDOWN ;ButtonClick On Window
    Case #WM_LBUTTONUP ;ButtonClick On Window
      If hWin=#win1
        ReleaseCapture_()
        showcursor_(#True)
      EndIf
    Case  #WM_MOUSEMOVE
      ;outputdebugstring_("MouseMove over : " + Str(hWin))
  EndSelect
Until Ev=#PB_Event_CloseWindow
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

This is not a bug. The event 14002 is part of a few changes made to support
Drag & Drop in the future. It indicates that the user wants to drag that image.
(ie, a button press and the mouse started moving)

Just put your SetCapture_() after this event instead of the click event and it should be just fine.
quidquid Latine dictum sit altum videtur
Post Reply