SetSysColors的参数一些小疑问
Declare Function SetSysColors Lib "user32" Alias "SetSysColors" (ByVal nChanges As Long, lpSysColor As Long, lpColorValues As Long) As Long
COLOR_3DFACECOLOR_3DLIGHTCOLOR_BTNHIGHLIGHTCOLOR_INFOTEXT ' 这个说的是不是ToolTip的文本色?COLOR_MENU '这个对应的是菜单的背景颜色吗?COLOR_3DDKSHADOWCOLOR_3DHILIGHT
'Example Name:System ColorsPrivate Declare Function SetSysColors Lib "user32" (ByVal nChanges As Long, lpSysColor As Long, lpColorValues As Long) As LongPrivate Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As LongConst COLOR_SCROLLBAR = 0 'The Scrollbar colourConst COLOR_BACKGROUND = 1 'Colour of the background with no wallpaperConst COLOR_ACTIVECAPTION = 2 'Caption of Active WindowConst COLOR_INACTIVECAPTION = 3 'Caption of Inactive windowConst COLOR_MENU = 4 'MenuConst COLOR_WINDOW = 5 'Windows backgroundConst COLOR_WINDOWFRAME = 6 'Window frameConst COLOR_MENUTEXT = 7 'Window TextConst COLOR_WINDOWTEXT = 8 '3D dark shadow (Win95)Const COLOR_CAPTIONTEXT = 9 'Text in window captionConst COLOR_ACTIVEBORDER = 10 'Border of active windowConst COLOR_INACTIVEBORDER = 11 'Border of inactive windowConst COLOR_APPWORKSPACE = 12 'Background of MDI desktopConst COLOR_HIGHLIGHT = 13 'Selected item backgroundConst COLOR_HIGHLIGHTTEXT = 14 'Selected menu itemConst COLOR_BTNFACE = 15 'ButtonConst COLOR_BTNSHADOW = 16 '3D shading of buttonConst COLOR_GRAYTEXT = 17 'Grey text, of zero if dithering is used.Const COLOR_BTNTEXT = 18 'Button textConst COLOR_INACTIVECAPTIONTEXT = 19 'Text of inactive windowConst COLOR_BTNHIGHLIGHT = 20 '3D highlight of buttonConst COLOR_2NDACTIVECAPTION = 27 'Win98 only: 2nd active window colorConst COLOR_2NDINACTIVECAPTION = 28 'Win98 only: 2nd inactive window colorPrivate Sub Form_Load() 'KPD-Team 1998 'URL: http://www.allapi.net/ 'E-Mail: KPDTeam@Allapi.net 'Get the caption's active color col& = GetSysColor(COLOR_ACTIVECAPTION) 'Change the active caption's color to red t& = SetSysColors(1, COLOR_ACTIVECAPTION, RGB(255, 0, 0)) MsgBox "The old title bar color was" + Str$(col&) + " and is now" + Str$(GetSysColor(COLOR_ACTIVECAPTION))End Sub
[解决办法]
#include <windows.h>#include <stdio.h>void main(){ int aElements[2] = {COLOR_WINDOW, COLOR_ACTIVECAPTION}; DWORD aOldColors[2]; DWORD aNewColors[2]; // Get the current color of the window background. aOldColors[0] = GetSysColor(aElements[0]); printf("Current window color: {0x%x, 0x%x, 0x%x}\n", GetRValue(aOldColors[0]), GetGValue(aOldColors[0]), GetBValue(aOldColors[0])); // Get the current color of the active caption. aOldColors[1] = GetSysColor(aElements[1]); printf("Current active caption color: {0x%x, 0x%x, 0x%x}\n", GetRValue(aOldColors[1]), GetGValue(aOldColors[1]), GetBValue(aOldColors[1])); // Define new colors for the elements aNewColors[0] = RGB(0x80, 0x80, 0x80); // light gray aNewColors[1] = RGB(0x80, 0x00, 0x80); // dark purple printf("\nNew window color: {0x%x, 0x%x, 0x%x}\n", GetRValue(aNewColors[0]), GetGValue(aNewColors[0]), GetBValue(aNewColors[0])); printf("New active caption color: {0x%x, 0x%x, 0x%x}\n", GetRValue(aNewColors[1]), GetGValue(aNewColors[1]), GetBValue(aNewColors[1])); // Set the elements defined in aElements to the colors defined // in aNewColors SetSysColors(2, aElements, aNewColors); printf("\nWindow background and active border " "have been changed.\n"); printf("Reverting to previous colors in 10 seconds...\n"); Sleep(10000); // Restore the elements to their original colors SetSysColors(2, aElements, aOldColors); }
[解决办法]
Const COLOR_SCROLLBAR = 0Const COLOR_BACKGROUND = 1Const COLOR_ACTIVECAPTION = 2Const COLOR_INACTIVECAPTION = 3Const COLOR_MENU = 4Const COLOR_WINDOW = 5Const COLOR_WINDOWFRAME = 6Const COLOR_MENUTEXT = 7Const COLOR_WINDOWTEXT = 8Const COLOR_CAPTIONTEXT = 9Const COLOR_ACTIVEBORDER = 10Const COLOR_INACTIVEBORDER = 11Const COLOR_APPWORKSPACE = 12Const COLOR_HIGHLIGHT = 13Const COLOR_HIGHLIGHTTEXT = 14Const COLOR_BTNFACE = 15Const COLOR_BTNSHADOW = 16Const COLOR_GRAYTEXT = 17Const COLOR_BTNTEXT = 18Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As LongPrivate Declare Function SetSysColors Lib "user32" (ByVal nChanges As Long, lpSysColor As Long, lpColorValues As Long) As LongDim SavedColors(18) As Long, IndexArray(18) As Long, NewColors(18) As LongPrivate Sub Form_Load() 'KPD-Team 1999 'URL: http://www.allapi.net/ 'E-Mail: KPDTeam@Allapi.net ' Save current system colors: For i = 0 To 18 SavedColors(i) = GetSysColor(i) Next i ' Change all display elements: For i = 0 To 18 Randomize Timer NewColors(i) = RGB(Rnd * 255, Rnd * 255, Rnd * 255) IndexArray(i) = i Next i SetSysColors 19, IndexArray(0), NewColors(0)End SubPrivate Sub Form_Unload(Cancel As Integer) ' Restore system colors: SetSysColors 19, IndexArray(0), SavedColors(0)End Sub