challenge?

A

anthony

this one is really a challenge to me.

the application i developed in VB.NET 2003 runs on marine boat, the
application has many screens and controls. On a marine boat at night, only
dark cyan (or similar) color must be used on display (much like the radar
display) otherwise the captain will be blinded by the bright colors.

When at night, the user clicks on a button to turn the application into
night mode. I do not want to go through all the objects (over 1000) to
change each color, I am thinking that maybe I can change the palette of
Windows or VB, the computer they are using is designated to run my
application only, so it will not affect other application.

Is there a way i can change for example the definition of
SystemColors.Control.Yellow to SystemColors.Control.DarkCyan at night mode
and return to normal on day mode?


Thanks in advance.
 
L

Larry Lard

anthony said:
this one is really a challenge to me.

the application i developed in VB.NET 2003 runs on marine boat, the
application has many screens and controls. On a marine boat at night, only
dark cyan (or similar) color must be used on display (much like the radar
display) otherwise the captain will be blinded by the bright colors.

When at night, the user clicks on a button to turn the application into
night mode. I do not want to go through all the objects (over 1000) to
change each color, I am thinking that maybe I can change the palette of
Windows or VB, the computer they are using is designated to run my
application only, so it will not affect other application.

Is there a way i can change for example the definition of
SystemColors.Control.Yellow to SystemColors.Control.DarkCyan at night mode
and return to normal on day mode?

Given that your app has sole use of the PC, sounds like the easiest way
would be to make sure all your controls use SystemColors, then change
the *global* Windows colour scheme (you know, where you set what colour
title bars and stuff are). I just did a quick test and a VB.NET 2002
app running on Win2k changes colours *automatically* when the Windows
colour scheme changes, so you should be alright.

Now the question becomes how to change that Windows setting? I suspect
it will involve P/Invoke'ing the API, but I don't expect it to be
particularly difficult. You can find this yourself, or you want more?
 
L

Larry Lard

Larry said:
1000) palette night

Given that your app has sole use of the PC, sounds like the easiest way
would be to make sure all your controls use SystemColors, then change
the *global* Windows colour scheme (you know, where you set what colour
title bars and stuff are). I just did a quick test and a VB.NET 2002
app running on Win2k changes colours *automatically* when the Windows
colour scheme changes, so you should be alright.

Now the question becomes how to change that Windows setting? I suspect
it will involve P/Invoke'ing the API, but I don't expect it to be
particularly difficult. You can find this yourself, or you want more?

[replying to self]
(it's SetSysColor but...)
Actually, why re-invent the wheel? Just make sure your app uses only
SystemColor's for its colours, then the user can just use Control Panel
| Display to switch to a night-time scheme at night, and (as I have
established) your app will switch automatically.
 
J

jo0ls

this one is really a challenge to me.

the application i developed in VB.NET 2003 runs on marine boat, the
application has many screens and controls. On a marine boat at night,
only dark cyan (or similar) color must be used on display (much like
the radar display) otherwise the captain will be blinded by the bright
colors.

When at night, the user clicks on a button to turn the application
into night mode. I do not want to go through all the objects (over
1000) to change each color, I am thinking that maybe I can change the
palette of Windows or VB, the computer they are using is designated to
run my application only, so it will not affect other application.

Is there a way i can change for example the definition of
SystemColors.Control.Yellow to SystemColors.Control.DarkCyan at night
mode and return to normal on day mode?


Thanks in advance.

See getsyscolors and setsyscolors in the library (Platform SDK), not sure
how to use it. I'll have a go...
 
A

anthony

Thanks Larry,

Do you know which API to invoke? GDI+ or DirectX API or sth else...?
 
A

anthony

I actually have to place a button or menu item on my application to do so, I
would have a hard time to explain what a Windows Control Panel to the boat
user/captain, so a one-click way is essental, I will look at the SetSysColor
you suggest.

Thanks!



Larry Lard said:
Larry said:
1000) palette night

Given that your app has sole use of the PC, sounds like the easiest way
would be to make sure all your controls use SystemColors, then change
the *global* Windows colour scheme (you know, where you set what colour
title bars and stuff are). I just did a quick test and a VB.NET 2002
app running on Win2k changes colours *automatically* when the Windows
colour scheme changes, so you should be alright.

Now the question becomes how to change that Windows setting? I suspect
it will involve P/Invoke'ing the API, but I don't expect it to be
particularly difficult. You can find this yourself, or you want more?

[replying to self]
(it's SetSysColor but...)
Actually, why re-invent the wheel? Just make sure your app uses only
SystemColor's for its colours, then the user can just use Control Panel
| Display to switch to a night-time scheme at night, and (as I have
established) your app will switch automatically.
 
B

Bob

Just an idea, why not cut the wire to the monitor and install a switch that cuts or attenuates the
blue and green pins' signals? I'm not familiar with marine standards, but I know that red is a good
color for not affecting night vision. Not exactly a software solution, but it's also the simplest
and most general... I also happen to know it works from when I had to use a monitor with a bad blue
pin. The captain may also appreciate a nice beefy physical switch instead of having to shade the
monitor in full sunlight to be able to see it well enough to get it out of night mode.

Robert
 
C

Chris, Master of All Things Insignificant

You could cycle through the controls collection of the form and modify all
the controls that way. If you do it static this way you only have to check
if the control is a type you want to change. Have every form pass in it's
controls and you have it solved with only writing one function.

Public Class ColorChange
Pulblic Static Sub NightMode(byref Ctrs as Collection)
dim Ctr as Control
For each ctr in ctrs
if ctr typeof ...... then 'forget the code to check if the type
is the same

end if
next
End Sub
End Class

Hope it helps some..
Chris
 
A

anthony

Thanks for all your suggestions, I am trying each one right now, I found the
API working like this:

Private Declare Function SetSysColors Lib "user32" _

(ByVal nChanges As Integer, ByRef lpSysColor As Integer, ByRef lpColorValues
As Integer) As Integer

Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As
Long

Const COLOR_SCROLLBAR = 0 'The Scrollbar colour

Const COLOR_BACKGROUND = 1 'Colour of the background with no wallpaper

Const COLOR_ACTIVECAPTION = 2 'Caption of Active Window

Const COLOR_INACTIVECAPTION = 3 'Caption of Inactive window

Const COLOR_MENU = 4 'Menu

Const COLOR_WINDOW = 5 'Windows background

Const COLOR_WINDOWFRAME = 6 'Window frame

Const COLOR_MENUTEXT = 7 'Window Text

Const COLOR_WINDOWTEXT = 8 '3D dark shadow (Win95)

Const COLOR_CAPTIONTEXT = 9 'Text in window caption

Const COLOR_ACTIVEBORDER = 10 'Border of active window

Const COLOR_INACTIVEBORDER = 11 'Border of inactive window

Const COLOR_APPWORKSPACE = 12 'Background of MDI desktop

Const COLOR_HIGHLIGHT = 13 'Selected item background

Const COLOR_HIGHLIGHTTEXT = 14 'Selected menu item

Const COLOR_BTNFACE = 15 'Button

Const COLOR_BTNSHADOW = 16 '3D shading of button

Const COLOR_GRAYTEXT = 17 'Grey text, of zero if dithering is used.

Const COLOR_BTNTEXT = 18 'Button text

Const COLOR_INACTIVECAPTIONTEXT = 19 'Text of inactive window

Const COLOR_BTNHIGHLIGHT = 20 '3D highlight of button

Const COLOR_2NDACTIVECAPTION = 27 'Win98 only: 2nd active window color

Const COLOR_2NDINACTIVECAPTION = 28 'Win98 only: 2nd inactive window color

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim col As Long, t As Long

'Get the caption's active color

col = GetSysColor(COLOR_BACKGROUND)

'Change the active caption's color to red

t = SetSysColors(1, COLOR_BACKGROUND, RGB(255, 0, 0))

MsgBox("The old title bar color was" + Str$(col) + " and is now" +
Str$(GetSysColor(COLOR_ACTIVECAPTION)))

End Sub
 
J

Jay B. Harlow [MVP - Outlook]

Anthony,
The definitions should be:

Private Declare Function SetSysColors Lib "user32" _
(ByVal nChanges As Integer, ByVal lpSysColor() As Integer, _
ByVal lpColorValues() As Integer) As Boolean

Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As
Integer) _
As Integer

Rather then use a list of disparate constants for an API, I normally create
an Enum, something like:

Public Enum SystemColor As Integer
ScrollBar = 0 'The Scrollbar colour
BackGround = 1 'Colour of the background with no wallpaper
ActiveCaption = 2 'Caption of Active Window
InactiveCaption = 3 'Caption of Inactive window
Menu = 4 'Menu
Window = 5 'Windows background
WindowFrame = 6 'Window frame
MenuText = 7 'Window Text
WindowText = 8 '3D dark shadow (Win95)
CaptionText = 9 'Text in window caption
ActiveBorder = 10 'Border of active window
InactiveBorder = 11 'Border of inactive window
AppWorkspace = 12 'Background of MDI desktop
Highlight = 13 'Selected item background
HighlightText = 14 'Selected menu item
BtnFace = 15 'Button
BtnShadow = 16 '3D shading of button
GrayText = 17 'Grey text, of zero if dithering is used.
BtnText = 18 'Button text
InactiveCaptionText = 19 'Text of inactive window
BtnHightList = 20 '3D highlight of button
SecondActiveCatpion = 27 'Win98 only: 2nd active window color
SecondInactiveCaption = 28 'Win98 only: 2nd inactive window color
End Enum

Private Declare Function SetSysColors Lib "user32" (ByVal nChanges As
Integer, ByVal lpSysColor() As SystemColor, ByVal lpColorValues() As
Integer) As Integer

Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As
SystemColor) As Integer

As this gives intellisense on the API call itself, and neatly encapsulates
the constants in a single type...

Hope this helps
Jay
 
C

Chris Dunaway

It's a shame that the values for the KnownColor enumeration in
System.Drawing do not match those required for the SetSysColors
function. Then you wouldn't have had to create your own enum.
 
J

Jay B. Harlow [MVP - Outlook]

Chris,
Unfortunately KnownColor has significantly more values then what
SetSysColors expects, even if the "system color" subrange of KnownColor
matched, there would be too great a chance of sending invalid arguments to
SetSysColors if you used the KnownColor enum directly!

Or were you thinking of defining the SystemColor enum in terms of
KnownColor?

' This will not work correctly! for the reason you gave
Public Enum SystemColor As Integer
ScrollBar = KnownColor.ScrollBar
...
End Enum

I use the define my enum in terms of another enum when it makes sense, for
example defining a class library that encapsulates a COM object, if I need
to "expose" one of the COM object's enums, I will define my enum in terms of
the COM object's enum, to prevent consumers of my class library from being
coupled to the COM class library also...

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top