Disable Drag and Drop in Webgadget

Just starting out? Need help? Post your questions and find answers here.
codeprof
User
User
Posts: 65
Joined: Sun Sep 16, 2012 12:13 pm

Disable Drag and Drop in Webgadget

Post by codeprof »

Hello,
with this code I can disable drop into the webgadget. However, I did not find a working solution to disable drag operations too.
Hope somebody here in the forums can help me.

Code: Select all

  If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
    WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com") 
    
    WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(0), #GWL_USERDATA) 
    WebObject\put_RegisterAsDropTarget(#VARIANT_FALSE)
    Repeat 
    Until WaitWindowEvent() = #PB_Event_CloseWindow 
  EndIf
Thanks for the help
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5014
Joined: Sun Apr 12, 2009 6:27 am

Re: Disable Drag and Drop in Webgadget

Post by RASHAD »

Code: Select all

  OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com")
   
    WebObject.IWebBrowser2 = GetWindowLongPtr_(GadgetID(0), #GWL_USERDATA)
    WebObject\put_RegisterAsDropTarget(#VARIANT_FALSE)
       
Repeat
  Select WaitWindowEvent()
      
       Case #PB_Event_CloseWindow
            Quit = 1
          
      Case #WM_MOUSEMOVE       
             If EventwParam() = 1 And GetCursor_() = LoadCursor_(0,#IDC_HAND)
                 ReleaseCapture_()
             EndIf
  EndSelect 

Until Quit = 1

Egypt my love
codeprof
User
User
Posts: 65
Joined: Sun Sep 16, 2012 12:13 pm

Re: Disable Drag and Drop in Webgadget

Post by codeprof »

Thanks.
Really clever solution. However here it is not working because an other cursor is used(this here).
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5014
Joined: Sun Apr 12, 2009 6:27 am

Re: Disable Drag and Drop in Webgadget

Post by RASHAD »

Code: Select all

  nCursor = LoadCursor_(0,#IDC_ARROW)

  OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com")
 
  WebObject.IWebBrowser2 = GetWindowLongPtr_(GadgetID(0), #GWL_USERDATA)
  WebObject\put_RegisterAsDropTarget(#VARIANT_FALSE)
       
Repeat
  Select WaitWindowEvent()
     
       Case #PB_Event_CloseWindow
            Quit = 1
         
      Case #WM_MOUSEMOVE       
             If EventwParam() = 1 And GetCursor_() <> nCursor
                 ReleaseCapture_()
             EndIf
  EndSelect

Until Quit = 1

Egypt my love
codeprof
User
User
Posts: 65
Joined: Sun Sep 16, 2012 12:13 pm

Re: Disable Drag and Drop in Webgadget

Post by codeprof »

hm, doesn't work either...
I think one way would be to use the Atl... commands directly and do not call OleInitialize(). Howerver, I do not want to write my own WebGadget...
Does somebody know a way to prevent PureBasic form calling OleInitialize?
codeprof
User
User
Posts: 65
Joined: Sun Sep 16, 2012 12:13 pm

Re: Disable Drag and Drop in Webgadget

Post by codeprof »

I think I got it working. At least at first sight. However, I cannot recommend somebody else to use this code as it is PLAIN HACKING :wink: hoping fred does not see it
Better/other solutions are still welcome. :wink:

Code: Select all

Global sLoadUrl.s = "http://www.purebasic.com"

Procedure __Hooked_OleInitialize(reserver)
  ProcedureReturn #S_OK
EndProcedure  

OpenLibrary(0,"atl.dll")
OpenLibrary(1,"user32.dll")

Procedure __Hooked_CreateWindowEx(a,b,c,d,e,f,g,h,i,j,k,l)
  If PeekS(b) = "AtlAxWin"  
    hWnd = CallFunction(1, "CreateWindowExA",a,@"STATIC",c,d | #WS_VSCROLL | #WS_HSCROLL,e,f,g,h,i,j,k,l)
    mem.s = Space(1000)
    PokeS(@mem, sLoadUrl, -1, #PB_Unicode)
    CallFunction(0, "AtlAxCreateControl", @mem, hWnd, 0, @Container.IUnknown)
    ProcedureReturn hWnd
  Else    
    ProcedureReturn CallFunction(1,"CreateWindowExA",a,b,c,d,e,f,g,h,i,j,k,l)
  EndIf
EndProcedure

!extrn __imp__OleInitialize@4
!MOV eax,__imp__OleInitialize@4
!MOV [v__g_imp__OleInitialize],eax
_g_new_imp_OleInitialize = @__Hooked_OleInitialize()
WriteProcessMemory_(GetCurrentProcess_(), _g_imp__OleInitialize, @_g_new_imp_OleInitialize, SizeOf(Integer), #Null)  
  
!extrn __imp__CreateWindowExA@48
!MOV eax,__imp__CreateWindowExA@48
!MOV [v__g_imp__CreateWindowEx],eax
_g_new_imp_CreateWindowEx = @__Hooked_CreateWindowEx()
WriteProcessMemory_(GetCurrentProcess_(), _g_imp__CreateWindowEx, @_g_new_imp_CreateWindowEx, SizeOf(Integer), #Null)  
  
  
OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(0, 0, 0, 580, 280, "http://www.purebasic.com")

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5014
Joined: Sun Apr 12, 2009 6:27 am

Re: Disable Drag and Drop in Webgadget

Post by RASHAD »

Code: Select all

OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com")

WebObject.IWebBrowser2 = GetWindowLongPtr_(GadgetID(0), #GWL_USERDATA)
WebObject\put_RegisterAsDropTarget(#VARIANT_FALSE)
       
Repeat
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
            
       Case #WM_MOUSEMOVE  ;
            GetCursorPos_ (@p.POINT) 
            ScreenToClient_ (GadgetID(0), @p)
            GetClientRect_(GadgetID(0),r.RECT)
            If p\x > r\left And p\x < (r\right -25) And p\y > r\top And p\y < (r\bottom-25)
               ReleaseCapture_()
            EndIf

      ;
  EndSelect 

Until Quit = 1

Egypt my love
codeprof
User
User
Posts: 65
Joined: Sun Sep 16, 2012 12:13 pm

Re: Disable Drag and Drop in Webgadget

Post by codeprof »

@RASHAD
seems to work, but now I cannot correctly select text in the html file.

I now use the following code which seems to work fairly good.

Code: Select all

Prototype.i WinApiAtlAxCreateControl(lpszName.p-unicode, hWnd,*pStream.IStream, *ppUnkContainer.Integer)
Prototype.i WinApiCreateWindowExA(dwExStyle.i, lpClassName.i, lpWindowName.i, dwStyle, x, y , nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)

Global WinApi_AtlAxCreateControl.WinApiAtlAxCreateControl
Global WinApi_CreateWindowExA.WinApiCreateWindowExA

Procedure __Hooked_OleInitialize(reserved)
  ProcedureReturn #S_OK
EndProcedure  

Procedure __CBStatic(hWnd, Message, WParam, LParam)
  If Message = #WM_CTLCOLORSTATIC
    SetBkMode_(wParam, #TRANSPARENT)
    ProcedureReturn GetStockObject_(#HOLLOW_BRUSH)
  Else     
    If GetProp_(hWnd, "OldCB")
      ProcedureReturn CallWindowProc_(GetProp_(hWnd, "OldCB"), hWnd, Message, WParam, LParam)
    Else
      ProcedureReturn DefWindowProc_(hWnd, Message, WParam, LParam)
    EndIf  
  EndIf    
EndProcedure 

Procedure __Hooked_CreateWindowEx(dwExStyle.i, lpClassName.i, lpWindowName.i, dwStyle, x, y , nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
  If lpClassName <> #Null 
    If PeekS(lpClassName) = "AtlAxWin"  
      hWnd = WinApi_CreateWindowExA(0, @"static", @"", #WS_CHILD | #WS_VISIBLE | #WS_CLIPCHILDREN, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
      
      SetProp_(hWnd, "OldCB", GetWindowLong_(hWnd, #GWL_WNDPROC))
      SetWindowLong_(hWnd, #GWL_WNDPROC, @__CBStatic())
      
      WinApi_AtlAxCreateControl("Shell.Explorer.1", hWnd, 0, @Container.IUnknown)
      ProcedureReturn hWnd
    EndIf
  EndIf   
  ProcedureReturn WinApi_CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
EndProcedure

hAtl = LoadLibrary_("atl.dll")
hUser = LoadLibrary_("user32.dll")
If hAtl And hUser
  WinApi_AtlAxCreateControl = GetProcAddress_(hAtl, "AtlAxCreateControl")
  WinApi_AtlAxGetControl = GetProcAddress_(hAtl, "AtlAxGetControl")    
  WinApi_CreateWindowExA = GetProcAddress_(hUser, "CreateWindowExA")
  
  If WinApi_AtlAxCreateControl And WinApi_CreateWindowExA ; only if possible...
    !extrn __imp__OleInitialize@4
    !MOV eax,__imp__OleInitialize@4
    !MOV [v__g_imp__OleInitialize],eax
    _g_new_imp_OleInitialize = @__Hooked_OleInitialize()
    WriteProcessMemory_(GetCurrentProcess_(), _g_imp__OleInitialize, @_g_new_imp_OleInitialize, SizeOf(Integer), #Null)  
    
    !extrn __imp__CreateWindowExA@48
    !MOV eax,__imp__CreateWindowExA@48
    !MOV [v__g_imp__CreateWindowEx],eax
    _g_new_imp_CreateWindowEx = @__Hooked_CreateWindowEx()
    WriteProcessMemory_(GetCurrentProcess_(), _g_imp__CreateWindowEx, @_g_new_imp_CreateWindowEx, SizeOf(Integer), #Null)  
  EndIf
EndIf
CoInitialize_(0)



If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com")
  ; Note: if you want to use a local file, change last parameter to "file://" + path + filename
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf



If hAtl
  FreeLibrary_(hAtl)
EndIf  
If hUser
  FreeLibrary_(hUser)
EndIf  
Post Reply