Set Webgadget border style?

Just starting out? Need help? Post your questions and find answers here.
hagibaba
Enthusiast
Enthusiast
Posts: 170
Joined: Fri Mar 05, 2004 2:55 am
Location: UK
Contact:

Set Webgadget border style?

Post by hagibaba »

Does anyone know if you can change the border style around a webgadget? It defaults to borderless. I want a double line sunken border. I have a container gadget for the border currently.
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

Someone might be able to make a better example...

Code: Select all

  If OpenWindow(0, 0, 0, 640, 480, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
    
    web_gadget = WebGadget(#PB_Any, 50, 50, 256, 256, "http://localhost")
    web_gadget_handle = GadgetID(web_gadget)

    web_gadget_exstyle = GetWindowLong_( web_gadget_handle, #GWL_EXSTYLE)
    SetWindowLong_( web_gadget_handle, #GWL_EXSTYLE, web_gadget_exstyle |  #WS_EX_CLIENTEDGE | #WS_EX_LEFTSCROLLBAR	) ; dont ask why this works...
		UpdateWindow_( web_gadget_handle ) ; make sure it updates?
    
    Repeat 
    Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
I don't know why this works, I mean... without the #WS_EX_LEFTSCROLLBAR it doesn't work!

--EDIT--

Either #WS_EX_LEFTSCROLLBAR or #WS_EX_LEFT or #WS_EX_RIGHT is needed for the border styles to work, anyone knows why?

Try #WS_EX_STATICEDGE if you want a thinner border though.

--EDIT2--

Well, this is what I have so far:


Code: Select all

 Procedure WebGadgetBorder( hWnd.l )
  	If (IsWindow_(hWnd)) 
	    SetWindowLong_( hWnd, #GWL_EXSTYLE, GetWindowLong_( hWnd, #GWL_EXSTYLE) |  #WS_EX_CLIENTEDGE | #WS_EX_RIGHT ) ; #WS_EX_LAYOUTRTL
			UpdateWindow_( hWnd ) ; make sure it updates?
  	EndIf
  EndProcedure
  
  If OpenWindow(0, 0, 0, 640, 480, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
    
    web_gadget = WebGadget(#PB_Any, 50, 20, 540, 440, "http://www.google.com/search?&q=Google")		
		WebGadgetBorder( GadgetID(web_gadget) )

    Repeat 
    Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
I researched on the problem and I couldn't find anything useful, it simply isn't displaying the border in my XP unless I set an RTL style!... Very, very strange.
Last edited by superadnim on Tue Apr 22, 2008 9:42 pm, edited 1 time in total.

:lol: should I bash the keyboard and give up?
:?
hagibaba
Enthusiast
Enthusiast
Posts: 170
Joined: Fri Mar 05, 2004 2:55 am
Location: UK
Contact:

Post by hagibaba »

Thanks for the quick reply. Doesn't work here though (Win ME).

Also, how do you set the focus on a webgadget? I can't do that either.

Edit: oh, another one. Checking it out now.

Edit2: No the second one doesn't work either.
hagibaba
Enthusiast
Enthusiast
Posts: 170
Joined: Fri Mar 05, 2004 2:55 am
Location: UK
Contact:

Post by hagibaba »

I tried using GetWindowLong_() with #GWL_EXSTYLE for a webgadget and it just returns zero. I assume this means webgadgets don't have extended styles.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Does this not work ?

Code: Select all

  If OpenWindow(0, 0, 0, 640, 480, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
    
    web_gadget = WebGadget(#PB_Any, 50, 50, 256, 256, "http://localhost") 
    hWnd = GadgetID(web_gadget) 

    style = GetWindowLong_(hWnd, #GWL_EXSTYLE) 
    SetWindowLong_(hWnd, #GWL_EXSTYLE, style|#WS_EX_CLIENTEDGE)
    SetWindowPos_(hWnd,0,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE|#SWP_NOOWNERZORDER|#SWP_DRAWFRAME)	

    
    Repeat 
    Until WaitWindowEvent() = #PB_Event_CloseWindow 
  EndIf
I may look like a mule, but I'm not a complete ass.
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

Try this for setting the focus, and I added a WS_STYLE in hopes that it works under 9X but I can't test right now, I only have XP here, sorry.

Code: Select all

  Procedure WebGadgetSetBorder( hWnd.l )
  	If (IsWindow_(hWnd)) 
  		SetWindowLong_( hWnd, #GWL_STYLE, GetWindowLong_( hWnd, #GWL_STYLE) |  #WS_THICKFRAME ) ; as thick as it gets
	    SetWindowLong_( hWnd, #GWL_EXSTYLE, GetWindowLong_( hWnd, #GWL_EXSTYLE) |  #WS_EX_WINDOWEDGE | #WS_EX_CLIENTEDGE | #WS_EX_RIGHT ) ; #WS_EX_LAYOUTRTL
			UpdateWindow_( hWnd ) ; make sure it updates?
  	EndIf
  EndProcedure
	Procedure.l WebGadgetSetFocus( hWnd.l )
		Repeat 
			hWnd = GetWindow_( hWnd, #GW_CHILD )
			Define.s lpClassName = Space(#MAX_PATH)
			GetClassName_( hWnd, lpClassName, #MAX_PATH)
			If lpClassName = "Internet Explorer_Server"
				ProcedureReturn SetFocus_( hWnd )
				EndIf
		Until hWnd = #Null
	EndProcedure
		
  If OpenWindow(0, 0, 0, 640, 480, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
    
    web_gadget = WebGadget(#PB_Any, 50, 20, 540, 440, "http://www.google.com/search?&q=Google")		
		WebGadgetSetBorder( GadgetID(web_gadget) )
		WebGadgetSetFocus( GadgetID(web_gadget) )
		
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
    
  EndIf
Notice, if you're browsing local files inside your WebGadget the WebGadgetSetFocus routine WILL fail, because the instance created in the embedded object is not an internet explorer object but rather a shell (explorer) object. (at least thats what I remember from previous attempts)
Last edited by superadnim on Tue Apr 22, 2008 9:58 pm, edited 1 time in total.

:lol: should I bash the keyboard and give up?
:?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

superadnim, the reason you're having to use the extra styles is because UpdateWindow_() does not refresh the non-client area. Instead, simply use SetWindowPos_() etc.
I may look like a mule, but I'm not a complete ass.
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

srod, thanks! thats it!
sending #SWP_FRAMECHANGED seems to work :)

now, I should undust my old winME and see if it works.

:lol: should I bash the keyboard and give up?
:?
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

Final code from my side, works in XP and WinME:

Code: Select all

  Procedure WebGadgetSetBorder( hWnd.l, mode.l=#False )
  	If (IsWindow_(hWnd)) 
			If (mode)
				SetWindowLong_( hWnd, #GWL_STYLE, GetWindowLong_( hWnd, #GWL_STYLE) |  #WS_THICKFRAME )
			Else
				SetWindowLong_( hWnd, #GWL_EXSTYLE, GetWindowLong_( hWnd, #GWL_EXSTYLE) | #WS_EX_CLIENTEDGE  )
			EndIf
			SetWindowPos_(hWnd, #Null, 0,0,0,0 , #SWP_FRAMECHANGED | #SWP_NOSIZE | #SWP_NOMOVE	)
  	EndIf
  EndProcedure
	Procedure.l WebGadgetSetFocus( hWnd.l )
		Repeat 
			hWnd = GetWindow_( hWnd, #GW_CHILD )
			Define.s lpClassName = Space(#MAX_PATH)
			GetClassName_( hWnd, lpClassName, #MAX_PATH)
			If lpClassName = "Internet Explorer_Server"
				ProcedureReturn SetFocus_( hWnd )
				EndIf
		Until hWnd = #Null
	EndProcedure
		
  If OpenWindow(0, 0, 0, 640, 480, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
    
    web_gadget = WebGadget(#PB_Any, 50, 20, 540, 440, "http://www.google.com/search?&q=Google")		
		WebGadgetSetBorder( GadgetID(web_gadget) )
		WebGadgetSetFocus( GadgetID(web_gadget) )
		
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
    
  EndIf
I'm not too happy about the focus routine but thats the only thing I could come up with :(

Perhaps, if you iterate until you can't find a child anymore, that'll give you the last child which is the one you should be sending the focus to. Either way I ignore if winapi has a function or better way to do this that's why I did it by hand.

Hope it works over there too.

--EDIT--

This is what I meant, but it doesn't work with files...

Code: Select all

	Procedure.l WebGadgetSetFocus( hWnd.l ) ; still doesn't work with webgadget while browsing files...
		If (IsWindow_(hWnd))
			Define.l temp
			Repeat 
				temp = hWnd
				hWnd = GetWindow_( hWnd, #GW_CHILD )
			Until hWnd = #Null
			If (IsWindow_(temp))
				ProcedureReturn SetFocus_( temp )
			EndIf
		EndIf
	EndProcedure

:lol: should I bash the keyboard and give up?
:?
hagibaba
Enthusiast
Enthusiast
Posts: 170
Joined: Fri Mar 05, 2004 2:55 am
Location: UK
Contact:

Post by hagibaba »

Yes, srod your example works here, and superadnim's last example works. Thanks!

Any ideas about setting the focus? Like when I change tabs setgadgetstate works for an editorgadget but not with a webgadget.

Edit: Oops, sorry superadnim, I didn't read your whole last post.
hagibaba
Enthusiast
Enthusiast
Posts: 170
Joined: Fri Mar 05, 2004 2:55 am
Location: UK
Contact:

Post by hagibaba »

Both your setfocus functions work here superadnim, I'm using local files. Thanks, I prefer the first version, it loops 3 times so not too many. I didn't realize a webgadget is embedded. Anyway, here is what I am using now...

Code: Select all

Procedure SetWebBorder(Gadget.l)
 ;Double sunken border for WebGadget, by srod
 
 Protected hWnd.l = GadgetID(Gadget)
 SetWindowLong_(hWnd, #GWL_EXSTYLE, GetWindowLong_(hWnd, #GWL_EXSTYLE) | #WS_EX_CLIENTEDGE)
 SetWindowPos_(hWnd, 0, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_NOOWNERZORDER | #SWP_DRAWFRAME)
 
EndProcedure

Code: Select all

Procedure.l SetWebFocus(Gadget.l)
 ;Set the focus on a WebGadget, by superadnim
 
 Protected lpClassName$, hWnd.l = GadgetID(Gadget)
 Repeat
  hWnd = GetWindow_(hWnd, #GW_CHILD)
  lpClassName$ = Space(#MAX_PATH)
  GetClassName_(hWnd, lpClassName$, #MAX_PATH)
  If lpClassName$ = "Internet Explorer_Server"
   ProcedureReturn SetFocus_(hWnd)
  EndIf
 Until hWnd = #Null
 
EndProcedure
Post Reply