Page 1 of 1

Webgadget : use clipboard ?

Posted: Mon Aug 25, 2003 1:27 am
by eddy
I've found this C++ code and I wonder if PB can use ExecWB_ like a API command...

Code: Select all

void CWebBrowserView::OnEditCut()
{ 
    ExecWB(OLECMDID_CUT, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL); 
} 

void CWebBrowserView::OnEditCopy() 
{ 
    ExecWB(OLECMDID_COPY, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL); 
} 

void CWebBrowserView::OnEditPaste() 
{ 
    ExecWB(OLECMDID_PASTE, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL); 
} 
 

Posted: Tue Aug 26, 2003 9:22 am
by LuckyLuke
I guess the CallCom function is needed to call ExecWB.

In viewtopic.php?t=4375 El_Choni wrote :
I don't know how to use this with WebGadget, but these are the methods allowed by the IWebBrowser2 interface, which is used by WebGadget and by this snippet posted by Fred
Unfortunatly I can't find Fred's snippet .

Posted: Tue Aug 26, 2003 8:37 pm
by freak
With a bit of Fred's help, I got this thing working...

Just select something and press 'copy'...

Code: Select all

  #X = 0  ; the good old trick... I'm too lazy

; here comes the IWebBrowser2 Interface for CallCOM()
  #QueryInterface           = #X: #X = #X + 4
  #AddRef                   = #X: #X = #X + 4
  #Release                  = #X: #X = #X + 4        
  #GetTypeInfoCount         = #X: #X = #X + 4
  #GetTypeInfo              = #X: #X = #X + 4
  #GetIDsOfNames            = #X: #X = #X + 4
  #Invoke                   = #X: #X = #X + 4        
  #GoBack                   = #X: #X = #X + 4
  #GoForward                = #X: #X = #X + 4
  #GoHome                   = #X: #X = #X + 4
  #GoSearch                 = #X: #X = #X + 4
  #Navigate                 = #X: #X = #X + 4
  #Refresh                  = #X: #X = #X + 4
  #Refresh2                 = #X: #X = #X + 4
  #Stop                     = #X: #X = #X + 4
  #get_Application          = #X: #X = #X + 4
  #get_Parent               = #X: #X = #X + 4
  #get_Container            = #X: #X = #X + 4
  #get_Document             = #X: #X = #X + 4
  #get_TopLevelContainer    = #X: #X = #X + 4
  #get_Type                 = #X: #X = #X + 4
  #get_Left                 = #X: #X = #X + 4
  #put_Left                 = #X: #X = #X + 4
  #get_Top                  = #X: #X = #X + 4
  #put_Top                  = #X: #X = #X + 4
  #get_Width                = #X: #X = #X + 4
  #put_Width                = #X: #X = #X + 4
  #get_Height               = #X: #X = #X + 4
  #put_Height               = #X: #X = #X + 4
  #get_LocationName         = #X: #X = #X + 4
  #get_LocationURL          = #X: #X = #X + 4
  #get_Busy                 = #X: #X = #X + 4
  #Quit                     = #X: #X = #X + 4
  #ClientToWindow           = #X: #X = #X + 4
  #PutProperty              = #X: #X = #X + 4
  #GetProperty              = #X: #X = #X + 4
  #get_Name                 = #X: #X = #X + 4
  #get_HWND                 = #X: #X = #X + 4
  #get_FullName             = #X: #X = #X + 4
  #get_Path                 = #X: #X = #X + 4
  #get_Visible              = #X: #X = #X + 4
  #put_Visible              = #X: #X = #X + 4
  #get_StatusBar            = #X: #X = #X + 4
  #put_StatusBar            = #X: #X = #X + 4
  #get_StatusText           = #X: #X = #X + 4
  #put_StatusText           = #X: #X = #X + 4
  #get_ToolBar              = #X: #X = #X + 4
  #put_ToolBar              = #X: #X = #X + 4
  #get_MenuBar              = #X: #X = #X + 4
  #put_MenuBar              = #X: #X = #X + 4
  #get_FullScreen           = #X: #X = #X + 4
  #put_FullScreen           = #X: #X = #X + 4
  #Navigate2                = #X: #X = #X + 4
  #QueryStatusWB            = #X: #X = #X + 4
  #ExecWB                   = #X: #X = #X + 4
  #ShowBrowserBar           = #X: #X = #X + 4
  #get_ReadyState           = #X: #X = #X + 4
  #get_Offline              = #X: #X = #X + 4
  #put_Offline              = #X: #X = #X + 4
  #get_Silent               = #X: #X = #X + 4
  #put_Silent               = #X: #X = #X + 4
  #get_RegisterAsBrowser    = #X: #X = #X + 4
  #put_RegisterAsBrowser    = #X: #X = #X + 4
  #get_RegisterAsDropTarget = #X: #X = #X + 4
  #put_RegisterAsDropTarget = #X: #X = #X + 4
  #get_TheaterMode          = #X: #X = #X + 4
  #put_TheaterMode          = #X: #X = #X + 4
  #get_AddressBar           = #X: #X = #X + 4
  #put_AddressBar           = #X: #X = #X + 4
  #get_Resizable            = #X: #X = #X + 4
  #put_Resizable            = #X


; Constants for the ExecWB Method: 
     #OLECMDID_OPEN              = 1
     #OLECMDID_NEW               = 2 
     #OLECMDID_SAVE              = 3
     #OLECMDID_SAVEAS            = 4 
     #OLECMDID_SAVECOPYAS        = 5 
     #OLECMDID_PRINT             = 6 
     #OLECMDID_PRINTPREVIEW      = 7 
     #OLECMDID_PAGESETUP         = 8 
     #OLECMDID_SPELL             = 9 
     #OLECMDID_PROPERTIES        = 10 
     #OLECMDID_CUT               = 11 
     #OLECMDID_COPY              = 12 
     #OLECMDID_PASTE             = 13 
     #OLECMDID_PASTESPECIAL      = 14 
     #OLECMDID_UNDO              = 15 
     #OLECMDID_REDO              = 16
     #OLECMDID_SELECTALL         = 17
     #OLECMDID_CLEARSELECTION    = 18
     #OLECMDID_ZOOM              = 19
     #OLECMDID_GETZOOMRANGE      = 20 
     #OLECMDID_UPDATECOMMANDS    = 21 
     #OLECMDID_REFRESH           = 22 
     #OLECMDID_STOP              = 23 
     #OLECMDID_HIDETOOLBARS      = 24 
     #OLECMDID_SETPROGRESSMAX    = 25 
     #OLECMDID_SETPROGRESSPOS    = 26 
     #OLECMDID_SETPROGRESSTEXT   = 27 
     #OLECMDID_SETTITLE          = 28 
     #OLECMDID_SETDOWNLOADSTATE  = 29 
     #OLECMDID_STOPDOWNLOAD      = 30 

     #OLECMDEXECOPT_DODEFAULT        = 0 
     #OLECMDEXECOPT_PROMPTUSER       = 1 
     #OLECMDEXECOPT_DONTPROMPTUSER   = 2
     #OLECMDEXECOPT_SHOWHELP         = 3 
     
; -----------------------------------------------------

; Now the code

#WebGadget = 1
#Button = 2

OpenWindow(0, 0, 0, 800, 800, #PB_Window_Screencentered|#PB_Window_SystemMenu, "WebBrowser")
CreateGadgetList(WindowID())

WebGadget(#WebGadget, 10, 40, 780, 750, "www.purebasic.com")
ButtonGadget(#Button, 10, 10, 60, 20, "Copy")

; Fred the genius stored the Interface pointer to IWebBrowser2 in the DATA
; member of the windowstructure of the WebGadget containerwindow, so we can get
; that easily:
WebObject.l = GetWindowLong_(GadgetID(#WebGadget), #GWL_USERDATA)

Repeat
  Event = WaitWindowEvent() 
  If Event = #PB_EventGadget And EventGadgetID() = #Button
    
    ; Now here's the actual copy thing, not that complicated... 
    CallCOM(#ExecWB, WebObject, #OLECMDID_COPY, #OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)
    
    ; little test:
    MessageRequester("", GetClipboardText(), 0)
    
  EndIf
Until Event = #PB_EventCLoseWindow

End
Here's the description of the Methods of IWebBrowser2:
http://msdn.microsoft.com/library/defau ... owser2.asp

ms-help://MS.PSDK.1033/inet/workshop/browser/webbrowser/reference/ifaces/iwebbrowser2/iwebbrowser2.htm (for those with MS PlatformSDK 2003)

Timo

Posted: Wed Aug 27, 2003 1:39 am
by eddy
Thx Freak, this tip is very usefull.

:arrow: Andre should add it in code archive.

Today, I've discovered a new function CALLCOM et COM objects

Posted: Wed Aug 27, 2003 1:00 pm
by LuckyLuke
How should we call this function in PB ?

Code: Select all

HRESULT IWebBrowser2::get_LocationURL(BSTR *pbstrLocationURL);
I tried this, but it's returning random strange characters ...

Code: Select all

a$ = ""
CallCOM(#get_LocationURL, WebObject, @a$) 
MessageRequester("", a$, 0) 

Posted: Thu Aug 28, 2003 1:15 am
by freak
The String involved here is of type BSTR, which is different from PB's strings.

Basically, it is a Unicode string, of which you only get the pointer, and later
have to call SysFreeString_() to free it.

here is how it works:

Code: Select all

CallCOM(#get_LocationURL, WebObject, @BSTR_Url.l)   ; get BSTR pointer
Length.l = WideCharToMultiByte_(#CP_ACP, 0, BSTR_Url, -1, 0, 0, 0, 0)  ; get Length of String in ANSI format
Url.s = Space(Length)  ; reserve String buffer
WideCharToMultiByte_(#CP_ACP, 0, BSTR_Url, -1, @url, Length, 0, 0)  ; translate string from UNICODE
SysFreeString_(BSTR_Url)  ; free BSTR string

MessageRequester("", Url, 0)
Timo

Posted: Thu Aug 28, 2003 8:34 am
by LuckyLuke
Thanks freak !
Interesting information.

Posted: Thu Aug 28, 2003 12:40 pm
by freak
I put together a little procedure for simpler usage...
It converts the String to ANSI format (what PB uses), and frees the
BSTR string.

So it can look like this:

Code: Select all

Procedure.s ConvertBSTR(BSTR_String.l)
  Protected ANSI_String.s, ANSI_Length.l
  ANSI_Length = WideCharToMultiByte_(#CP_ACP, 0, BSTR_String, -1, 0, 0, 0, 0)
  ANSI_String = Space(ANSI_Length)
  WideCharToMultiByte_(#CP_ACP, 0, BSTR_String, -1, @ANSI_String, ANSI_Length, 0, 0)
  SysFreeString_(BSTR_String)
  ProcedureReturn ANSI_String
EndProcedure

; ----------------------------------------

CallCOM(#get_LocationURL, WebObject, @BSTR_Url.l)
Url.s = ConvertBSTR(BSTR_Url)

MessageRequester("", Url, 0)
Timo

Posted: Sun Sep 07, 2003 12:13 pm
by Andre
eddy wrote: :arrow: Andre should add it in code archive.
Done, for next version... :D