首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

SetSysColors的参数一些小疑问解决思路

2012-02-22 
SetSysColors的参数一些小疑问VB codeDeclare Function SetSysColors Lib user32 Alias SetSysColors

SetSysColors的参数一些小疑问

VB code
Declare Function SetSysColors Lib "user32" Alias "SetSysColors" (ByVal nChanges As Long, lpSysColor As Long, lpColorValues As Long) As Long


[color=#99CCFF]1[/color]首先是后面两个参数的问题,当设置多个颜色的时候,API说明是要用数组的第一个参数,这个没理解到,希望能给个例子11
[color=#99CCFF]2[/color]最后一个参数用的是什么形式的颜色? 像&H00FFC0C0&这种格式的还是?
[color=#99CCFF]3[/color]最后就是一些常数,有的光看说明还是弄不清,
VB code
COLOR_3DFACECOLOR_3DLIGHTCOLOR_BTNHIGHLIGHTCOLOR_INFOTEXT ' 这个说的是不是ToolTip的文本色?COLOR_MENU '这个对应的是菜单的背景颜色吗?COLOR_3DDKSHADOWCOLOR_3DHILIGHT

感谢各位热心人士的来到,不管你们是不是来回答问题的

[解决办法]
【操作系统】
Win9X:Yes
WinNT:Yes
【说明】
设置指定窗口显示对象的颜色 
【返回值】
Long,非零表示成功,零表示失败。会设置GetLastError 
【其它】
【参数表】
nChanges ------- Long,欲改变的对象的数量
lpSysColor ----- Long,按引用传递。这是一个整数数组(总共包含nChanges个元素)的第一个元素。每个条目都包含了一个常数,指定一个windows显示对象。参考GetSysColor函数
lpColorValues -- Long,按引用传递。这是RGB值数组的第一个元素;该数组用于设置lpSysColor数组中的对象颜色

Public Declare Function SetSysColors Lib "user32" (ByVal nChanges As Long, lpSysColor As Long, lpColorValues As Long) As Long

[解决办法]
VB code
'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
[解决办法]
探讨
引用:

VB code

'Example Name:System Colors
Private Declare Function SetSysColors Lib "user32" (ByVal nChanges As Long, lpSysColor As Long, lpColorValues As Long) As Long
Private ……

------解决方案--------------------


MSDN源代码:

C/C++ code
#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); }
[解决办法]
VB code
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 

热点排行