WebGadget Edit Mode, Help

Just starting out? Need help? Post your questions and find answers here.
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

WebGadget Edit Mode, Help

Post by Truth_Seeker »

I am trying to create a WYSIWYG HTML Editor for a project I am working on and I was wondering how would I turn DesignMode On for the WebGadget? Or am I totaly going at this the wrong way? If I am can you show me the right way to do this and maybe some tiny example to get me started.

I know that PureBasic has some Interfaces already declared but I do not know how to use them in what I am trying to do.

If there is another way than using the WebGadget that will be fine also.
Last edited by Truth_Seeker on Fri Apr 08, 2005 9:27 pm, edited 1 time in total.
Thanks
Truth Seeker
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

Any Ideas?
Thanks
Truth Seeker
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

You have to access DOM. The easir (but no the best) is doing this by javascript with MSscript.
The best should be using the interface, but i cant help you in this was. Maybe PB can give some idea.
ARGENTINA WORLD CHAMPION
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

I tried using MSScriptControl made by FloHimself so I could do some javascript inside my application but PureBasic gave me a error.

Image

I am using the latest version of PureBasic 3.93. The only other idea to do is use the webgadget and make a webpage that would do what I wanted but I did not really want to do that.

The interface idea still sounds good maybe PB can give me some help with that.
Thanks
Truth Seeker
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

Well I have been playing around with the interfaces (more like stumbling, tripping, falling, etc...) and have gotten sorta something like what I wanted (basicly) but I do not know why the delete key will not work for delete like normal (just like you can delete one letter at a time in this text box).

The following code is my poor webgadet editing, not even sure if I am doing it right. Am I on the right track? Help?

Code: Select all

If OpenWindow(0, 0, 0, 640, 480, #PB_Window_ScreenCentered|#PB_Window_SystemMenu, "WebGadget Edit") 
  If CreateGadgetList(WindowID())  
    
    WebGadget(0, 5, 5, 630, 340, "www.google.com")
    ButtonGadget(1, 5, 350, 100, 25, "Bold")
    ButtonGadget(2, 110, 350, 100, 25, "Test")
    
    ; get webgadgets IWebBrowser2 interface: 
    Browser.IWebBrowser2 = GetWindowLong_(GadgetID(0), #GWL_USERDATA)    
    
    ; wait for page to be loaded.. 
    Repeat 
      While WindowEvent(): Wend 
      Delay(1) 
      Browser\get_Busy(@IsBusy.l) 
    Until IsBusy = 0 
    
    ; get the document interface 
    If Browser\get_Document(@DocumentDispatch.IDispatch) = #S_OK 
      
      ; query for IHTMLDocument3: 
      If DocumentDispatch\QueryInterface(?IID_IHTMLDocument2, @Document.IHTMLDocument2) = #S_OK 
        
        ; here you have a IHTMLDocument2 pointer, and can work with it...
        Document\put_designMode(Ansi2Uni("On")) ;Turns on Edit Mode
        
        If DocumentDispatch\QueryInterface(?IID_IOleCommandTarget, @CmdTarget.IOleCommandTarget) = #S_OK
          
          CmdTarget\Exec(@CGID_MSHTML, IDM_2D_POSITION, MSOCMDEXECOPT_DODEFAULT, @var, NULL) ;Lets you drag and drop items
          
          CmdTarget\Release()
        EndIf
        
        
        Document\Release() 
      EndIf 
      
      DocumentDispatch\Release()    
    EndIf 
    
    vb.l
    
    Repeat
      EventID = WaitWindowEvent()
      
      If EventID = #PB_Event_Gadget ;checks for the events
        Select EventGadgetID() ;Checks for Gadget Events
          Case 1
            ;Document\execCommand(Ansi2Uni("Delete"), #False, #Null, @vOut)
            CmdTarget\Exec(@CGID_MSHTML, IDM_BOLD, MSOCMDEXECOPT_DODEFAULT, 0, 0) ;Does not work, dont know why
            
          ; Case 2
            ; Document\queryCommandState(Ansi2Uni("Bold"), @vb)
            ; MessageRequester("", Str(vb))
            
        EndSelect
      EndIf
    Until EventID = #PB_EventCloseWindow 
    
  EndIf 
EndIf 

End 


DataSection

IID_IHTMLDocument2:  ; {332c4425-26cb-11d0-b483-00c04fd90119}
Data.l $332C4425
Data.w $26CB, $11D0
Data.b $B4, $83, $00, $C0, $4F, $D9, $01, $19

IID_IOleCommandTarget:  ; {b722bccb-4e68-101b-a2bc-00aa00404770}
Data.l $B722BCCB
Data.w $4E68, $101B
Data.b $A2, $BC, $00, $AA, $00, $40, $47, $70

EndDataSection

Also I was wondering should I be trying to use the DHTMLEdit interface instead of MSHTML?
Thanks
Truth Seeker
doodlemunch
Enthusiast
Enthusiast
Posts: 237
Joined: Tue Apr 05, 2005 11:20 pm

Post by doodlemunch »

Ansi2Uni() ? is that a function of yours? because my pb doesnt seem to have it :cry:
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

Ansi2Uni() is part of aXend's COMlib.

Library: http://www.purearea.net/pb/download/use ... B_demo.zip

Patch for PureBasic 3.93: http://www.purearea.net/pb/download/use ... IB_393.zip
Thanks
Truth Seeker
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

I made already one for Windows with EditorGadget ;) http://www.bradan.net/ under downloads, but that's stone age.
bye,
Daniel
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

DarkDragon wrote:I made already one for Windows with EditorGadget ;) http://www.bradan.net/ under downloads, but that's stone age.
@DarkDragon: Intresting but I do not think I want to do it like that.

@All: Any replies?
Thanks
Truth Seeker
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

Well I gave up and was lost. But I have come back to this part of the project. I am still hoping someone can give me some help.
Thanks
Truth Seeker
Ziltch
User
User
Posts: 59
Joined: Sun Aug 03, 2003 12:05 am
Location: Australia

Found a few probs in your code

Post by Ziltch »

In your code you have made a few variables from constants tha should have been predefined.

#IDM_2D_POSITION = 2394
#IDM_REGULAR = 1100
#IDM_BOLD = 1200
#IDM_ITALIC = 1300
#IDM_ULINE = 1400
#MSOCMDEXECOPT_DODEFAULT = 0

Put this at the top of your code and put the # in front of them ie
change

Code: Select all

CmdTarget\Exec(@CGID_MSHTML, IDM_BOLD, MSOCMDEXECOPT_DODEFAULT, 0, 0) ;Does Not work, dont know why 
to

Code: Select all

CmdTarget\Exec(@CGID_MSHTML, #IDM_BOLD, #MSOCMDEXECOPT_DODEFAULT, 0, 0) 
This is just at first glance. I will see if I can spot more errors.
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

Thanks for your help, I will keep trying and I hope people will be able to help me some more. It would be nice if we had a library that created a basic wysiwyg HTML (or XHTML) editor out of the webgadget so that people could expand on it for thier own applications.

By the way I am not actualy sure which interface I should be using. I have also heard of the IWebBrowser2 interface. I am really confused about all of this. It might be just me but the M$ documentation is really hard to understand.
Thanks
Truth Seeker
Ziltch
User
User
Posts: 59
Joined: Sun Aug 03, 2003 12:05 am
Location: Australia

Post by Ziltch »

I think this will help

Code: Select all

Enumeration 0 
 #olecmdexecopt_dodefault      
 #olecmdexecopt_promptuser        
 #olecmdexecopt_dontpromptuser    
 #olecmdexecopt_showhelp        
EndEnumeration 


Enumeration
#IDM_ALIGNBOTTOM             
#IDM_ALIGNHORIZONTALCENTERS  
#IDM_ALIGNLEFT               
#IDM_ALIGNRIGHT              
#IDM_ALIGNTOGRID             
#IDM_ALIGNTOP                
#IDM_ALIGNVERTICALCENTERS    
#IDM_ARRANGEBOTTOM           
#IDM_ARRANGERIGHT            
#IDM_BRINGFORWARD            
#IDM_BRINGTOFRONT            
#IDM_CENTERHORIZONTALLY      
#IDM_CENTERVERTICALLY        
#IDM_CODE                    
#IDM_DELETE     =17             
#IDM_FONTNAME                
#IDM_FONTSIZE                
#IDM_GROUP                   
#IDM_HORIZSPACECONCATENATE   
#IDM_HORIZSPACEDECREASE      
#IDM_HORIZSPACEINCREASE      
#IDM_HORIZSPACEMAKEEQUAL     
#IDM_INSERTOBJECT            
#IDM_MULTILEVELREDO     =30      
#IDM_SENDBACKWARD        =32     
#IDM_SENDTOBACK              
#IDM_SHOWTABLE               
#IDM_SIZETOCONTROL           
#IDM_SIZETOCONTROLHEIGHT     
#IDM_SIZETOCONTROLWIDTH      
#IDM_SIZETOFIT               
#IDM_SIZETOGRID              
#IDM_SNAPTOGRID              
#IDM_TABORDER                
#IDM_TOOLBOX                 
#IDM_MULTILEVELUNDO      =44   
#IDM_UNGROUP                
#IDM_VERTSPACECONCATENATE    
#IDM_VERTSPACEDECREASE       
#IDM_VERTSPACEINCREASE       
#IDM_VERTSPACEMAKEEQUAL      
#IDM_JUSTIFYFULL             
#IDM_BACKCOLOR               
#IDM_BOLD                    
#IDM_BORDERCOLOR             
#IDM_FLAT                    
#IDM_FORECOLOR               
#IDM_ITALIC                  
#IDM_JUSTIFYCENTER           
#IDM_JUSTIFYGENERAL          
#IDM_JUSTIFYLEFT             
#IDM_JUSTIFYRIGHT            
#IDM_RAISED                  
#IDM_SUNKEN                  
#IDM_UNDERLINE               
#IDM_CHISELED                
#IDM_ETCHED                  
#IDM_SHADOWED                
#IDM_FIND                    
#IDM_SHOWGRID               = 69
EndEnumeration 
#idm_2d_position = 2394
This command is still not working but I think it should look more like this;

Code: Select all

 CmdTarget\Exec(?CGID_MSHTML, #idm_bold, #olecmdexecopt_dontpromptuser  , 0, 0)
Add this to your datasection and use ?CGID_MSHTML not @CGID_MSHTML

Code: Select all

CGID_MSHTML: 
   Data.l $DE4BA900 
   Data.w $59CA, $11CF
   Data.b $95, $92, $44, $45, $53, $54, $00, $00 
I will try and help more!
Ziltch
User
User
Posts: 59
Joined: Sun Aug 03, 2003 12:05 am
Location: Australia

Post by Ziltch »

Here is some code that works a bit better.

Code: Select all

Enumeration 1 
	#olecmdid_open          
	#olecmdid_new        
	#olecmdid_save          
	#olecmdid_saveas            
	#olecmdid_savecopyas    
	#olecmdid_print        
	#olecmdid_printpreview        
	#olecmdid_pagesetup        
	#olecmdid_spell            
	#olecmdid_properties  
	#olecmdid_cut          
	#olecmdid_copy        
	#olecmdid_paste            
	#olecmdid_pastespecial    
	#olecmdid_undo            
	#olecmdid_redo          
	#olecmdid_selectall        
	#olecmdid_clearselection 
	#olecmdid_zoom            
	#olecmdid_getzoomrange      
	#olecmdid_updatecommands  
	#olecmdid_refresh            
	#olecmdid_stop              
	#olecmdid_hidetoolbars      
	#olecmdid_setprogressmax    
	#olecmdid_setprogresspos  
	#olecmdid_setprogresstext    
	#olecmdid_settitle          
	#olecmdid_setdownloadstate  
	#olecmdid_stopdownload    
	#olecmdid_ontoolbaractivated
	#olecmdid_find 
	#olecmdid_delete
	#olecmdid_httpequiv
	#olecmdid_httpequiv_done
	#olecmdid_enable_interaction 
	#olecmdid_onunload
	#olecmdid_propertybag2
	#olecmdid_prerefresh
	#olecmdid_showscripterror
	#olecmdid_showmessage
	#olecmdid_showfind
	#olecmdid_showpagesetup
	#olecmdid_showprint
	#olecmdid_clos
	#olecmdid_allowuilesssaveas
	#olecmdid_dontdownloadcss
	#olecmdid_updatepagestatus
	#olecmdid_print2
	#olecmdid_printpreview2
	#olecmdid_setprinttemplate
	#olecmdid_getprinttemplate
	#olecmdid_pageactionblocked      = 55; no 53 or 54
	#olecmdid_pageactionuiquery     
	#olecmdid_focusviewcontrols     
	#olecmdid_focusviewcontrolsquery 
	#olecmdid_showpageactionmenu    
EndEnumeration 

Enumeration 0 
	#olecmdexecopt_dodefault      
	#olecmdexecopt_promptuser        
	#olecmdexecopt_dontpromptuser    
	#olecmdexecopt_showhelp        
EndEnumeration 


Enumeration
	#idm_alignbottom             
	#idm_alignhorizontalcenters  
	#idm_alignleft               
	#idm_alignright              
	#idm_aligntogrid             
	#idm_aligntop                
	#idm_alignverticalcenters    
	#idm_arrangebottom           
	#idm_arrangeright            
	#idm_bringforward            
	#idm_bringtofront            
	#idm_centerhorizontally      
	#idm_centervertically        
	#idm_code                    
	#idm_delete     =17             
	#idm_fontname                
	#idm_fontsize                
	#idm_group                   
	#idm_horizspaceconcatenate   
	#idm_horizspacedecrease      
	#idm_horizspaceincrease      
	#idm_horizspacemakeequal     
	#idm_insertobject            
	#idm_multilevelredo     =30      
	#idm_sendbackward        =32     
	#idm_sendtoback              
	#idm_showtable               
	#idm_sizetocontrol           
	#idm_sizetocontrolheight     
	#idm_sizetocontrolwidth      
	#idm_sizetofit               
	#idm_sizetogrid              
	#idm_snaptogrid              
	#idm_taborder                
	#idm_toolbox                 
	#idm_multilevelundo      =44   
	#idm_ungroup                
	#idm_vertspaceconcatenate    
	#idm_vertspacedecrease       
	#idm_vertspaceincrease       
	#idm_vertspacemakeequal      
	#idm_justifyfull             
	#idm_backcolor               
	#idm_bold                    
	#idm_bordercolor             
	#idm_flat                    
	#idm_forecolor               
	#idm_italic                  
	#idm_justifycenter           
	#idm_justifygeneral          
	#idm_justifyleft             
	#idm_justifyright            
	#idm_raised                  
	#idm_sunken                  
	#idm_underline               
	#idm_chiseled                
	#idm_etched                  
	#idm_shadowed                
	#idm_find                    
	#idm_showgrid               = 69
EndEnumeration 
#idm_2d_position = 2394

;#msocmdexecopt_dodefault = 0
Debug "#IDM_BOLD  = "+Str(#idm_bold )

If OpenWindow(0, 0, 0, 640, 480, #PB_Window_ScreenCentered|#PB_Window_SystemMenu, "WebGadget Edit") 
	If CreateGadgetList(WindowID())  
    
		WebGadget(0, 5, 5, 630, 340, "www.google.com") 
		ButtonGadget(1, 5, 350, 100, 25, "Bold") 
		ButtonGadget(2, 110, 350, 100, 25, "Test") 
    
    ; get webgadgets IWebBrowser2 interface: 
		Browser.IWebBrowser2 = GetWindowLong_(GadgetID(0), #GWL_USERDATA)    
    
    ; wait For page To be loaded.. 
		Repeat 
			While WindowEvent(): Wend 
			Delay(1) 
			Browser\get_Busy(@IsBusy.l) 
		Until IsBusy = 0 
    
    ; get the document interface 
		If Browser\get_Document(@DocumentDispatch.IDispatch) = #S_OK 
      
      ; query For IHTMLDocument3: 
			If DocumentDispatch\QueryInterface(?IID_IHTMLDocument2, @Document.IHTMLDocument2) = #S_OK 
        
        ; here you have a IHTMLDocument2 pointer,  can work with it... 
				Document\put_designMode(Ansi2Uni("On")) ;Turns on Edit Mode 
				CmdTarget.IOleCommandTarget
				If DocumentDispatch\QueryInterface(?IID_IOleCommandTarget, @CmdTarget.IOleCommandTarget) = #S_OK 
          
					CmdTarget\Exec(?CGID_MSHTML, #idm_2d_position, #olecmdexecopt_dontpromptuser, @var, Null) ;Lets you drag  drop items 
    ; CmdTarget\Release() 
				EndIf 
 
				Document\Release() 
			EndIf 
      
			DocumentDispatch\Release()    
		EndIf 
    
		vb.l 
    
		Repeat 
			EventID = WaitWindowEvent() 
      
			If EventID = #PB_Event_Gadget ;checks For the events 
				Select EventGadgetID() ;Checks For Gadget Events 
					Case 0 

						Debug "Web Gadget "

					Case 1
						Debug "bold button " 
						;Document\execCommand(Ansi2Uni("Delete"), #False, #Null, @vOut) 
						CmdTarget\Exec(?CGID_MSHTML, #idm_bold,#olecmdexecopt_dontpromptuser  , 0, 0)
						; Document\execCommand(Ansi2Uni("Bold"), #False, #Null, @vOut)     

					Case 2
						Debug "test button "
						Document\queryCommandState(Ansi2Uni("Bold"), @vb) 
						MessageRequester("Bold State", Str(vb)) 
            
				EndSelect 
			EndIf 
		Until EventID = #PB_EventCloseWindow 
		If CmdTarget 
			CmdTarget\Release() 
		EndIf
	EndIf 
EndIf 

End 


DataSection 

IID_IHTMLDocument2:  ; {332c4425-26cb-11d0-b483-00c04fd90119} 
	Data.l $332C4425 
	Data.w $26CB, $11D0 
	Data.b $B4, $83, $00, $C0, $4F, $D9, $01, $19 

IID_IOleCommandTarget:  ; {b722bccb-4e68-101b-a2bc-00aa00404770} 
	Data.l $B722BCCB 
	Data.w $4E68, $101B 
	Data.b $A2, $BC, $00, $AA, $00, $40, $47, $70 
CGID_MSHTML: ; { 0xDE4BA900, 0x59CA, 0x11CF, { 0x95, 0x92, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 } }
	Data.l $DE4BA900 
	Data.w $59CA, $11CF
	Data.b $95, $92, $44, $45, $53, $54, $00, $00 
EndDataSection
The idm constants are found in the Ms header "MsHtmcid.h". If you get a copy of this file it has lots more constants that you could find useful.

I hope this helps!
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

Wow your fast, thanks for the help. I have not even had a chance to do anything yet with it. By the way I noticed that the delete button does not delete.

Where did you find all of this stuff? Can you post some links?
Thanks
Truth Seeker
Post Reply