Code: Select all
; Thanks TI-994A very much!
; This code is nice in pb5.43,bad in pb5.51,code:
Procedure makeInvisible(win)
SetWindowColor(win, $6f6f6f)
win=WindowID(win)
SetWindowLongPtr_(win, #GWL_EXSTYLE,GetWindowLongPtr_(win, #GWL_EXSTYLE) | #WS_EX_LAYERED)
SetLayeredWindowAttributes_(win, $6f6f6f, 0, #LWA_COLORKEY)
EndProcedure
Procedure lineG(Image,Gadget,x1,y1,x2,y2,lineWidth)
xx=Abs(x1-x2):yy=Abs(y1-y2):zz.f=Sqr(xx*xx+yy*yy)
z_.f=lineWidth/zz:zy.f=z_*yy:zx.f=z_*xx:zy2.f=zy/2:zx2.f=zx/2
Width=xx+zy:Height=yy+zx
If CreateImage(Image,Width,Height,32,$ffffffff) And
StartVectorDrawing(ImageVectorOutput(Image))
x_=zy2:x1_=Width-zy2:If (x1-x2)*(y1-y2)>-1
;[(x1-x2)*(y1-y2)>-1] == [(x1<x2 And y1<y2) Or (x1>=x2 And y1>=y2)]
y_=zx2:y1_=Height-zx2:Else:y_=Height-zx2:y1_=zx2:EndIf
MovePathCursor(x_,y_):AddPathLine(x1_,y1_,#PB_Path_Default)
VectorSourceColor($ff0000ff):StrokePath(lineWidth)
StopVectorDrawing():EndIf
If x1>x2:a=x2:Else:a=x1:EndIf:If y1>y2:b=y2:Else:b=y1:EndIf
ImageGadget(Gadget,a-zy2,b-zx2,Width,Height,ImageID(Image))
EndProcedure
win0=OpenWindow(0, 0, 0, 550, 550, "Move/drag Image", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered)
TextGadget(99,20,50,400,25,"DragDrop Gadget 1(line) or 2(Point) or 3(Point)")
TitleBarHeight=GetSystemMetrics_(#SM_CYCAPTION)
rex=WindowX(0):rey=WindowY(0)+TitleBarHeight
wFlags = #PB_Window_BorderLess
win1=OpenWindow(1, rex, rey, 550, 550, "", wFlags,WindowID(0))
gx0=128:gy0=28:gx_=28:gy_=28:lineWidth=10
lineG(0,1,gx0,gy0,gx_,gy_,lineWidth)
win2=OpenWindow(2, rex, rey, 550, 550, "", wFlags,WindowID(0))
If CreateImage(1,16,16,32,$ffffffff)
If StartVectorDrawing(ImageVectorOutput(1))
AddPathCircle(8, 8,8)
VectorSourceColor(RGBA(0, 0, 0, 255))
FillPath()
StopVectorDrawing()
EndIf
ImageGadget(2, 20, 20,16,16,ImageID(1))
ImageGadget(3,120,20,16,16,ImageID(1))
ImageGadget(4,80,20,16,16,ImageID(1)):EndIf
DisableGadget(4,1)
makeInvisible(1)
makeInvisible(2)
;SetWindowPos_(WindowID(1),#HWND_BOTTOM,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
;SetWindowPos_(WindowID(2),#HWND_TOPMOST,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
StickyWindow(2,1)
;*****************************
;DragDrop Gadget 1(line) or 2(Point) or 3(Point)
;*****************************
Repeat:fw=GetForegroundWindow_():If fw=win0 Or fw=win1 Or fw=win2
SetWindowState(2,#PB_Window_Normal)
Else:SetWindowState(0,#PB_Window_Minimize):EndIf;for hide WindowID(2),#HWND_TOPMOST
Select WaitWindowEvent()
Case #PB_Event_Gadget
If GetAsyncKeyState_(#VK_LBUTTON):eg=EventGadget():EndIf
Case #WM_LBUTTONUP:jx=0:eg=-1
Case #WM_MOUSEMOVE
If eg>0:If jx=1
x01=WindowMouseX(1):y01=WindowMouseY(1)
If x00<>x01 Or y00<>y01
x00=x01:y00=y01:x=x01-x0:y=y01-y0
gx_=gx+x:gy_=gy+y:If eg>1:UseGadgetList( WindowID(1));SetActiveWindow(1)
lineG(0,1,gx0+8,gy0+8,gx_+8,gy_+8,lineWidth) ;Gosub lin
Else:ResizeGadget(1,gx1+x,gy1+y,#PB_Ignore,#PB_Ignore)
ResizeGadget(3,gx0+x,gy0+y,#PB_Ignore,#PB_Ignore):EndIf
If eg=1:ResizeGadget(2,gx+x,gy+y,#PB_Ignore,#PB_Ignore)
Else:ResizeGadget(eg,gx_,gy_,#PB_Ignore,#PB_Ignore):EndIf:EndIf
Else:jx=1:Gosub cs:EndIf:EndIf
Case #PB_Event_MoveWindow:If EventWindow()=0
rex=WindowX(0):rey=WindowY(0)+TitleBarHeight
ResizeWindow(1, rex, rey,#PB_Ignore,#PB_Ignore)
ResizeWindow(2, rex, rey,#PB_Ignore,#PB_Ignore):EndIf
Case #PB_Event_CloseWindow:appQuit = 1
EndSelect
Until appQuit = 1
End
cs: :x0=WindowMouseX(1):y0=WindowMouseY(1)
If eg=1:gx1=GadgetX(1):gy1=GadgetY(1)
gx=GadgetX(2):gy=GadgetY(2)
gx0=GadgetX(3):gy0=GadgetY(3)
Else:gx=GadgetX(eg):gy=GadgetY(eg)
gx0=GadgetX(5-eg):gy0=GadgetY(5-eg):EndIf
Return