Hej, Det finns ett program som heter RedGreenBlue som man kan ladda ner gratis på http://www.softwolves.pp.se/sw/. För att översätta till HTML skall du vända på Hexkoden från int till hex Din färgkod är vbButtonFace. Vilket hämtar RGB värdet från windows. Sven jag tror du har fel. Oki på det. Jag har skrivit tre funktioner som kan hjälpa dig. <b>VB skriver bakvänt av någon underlig anledning.</b> För att det är sättet som färgerna sparas; röd är på de lägre bitarna, blå är på de högre.Färgkoder
Jag har frågor ang. färgkoder. Om jag i VB6 i properties t.ex. har: Backcolor &H8000000F&. Hur översätter jag detta till HTML färgkod #XXYYZZ och till RGB-värden? Kan någon hjälpa mig med detta? Sv: Färgkoder
/MariaSv:Färgkoder
Ex. i Vb står det C0 FE A4 då blir det HTML #A4FEC0
VB skriver bakvänt av någon underlig anledning.Sv: Färgkoder
<code=vb>
myNumber = 255
myHex = hex(myNumber) ' myHex blir då FF
</code>
från hex till int
<code=vb>
myHex = "FF"
myNumber = int("&HFF") ' myNumber blir då 255 (jag kan vara lite fel ute här, ett bra tag sedan jag gjorde detta..)
</code>Sv: Färgkoder
För att få fram RGB-värdet anropar du OleTranslateColor:
Private Const S_OK As Long = &H0
Private Declare Function OleTranslateColor Lib "oleaut32.dll" ( _
ByVal lOleColor As Long, _
ByVal lHPalette As Long, _
lColorRef As Long) As Long
Public Function getRGB(Color As OLE_COLOR) As OLE_COLOR
If OleTranslateColor(Color, 0, getRGB) <> S_OK Then
Err.Raise 5, "getRGB", "Invalid procedure call or argument"
End If
End Function
I CSS motsvarar detta: buttonface
http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
Sv:Färgkoder
Du ser du den mest signifikanta byten är 80: &H<b>80</b>00000F&.
För en COLORREF/OLE_COLOR innebär 0x800000xx, att xx is a valid GetSysColor index
Med andra ord xx kan vara ett av följande:
<info>
Value Meaning
COLOR_3DDKSHADOW 21 Dark shadow for three-dimensional display elements.
COLOR_3DFACE 15 Face color for three-dimensional display elements and for dialog box backgrounds.
COLOR_3DHIGHLIGHT 20 Highlight color for three-dimensional display elements (for edges facing the light source.)
COLOR_3DHILIGHT 20 Highlight color for three-dimensional display elements (for edges facing the light source.)
COLOR_3DLIGHT 22 Light color for three-dimensional display elements (for edges facing the light source.)
COLOR_3DSHADOW 16 Shadow color for three-dimensional display elements (for edges facing away from the light source).
COLOR_ACTIVEBORDER 10 Active window border.
COLOR_ACTIVECAPTION 2 Active window title bar. Specifies the left side color in the color gradient of an active window's title bar if the gradient effect is enabled.
COLOR_APPWORKSPACE 12 Background color of multiple document interface (MDI) applications.
COLOR_BACKGROUND 1 Desktop.
COLOR_BTNFACE 15 Face color for three-dimensional display elements and for dialog box backgrounds.
COLOR_BTNHIGHLIGHT 20 Highlight color for three-dimensional display elements (for edges facing the light source.)
COLOR_BTNHILIGHT 20 Highlight color for three-dimensional display elements (for edges facing the light source.)
COLOR_BTNSHADOW 16 Shadow color for three-dimensional display elements (for edges facing away from the light source).
COLOR_BTNTEXT 18 Text on push buttons.
COLOR_CAPTIONTEXT 9 Text in caption, size box, and scroll bar arrow box.
COLOR_DESKTOP 1 Desktop.
COLOR_GRADIENTACTIVECAPTION 27 Right side color in the color gradient of an active window's title bar.
COLOR_GRADIENTINACTIVECAPTION 28 Right side color in the color gradient of an inactive window's title bar.
COLOR_GRAYTEXT 17 Grayed (disabled) text. This color is set to 0 if the current display driver does not support a solid gray color.
COLOR_HIGHLIGHT 13 Item(s) selected in a control.
COLOR_HIGHLIGHTTEXT 14 Text of item(s) selected in a control.
COLOR_HOTLIGHT 26 Color for a hyperlink or hot-tracked item.
COLOR_INACTIVEBORDER 11 Inactive window border.
COLOR_INACTIVECAPTION 3 Inactive window caption. Specifies the left side color in the color gradient of an inactive window's title bar if the gradient effect is enabled.
COLOR_INACTIVECAPTIONTEXT 19 Color of text in an inactive caption.
COLOR_INFOBK 24 Background color for tooltip controls.
COLOR_INFOTEXT 23 Text color for tooltip controls.
COLOR_MENU 4 Menu background.
COLOR_MENUHILIGHT 29 The color used to highlight menu items when the menu appears as a flat menu (see SystemParametersInfo).
COLOR_MENUBAR 30 The background color for the menu bar when menus appear as flat menus (see SystemParametersInfo).
COLOR_MENUTEXT 7 Text in menus.
COLOR_SCROLLBAR 0 Scroll bar gray area.
COLOR_WINDOW 5 Window background.
COLOR_WINDOWFRAME 6 Window frame.
COLOR_WINDOWTEXT 8 Text in windows.
</info>
Det är alltså inte ett RGB värde utan ett index till ett system färg.
Om det varit ett RGB värde så har det formatet 0x00bbggrr, där rr är det röda värdet, gg det gröna värdet och bb det blåa värdet. T.ex. grått: &H<b>00</b>C0C0C0&
Ditt påstående att: &H8000000F& = #0F0000 är bara sant om användaren ställt in mörkröd(#0F0000, Röd= 16, Grön = 0 och Blå = 0 det vill säga en mycket mörk röd färg) som ButtonFace färg på sitt operativ system(windows).
http://msdn.microsoft.com/library/en-us/com/html/f4b407c3-e88a-47b4-bb43-8f691629d2f3.aspSv: Färgkoder
Därför använder jag aldrig SystemColor.
Tycker det känns tryggare att köra med gamla RGB:koden (Palette) då vet jag vad jag får.
Då blir svar på hans fråga #D4D0C8Sv: Färgkoder
Funktionen OleColorToRGB(Color As OLE_COLOR) översätter/delar upp vilken RGB-/systemfärg till ett RGB-värde.
Funktionen RGBToCSS(Red As Byte, Green As Byte, Blue As Byte) översätter ett RGB värde till CSS-RGB-färgkod.
Funktionen OleColorToCSS(Color As OLE_COLOR) översätter en RGB- /systemfärg till CSS-RGB-färgkod.
Option Explicit
Private Const HexString As String = _
"000102030405060708090a0b0c0d0e0f" + _
"101112131415161718191a1b1c1d1e1f" + _
"202122232425262728292a2b2c2d2e2f" + _
"303132333435363738393a3b3c3d3e3f" + _
"404142434445464748494a4b4c4d4e4f" + _
"505152535455565758595a5b5c5d5e5f" + _
"606162636465666768696a6b6c6d6e6f" + _
"707172737475767778797a7b7c7d7e7f" + _
"808182838485868788898a8b8c8d8e8f" + _
"909192939495969798999a9b9c9d9e9f" + _
"a0a1a2a3a4a5a6a7a8a9aaabacadaeaf" + _
"b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" + _
"c0c1c2c3c4c5c6c7c8c9cacbcccdcecf" + _
"d0d1d2d3d4d5d6d7d8d9dadbdcdddedf" + _
"e0e1e2e3e4e5e6e7e8e9eaebecedeeef" + _
"f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"
Private Const S_OK As Long = &H0
Public Type RGBQUAD
Blue As Byte
Green As Byte
Red As Byte
Reserved As Byte
End Type
Private Declare Function OleTranslateColor Lib "oleaut32.dll" ( _
ByVal lOleColor As Long, _
ByVal lHPalette As Long, _
ByRef lColorRef As Any) As Long
Public Function OleColorToRGB(Color As OLE_COLOR) As RGBQUAD
If OleTranslateColor(Color, 0&, OleColorToRGB) <> S_OK Then
Err.Raise 5, "getRGB", "Invalid procedure call or argument"
End If
End Function
Public Function RGBToCSS(Red As Byte, Green As Byte, Blue As Byte) As String
RGBToCSS = "#" + Mid$(HexString, 1 + 2 * Red, 2) + _
Mid$(HexString, 1 + 2 * Green, 2) + _
Mid$(HexString, 1 + 2 * Blue, 2)
End Function
Public Function OleColorToCSS(Color As OLE_COLOR) As String
Dim rgb As RGBQUAD
rgb = OleColorToRGB(Color)
OleColorToCSS = RGBToCSS(rgb.Red, rgb.Green, rgb.Blue)
End Function
Sv: Färgkoder
Nån som vet varför VB6 skriver hex-färgkod baklänges?
ThomasSv:Färgkoder