Results 1 to 12 of 12
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VB6 sample - changing screen background (VB6)

    OK. I'm not sure what the protocol is ....

    Attached is an EXE and its source BAS. My first effort at a standalone executable in VB6, so lots of compliments, please (grin!).

    I had earlier a Word97/vba version of this, but it's a pain having a DOT in the Startup folder.

    I have dragged a shortcut to Registry.exe to my Startup, and every time I reboot, a new background colour is generated based on the hours and minutes value of the clock at the time Registry.exe is run. The NEXT time I reboot, the new color takes effect.
    (later) I noticed that registry.exe wasn't working, so I've fixed & recompiled and re-Zipped. If the new attachment hasn't "taken", you'll be getting the old Zip. The new Zip is timestamped 12-30-2001 7:12a)
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VB6 sample - changing screen background (VB6)

    OK, you said what it does, but what is it *for*? Was this just an exercise you set yourself or is there a purpose to it?
    Charlotte

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VB6 sample - changing screen background (VB6)

    Another question is, how do you use it without rebooting, if that's possible? It isn't polite to post an executable without adequate instructions and, if necessary, warnings. Not everyone would want their screen background to change with every reboot, but they might want to see how the thing works.
    Charlotte

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 sample - changing screen background (VB6)

    > Was this just an exercise you set yourself or is there a purpose to it?

    Yes. The purpose of the exercise was to migrate a Word97/VBA appliaction to a standalone VB6 executable. In that it worked.

    I'd like, ultimately, to work out how to implement the colour change in real time, rather than just leaving it in the registry for the next reboot, so that I can tell what time of day it is by looking at the screen.

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 sample - changing screen background (VB6)

    >Another question is, how do you use it without rebooting, if that's possible?

    It's an executable. You execute it, either from the DOS command line within Windows, or as part of some other Windows procedure, such as the Startup group.


    > It isn't polite to post an executable without adequate instructions and, if necessary, warnings.

    I thought I said that, that you drag it to the startup group?


    > Not everyone would want their screen background to change with every reboot, but they might want to see how the thing works.

    Well, there you go. I made the subject line contain the words "screen background" to let people know, and posted the source code. Its really the source code that Forum users would copy and execute themselves to watch it work (or to use as another template for registry work). Those who don't have VB6 and want to try it anyway can do so.

    I chose not to post a warning about the risks of modifying the registry keys; it's my experience that Loungers in the VB forum are well aware of the (in)sanctity of the Registry.

  6. #6
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: VB6 sample - changing screen background (VB6)

    Chris,

    The following code (VB & VBA) will change the background on demand in real time WITHOUT interfering with the registry, so that you default color should remain intact.<pre> Private Declare Function SetSysColors Lib "user32" _
    (ByVal nChanges As Long, _
    lpSysColor As Long, _
    lpColorValues As Long) As Long

    Const COLOR_BACKGROUND = 1

    Public Sub Main()
    Dim retValue As Long
    Dim bytHH As Byte
    Dim bytNN As Byte
    Dim bytSS As Byte

    bytHH = (Format(Now(), "1hh")) ' Hours as two digits
    bytNN = (Format(Now(), "1nn")) ' Minutes as two digits
    bytSS = (Format(Now(), "1ss")) ' seconds as two digits

    retValue = SetSysColors(1, COLOR_BACKGROUND, RGB(bytHH, bytNN, bytSS))

    End Sub</pre>

    I notice that whilst you coded for the third RGB element (i.e. seconds) you opted not to use the value, so you can do the same here by setting bytSS to 0.

    For a random value the following works nicely, but even though the random seed is based on the systen time I suspect you might have difficulty deciphering the time of day from the resultant colour. Or perhaps not in your case <img src=/S/grin.gif border=0 alt=grin width=15 height=15> <pre> retval = SetSysColors(1, COLOR_BACKGROUND, Int((&HFFFFFF * Rnd) + 1))</pre>

    I have a little clock on the taskbar that does a competent job of telling the time of day. You might notice that I append the leading 1 in the actual Format string rather than use concatenation. In your original code you could also have catered for the trailing space by using "1hh " for example. It saves a little typing.

    Andrew C

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 sample - changing screen background (VB6)

    > will change the background on demand in real time WITHOUT interfering with the registry

    Andrew, thanks for this sample.

    I have tried to compile it without success, because "SetSysColors" is not defined. It is almost surely in a library somewhere, which means I need to choose Project, references and add in a reference.

    Two questions:

    1) what particular library should I be adding?

    2) in general, how would I determine which library to add, if I didn't pose a direct question to someone like you? What is the mechanism for locating SetSysColors in all the library files that are floating on my hard drive system?




    >You might notice that I append the leading 1 in the actual Format string rather than use concatenation.

    Thanks too for this "better programming practices" tip. I might have gotten around to that after a few months; I was too excited about making the migration from Word/VBA to VB6/EXE!

  8. #8
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: VB6 sample - changing screen background (VB6)

    Sorry Chris, but I did edit the post to include the API Declaration, omitted in error. You must have taken the code from an email notification as I was prompt enough in rectifying the post. The declaration is :<pre> Private Declare Function SetSysColors Lib "user32" _
    (ByVal nChanges As Long, _
    lpSysColor As Long, _
    lpColorValues As Long) As Long

    Const COLOR_BACKGROUND = 1</pre>

    Andrew

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 sample - changing screen background (VB6)

    > I was prompt enough in rectifying the post.


    ... and until today you had no idea how much I hang on your every word. Most posts are just email notification, but I have set up a system whereby a post from you turns of the VCR, turns down the tea-kettle, and ejects me from my recliner towards the computer. All done in Word97/VBA, soon to be released as an EXE!



    Thanks for the follow-up. I pasted the decl immediately and have a sombre grey screen. I am morose yet delighted.

  10. #10
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 sample - changing screen background (VB6)

    > Lib "user32"


    Now suppose you weren't around. How should I have worked out that User32 was the library i wanted? Is there a reference somewhere that tells me this?

  11. #11
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: VB6 sample - changing screen background (VB6)

    Chris,

    If you do not know about it already, <A target="_blank" HREF=http://www.allapi.net/>All API Network</A> is a good source of information on all things API. You can download a guide which is very useful, and allows you to search for functions, constants etc. If this gets you out of your recliner, I'm sure you will find it worthwhile. I suspect it might keep you busy for a while.

    Andrew

  12. #12
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 sample - changing screen background (VB6)

    >a good source of information on all things API.

    Thank you! I had forgotten that. I had it installed on my old machine. I'll grab a fresh copy.

    It is indeed a wonderful device for peaople like me .....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •