Link to home
Start Free TrialLog in
Avatar of sirbounty
sirbountyFlag for United States of America

asked on

Windows media player

Is it possible to have my program reside in the toolbar, much like you can with the new version of media player?
I've got a form with only 3 controls on it and I'm curious if I can just have it 'sit' in the taskbar...

Just an 'is it possible' question for now...no code necessary at this point.  Thanx!
Avatar of Marv-in
Marv-in

yes its possible and pretty easy
quick google search for visual basic systemtray will bring back some code links

here is an ok one:
http://www.tek-tips.com/viewthread.cfm?qid=290478&page=1
Avatar of sirbounty

ASKER

My apologies...not the system tray - I know how to do that.
But the TaskBar.
The new version of MP allows you to show a 'slimmed-down' version of itself in the taskbar.
In other words, right-click the taskbar and click Toolbars - if MP is checked, when you minimize the app, you have the program running, not in the system tray, but minimized to the toolbar.  I hope that explains it better.  If not, let me know.

Right now, my form is invisible and my controls are the same bground color as my title bar and it sits on top, just left of the minimize, restore, and close buttons.  It works okay, but I thought if I could create a toolbar like this, I wouldn't have to worry about the differentiating colors when the background windows lose focus.
I don't know how WMP does it but a toolbar is just a folder that is shown in that area...

I expect you could create a second program, with no forms, just a Sub Main and use SendMessage API call dependant on what you want to do in your form.

The simplest method, I think, would be to set your form's KeyPreview property to true and write a keypress handler within your Form, so that, if 'SHIFT+CTRL+ALT+A' is pressed on your form, something happens, same for 'SHIFT+CTRL+ALT+B', etc:

      Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)

           Select Case True

                Case Shift = (vbShiftMask Or vbAltMask Or vbCtrlMask) And KeyCode = vbKeyA

                     'Do Something

                Case Shift = (vbShiftMask Or vbAltMask Or vbCtrlMask) And KeyCode = vbKeyB
   
                     'Do Something Else

           End Select
   
      End Sub

You'd also need to output the form's Window Handle (myForm.hWnd) to a readable resourse (Temp file, Registry, etc)

Now your second program retrieves the hWnd, parses the Command$ (command parameters) for an action and sends a message:
First declare the SendMessage API:

       Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
                                                                                                         ByVal wMsg As Long, _
                                                                                                         ByVal wParam As Long, _
                                                                                                         lParam As Any) As Long
       Public Const WM_KEYUP As Long = &H101
       Public Const MOD_ALT As Long = &H1
       Public Const MOD_CONTROL As Long = &H2
       Public Const MOD_SHIFT As Long = &H4

       Sub Main()

            Dim hWnd As Long

            'RETRIEVE HWND FROM YOUR CHOSEN STORE
            hWnd = myRetreiveFunction()

            Select Case Ucase(Command)

                 Case "PLAY"  
                      SendMessage hWnd, WM_KEYUP, (MOD_ALT Or MOD_CONTROL Or MOD_SHIFT), vbKeyA

                 Case "STOP"  
                      SendMessage hWnd, WM_KEYUP, (MOD_ALT Or MOD_CONTROL Or MOD_SHIFT), vbKeyB

            End Select

       End Sub

Compile that to ToolbarApp.EXE.  Now all you'd need to do is create your toolbar folder, with pretty icons, to run the program with the parameters;  One icon for ToolBarApp.EXE PLAY and one icon for ToolBarApp.EXE STOP  

Long winded but it should work...

HTH

J.
BTW, I'd output the Form1.hWnd when the form in the Form_Activate() event, in case for some reason, Windows does some manageing...

J.
Oh, and clear the hWnd when the Form is hidden/unloaded -- you don't want the toolbar app to affect any other programs.  You might want to check if the hWnd resource doesn't exist, start the main program...

J.
SOLUTION
Avatar of Shane Russell
Shane Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sirbounty, have we scared you away?  ;-)

J.
No gang - sorry.
Had a 90-hour work week last week and I'm still recovering.
I hope to look at this in the next few days.

Some of this looks promising, and I may have noted that it's currently positioned on the 'title' bar, which looks nice until the window is shrunken/minimized.

Would like to have it on the toolbar where it would 'sit' there and not allow other programs to show up under it, much like WMP's toolbar - you guys know what I'm talking about, right?
I love those 90-hour weeks!!

I've not installed WMP10, I vowed never to use WMP ever again a long time ago.  I hope I'm understanding what you mean by your terms.  Please clarify, so we're on the same page:

Title bar:  The coloured window title, with the icon, minimize, maximize and close button
Task bar:  The area (usually) at the bottom of the screen, where the Start button, Quick Launch, system tray and minimized programs go
Toolbar:  A section of the task bar that can contain icons, changed by right-clicking on the task bar and selecting from the Toolbars submenu (Quick Launch, with Show Desktop, IE and OX icons, is an example)

If you want buttons on the title bar, see http:Q_20149057.html#6275244 -- a great bit of subclassing from Aaron_Young
If you want buttons on the task bar, you could create a toolbar based on my concept above.

HTH

J.
Yep - we're on the same page with that then.
But my 'Title bar' concept isnt' really the title bar, like I said when the window is minimized (any window - cause I've got my app staying on top of all windows...well, that works sometimes...another story :)

And I didn't make a vow against WMP, although I use Winamp at home, our work build contains WMP 9, and if you check it off as a toolbar, it takes up the space of about two running programs, but includes the controls so you don't have to maximize it to operate it (still 'bigger' than Winamp though... :D)

Okay, I will take a look at both your suggestions and "try" to get back to you next week.  I have a 'tentative' install Tuesday (though the server is DOA, so I'm not quite sure how this is going to work) and I have another install on Friday - both out of state.

I will increase the points here though, since both sound like possible and promising solutions...

Thanx!
Did anyone find any leads about how to do this??
I still think you'd need two applications, like my post on 01/31/2005 04:37PM GMT.

J.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I wrote an application that I want to do this with but it is all coded in VB  I attempted to convert the code from the link above to VB from C# but I can't get the following lines to work..

Namespace SampleBars
{
    [Guid("AE07101B-46D4-4a98-AF68-0333EA26E113")]
    [BandObject("Hello World Bar", BandObjectStyle.Horizontal
         | BandObjectStyle.ExplorerToolbar, HelpText = "Shows bar that says hello.")]
    public class HelloWorldBar : BandObject
    {


Here is what I did, the [] represent places where the errors are found


Namespace SampleBars

 <Guid("AE07101B-46D4-4a98-AF68-0333EA26E113")> _
 [1]<BandObject("Hello World Bar", BandObjectStyle.Horizontal Or BandObjectStyle.ExplorerToolbar Or _
       BandObjectStyle.TaskbarToolBar, HelpText="Shows bar that says hello.")> _
 Public Class HelloWorldBar
       [2]Inherits BandObject  

[3] End Class

End Namespace


At [1] error = Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
At [2] error = Statment not valid in a namespace
At [3] error = End Class must follow a preceding Class statement


Has/does anyone know how to convert this code??
It sounds to me as if the second two errors are probably a result of a syntax error on the first line. I'm not sure, but can you try only having one set of square brackets, and delimiting the different attributes with commas like:

 [Guid("AE07101B-46D4-4a98-AF68-0333EA26E113"),
  BandObject("Hello World Bar", BandObjectStyle.Horizontal
         | BandObjectStyle.ExplorerToolbar, HelpText = "Shows bar that says hello.")]

Because I think C# may be interpretting it as an attribute, applied to an attribute. Appart from that the class declarator looks fine, so I'm guessing C#'s just getting stuck on the attributes. (If that doesnt work try putting the | symbol on the previous line like:

 [Guid("AE07101B-46D4-4a98-AF68-0333EA26E113")]
    [BandObject("Hello World Bar", BandObjectStyle.Horizontal |
     BandObjectStyle.ExplorerToolbar, HelpText = "Shows bar that says hello.")]

Hope this helps (but its difficult to work out exactly what error 1 refers to.

Tris
NickOlsen - why are you hijacking my thread here?
Please open a new question for your problem, as it's against site policies to post a new question within a question.
Thanx.
sirbounty -

my fault.  I just tried out the solution you found and was having problems...I figured that maybe you came across the same problem and found a fix.  I acutally did start a thread about this same problem long ago and it never got resolved.  Considering the problem I had is directly related to the solution you gave in c#, I figured you probably had the solution since you were doing the same exact thing I was...I figured you might be able to share your soultion with others that may have run into the same problem that I did.  

I had no malicious intentions of hijacking your thread...just thought more information might be useful to others that weren't having as much success as you were...thats all...sorry

______________________________________
tajmiester -

 I code is actually working fine in c#, but I am trying to convert the c# code into VB (the second send of code in my previous thread) and thats where i get those errors.  If you have any other ideas they would be greatly apprciated, but please direct them to my own thread about this problem to prevent "hijacking".  My thread is at:

https://www.experts-exchange.com/questions/21332766/Code-Conversion-with-a-GUID.html


Thanks!

Nick
No problem - it's just that there may be some confusion here after this is closed, but we can clean that up later.
I didn't post a solution though - I'm looking for one.  I hope to find it here, but honestly haven't been able to look further into this yet.
My last (I hope) 90-100 hour week was last week, just trying to recuperate now.  But the code I'm looking for and hoping was posted was for VB, not C#.
sir bounty, are you trying to get a c# solution for this then ? Also I assume this is for getting windows media player into the task bar, correct ?
I found this, not sure if this is of any help ?

http://www.thecodeproject.com/csharp/NckSingleInstance.asp
I found some freeware, not sure if this helps you out any :

http://www.dirfile.com/freeware/send-to-tray.htm

Dont mind me, I am just researching this as I would be interested in knowing and finding out how to do this myself :)
I found this :

http://library.n0i.net/linux-unix/standards/ex-hints/ar01s05.html

seems to be linux but I wasnt sure about it because it had the WM messages or something to that extent so might give you an idea of what messages you need to research, hopefully !
No - for VB.
My app now sits on the title bar, assuming the window (any window) is maximized.  It blends in nicely, until that window loses focus or is minimized.
I was looking for a way to move it onto the task bar (not the tray)...
Any chance you could send me that so I can see how it is done. If that is ok ?
>> My app now sits on the title bar, assuming the window (any window) is maximized.

Any chance you can send me a screen shot, showing where you have it and where you want it?

J.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial