Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Command Bars
  New Posts New Posts RSS Feed - [SOLVED!] Combined Refresh and Stop button?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

[SOLVED!] Combined Refresh and Stop button?

 Post Reply Post Reply
Author
Message
shipwreck View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 April 2008
Location: United States
Status: Offline
Points: 308
Post Options Post Options   Thanks (0) Thanks(0)   Quote shipwreck Quote  Post ReplyReply Direct Link To This Post Topic: [SOLVED!] Combined Refresh and Stop button?
    Posted: 26 December 2009 at 11:23pm
Hello Folks!
Here is another question for you.
I was interested in creating one button in the commandbars to work as both the refresh and stop button. Similar to most other browsers available today.
So, I was wondering that if this is possible and if so, just exactly how to implement this.
 
If anyone can give me a suggestion or maybe a code example it would be greatly appreciated.
 
Thanks and Regards in advance.
Product: Xtreme Suite Pro (Active-X), Version 15.3.1

Platform: Windows 7 Ultimate SP1 (64Bit) & Windows XP Mode SP3 (32Bit)

Language: Visual Basic 6.0 SP6
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 27 December 2009 at 2:16pm
Using Actions can help you here. First, in the General Declarations section, add some action IDs and a variable to store a reference to your Stop/Refresh button:


Private Const mc_ActionStop As Long = 100
Private Const mc_ActionRefresh As Long = 101

Private mo_StopOrRefresh As XtremeCommandBars.CommandBarControl


Note that these IDs should not be the same as IDs that you are using for other CommandBar controls.

Next, before adding any CommandBar controls, make sure to enable actions and create your stop and refresh actions:


Me.CommandBars1.EnableActions

Me.CommandBars1.Actions.Add mc_ActionRefresh, "Refresh", "Refresh this page", "Refresh this page", "Page"
Me.CommandBars1.Actions.Add mc_ActionStop, "Stop", "Stop loading this page", "Stop loading this page", "Page"


Next, add your Stop/Refresh button to the CommandBars (for this example, I am adding the control to a Ribbon), and then assign the starting action to it:


Set mo_StopOrRefresh = mo_Ribbon.Controls.Add(xtpControlButton, 0, "")
Set mo_StopOrRefresh.Action = Me.CommandBars1.Actions.Action(mc_ActionRefresh)


You can swap between actions as required by using this sub:


Public Sub SwapStopRefresh()
   Dim l_ActionId As Long

   Select Case mo_StopOrRefresh.Action.Id
   Case mc_ActionRefresh
      l_ActionId = mc_ActionStop
   Case Else
      l_ActionId = mc_ActionRefresh
   End Select

   Set mo_StopOrRefresh.Action = Me.CommandBars1.Actions.Action(l_ActionId)
End Sub


Finally, you can use the CommandBars_Execute event to test for (and perform) either action as follows:


Private Sub CommandBars1_Execute(ByVal Control As XtremeCommandBars.ICommandBarControl)
   Dim l_ExecId As Long
  
   ' Get the action ID to be processed
   If Not Control.Action Is Nothing Then
      l_ExecId = Control.Action.Id
   Else
      ' Some CommandBar UI elements (e.g. StatusBar Switches) don't use actions,
      ' so for those just get the control ID
      l_ExecId = Control.Id
   End If
  
   ' Act accordingly on the passed ID
   Select Case l_ExecId
   Case mc_ActionRefresh
      ' Refresh the page
      MsgBox "Refresh"
  
   Case mc_ActionStop
      ' Stop loading the page
      MsgBox "Stop"
     
   End Select
End Sub


Please note that some of this is air code, so if there are any problems, please get back to me.
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
shipwreck View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 April 2008
Location: United States
Status: Offline
Points: 308
Post Options Post Options   Thanks (0) Thanks(0)   Quote shipwreck Quote  Post ReplyReply Direct Link To This Post Posted: 27 December 2009 at 9:18pm
Okay man I'm opening the virtual machine now & will get back to you on these. Thanks!
Product: Xtreme Suite Pro (Active-X), Version 15.3.1

Platform: Windows 7 Ultimate SP1 (64Bit) & Windows XP Mode SP3 (32Bit)

Language: Visual Basic 6.0 SP6
Back to Top
shipwreck View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 April 2008
Location: United States
Status: Offline
Points: 308
Post Options Post Options   Thanks (0) Thanks(0)   Quote shipwreck Quote  Post ReplyReply Direct Link To This Post Posted: 27 December 2009 at 11:58pm
Dude, your a life saver!
This functions wonderfully. But, I have another question.
I intend the commandbutton to have a refresh icon as well as a stop icon. is there anyway I can have those change in runtime as well?
Product: Xtreme Suite Pro (Active-X), Version 15.3.1

Platform: Windows 7 Ultimate SP1 (64Bit) & Windows XP Mode SP3 (32Bit)

Language: Visual Basic 6.0 SP6
Back to Top
shipwreck View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 April 2008
Location: United States
Status: Offline
Points: 308
Post Options Post Options   Thanks (0) Thanks(0)   Quote shipwreck Quote  Post ReplyReply Direct Link To This Post Posted: 28 December 2009 at 12:24am
Okay man, I'll go ahead and create a new topic for the icon problem. Hite me up there. :]
Product: Xtreme Suite Pro (Active-X), Version 15.3.1

Platform: Windows 7 Ultimate SP1 (64Bit) & Windows XP Mode SP3 (32Bit)

Language: Visual Basic 6.0 SP6
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 28 December 2009 at 11:37am
Glad to help, but patience my friend, I'm in a different time zone ;)

The action objects that you create have an IconId property, so you can set the icons when you are creating the actions as follows:

With Me.CommandBars1.Actions.Add(mc_ActionRefresh, "Refresh", "Refresh this page", "Refresh this page", "Page")
.IconId = ' Icon # for an icon in your CommandBars icons list
End With
With Me.CommandBars1.Actions.Add(mc_ActionStop, "Stop", "Stop loading this page", "Stop loading this page", "Page")
.IconId = ' Different Icon #
End With

Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
shipwreck View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 April 2008
Location: United States
Status: Offline
Points: 308
Post Options Post Options   Thanks (0) Thanks(0)   Quote shipwreck Quote  Post ReplyReply Direct Link To This Post Posted: 28 December 2009 at 11:39am
Oh, I see. That definitely makes sense. I'll try that asap!
But I figured the time zones were different. The whole website is setup that way. It's pretty funny actually, I can post a reply at 11:00 and it says I posted it at like 5:14 on the site.
Product: Xtreme Suite Pro (Active-X), Version 15.3.1

Platform: Windows 7 Ultimate SP1 (64Bit) & Windows XP Mode SP3 (32Bit)

Language: Visual Basic 6.0 SP6
Back to Top
shipwreck View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 April 2008
Location: United States
Status: Offline
Points: 308
Post Options Post Options   Thanks (0) Thanks(0)   Quote shipwreck Quote  Post ReplyReply Direct Link To This Post Posted: 28 December 2009 at 12:44pm
Okay jpbro. Just got finished trying that code. It works perfect!
 
But, and I apologize, but I have another question for you. :p
What if I wanted to do a three button combination?
For example, Go, Refresh, and Stop.
I think You would have the refresh and stop setup on active forms web browser control and you would then have it set that if the address in the address bar is different from the location URL it would be a go button, otherwise it would be the refresh button.
Is there any way in doing that?
Product: Xtreme Suite Pro (Active-X), Version 15.3.1

Platform: Windows 7 Ultimate SP1 (64Bit) & Windows XP Mode SP3 (32Bit)

Language: Visual Basic 6.0 SP6
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 28 December 2009 at 8:00pm
Sure, just create a new Action object and assign it a unique ID...something like:

In the General Declarations:
Private Const mc_ActionGo As Long = 102

And then, you will want to change the name of your control reference variable to make more sense:
Private mo_StopGoRefresh As XtremeCommandBars.CommandBarControl

Then wherever you create your actions, add:
With Me.CommandBars1.Actions.Add(mc_ActionGo, "Go", "Go to this URL", "Go to this URL", "Page")
.IconId = ' ID # of GO icon
End With

And then instead of a SwapStopRefresh sub, you might want a SetPageState() sub (as an example):

First in the General Declarations, create a new enum to indicate the page state:

Private Enum e_PageState
   pagestate_Loaded   ' Page is loaded, REFRESH button should be available
   pagestate_Loading   ' Page is loading, STOP button should be available
   pagestate_DifferentUrl    ' User has typed a different URL than the current page URL, GO button should be available


And then add this sub, and call it with the appropriate page state parameter when your conditions are met:

Private Sub SetPageState(ByVal p_PageState As e_PageState)
   Dim l_ActionId As Long

   Select Case p_PageState
   Case pagestate_Loading
      l_ActionId = mc_ActionStop
   Case pagestate_Loaded
      l_ActionId = mc_ActionRefresh
   Case pagestate_DifferentUrl
      l_ActionId = mc_ActionGo
   Case Else
      Err.Raise 5, , "Unknown page state."
   End Select

   Set mo_StopGoRefresh.Action = Me.CommandBars1.Actions.Action(l_ActionId)
End Sub

Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
shipwreck View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 April 2008
Location: United States
Status: Offline
Points: 308
Post Options Post Options   Thanks (0) Thanks(0)   Quote shipwreck Quote  Post ReplyReply Direct Link To This Post Posted: 29 December 2009 at 1:15am
Okay jpbro, you've help me this far and I really appreciate it. So, let me ask you this:
I have been trying to implement a "Favorites/Bookmarks" bar into the browser, similar to firefox, chrome, safari, and even IE 8.
 
So far I haven't had any luck whatsoever on this one. I've tried several different ways using a text file, a database and etc.
 
In other words, I would like to have a toolbar that displays the users favorites and the user can edit, delete, and create more bookmarks to the bar at runtime.
 
Have any ideas on this one my friend?
Product: Xtreme Suite Pro (Active-X), Version 15.3.1

Platform: Windows 7 Ultimate SP1 (64Bit) & Windows XP Mode SP3 (32Bit)

Language: Visual Basic 6.0 SP6
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 29 December 2009 at 2:30pm
What problems were you having? A database or a text file should be fine for storing bookmarks. You can Add CommandBar controls using the Add method of a CommandBar.Controls object, and then use the Delete method of any CommandBar.Controls.Item object.

Editing is a bit trickier - You could use the CommandBars1_ControlRButtonUp event to catch when a user right-clicks a control, and then test the Id property to see if the control is one of your Bookmark controls. If so, you could then use the ShowPopup method of a CommandBar object to offer a menu with Edit and Remove buttons. If the user clicks Edit (as caught in the _Execute event), just show a new window and allow them to change the displayed caption.

Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
shipwreck View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 April 2008
Location: United States
Status: Offline
Points: 308
Post Options Post Options   Thanks (0) Thanks(0)   Quote shipwreck Quote  Post ReplyReply Direct Link To This Post Posted: 30 December 2009 at 3:01am
Okay, that pretty much describes exactly what I'm looking for jpbro. Is there anyway you could explain that option in further detail or maybe a sample?
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 30 December 2009 at 10:33am
Unfortunately, I don't have much time right now to do up a sample as I have a project due very soon.

Between the RC sample and my explanation above, there should be enough to get started. Why don't you give it a try (maybe in a separate, new project) and when you encounter problems, you can post the project up here with questions (maybe a new thread would be better). I can then try to help with specific problems if I have a bit of time to spare (or others can help too).

Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
shipwreck View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 April 2008
Location: United States
Status: Offline
Points: 308
Post Options Post Options   Thanks (0) Thanks(0)   Quote shipwreck Quote  Post ReplyReply Direct Link To This Post Posted: 30 December 2009 at 10:57am
Okay man but what are you leaning torwards when you say "RC Sample"?
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 30 December 2009 at 10:59am
Sorry, I had the ReportControl on my mind from another post ;) I meant the CommandBars Ribbon Sample that ships with the CJ controls (in your Program Files\Codejock Software\ActiveX\Xtreme SuitePro ActiveX vX.X.X\Samples\CommandBars\VB\RibbonSample folder, where X.X.X is the version of the suite that you have installed).
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
shipwreck View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 April 2008
Location: United States
Status: Offline
Points: 308
Post Options Post Options   Thanks (0) Thanks(0)   Quote shipwreck Quote  Post ReplyReply Direct Link To This Post Posted: 30 December 2009 at 11:02am
Oh, Okay. I see. Don't feel bad though, everyone makes mistakes ever once in a while.
But I'll attempt to try that I suppose. I'm not sure if I'll have any luck on this one since I'm not real familiar with the coding off the top of my head.
But, I hope you get that project done! Best of luck!
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.199 seconds.