#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Program.ico #AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;~ #Tidy_Parameters=/sf #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #Region globals Global Const _ $CV_COLOURSDIR = @TempDir & '\CV\', _ ;_ dir for the au3 files $CV_BMPHEIGHT = 148, _ ;_ pic and label control height $CV_BMPWIDTH = 180, _ ;_ pic and label control width $CV_RECTHEIGHT = $CV_BMPHEIGHT - 2, _ ;_ height for gdi+ image $CV_RECTWIDTH = $CV_BMPWIDTH - 2, _ ;_ width for gdi+ image $CV_ARGBMAXRANGE = 255, _ ;_ max amount for the alpha channel $CV_RGB = 'RGB', _ ;_ text for buttons and groups $CV_BGR = 'BGR', _ ;_ "" $CV_ARGB = 'ARGB', _ ;_ "" $CV_BGRA = 'BGRA', _ ;_ "" $CV_HEXN = '0x', _ ;_ hex notation $CV_ALPHA = 'FF' ;_ default alpha channel value Global Enum _ $CV_CONSTCOL, _ ;_ constant column in the $g_aColours array $CV_HEXCOL, _ ;_ hex code column in the $g_aColours array $CV_NAMECOL ;_ colour name column in the $g_aColours array Global _ $g_aColours = 0, _ ; _ array for colour consts, hex codes and names $g_hARGBBmp = 0, _ ; _ handle for the bitmap object $g_sColourFmt = $CV_RGB, _ ; _ current format for hex values. RGB or BGR $g_sRGBHexValue = -1 ; _ #EndRegion globals CV_ProgramStartup() ; initialise gdi+ #Region gui Global $g_hGui = GUICreate('Colour Viewer', 491, 377, 698, 289) GUISetIcon('V:\AutoIt\Colour Viewer\Program.ico', -1) GUICtrlCreateGroup('Colours', 8, 8, 475, 124) GUICtrlCreateLabel('Colour Constants', 16, 32, 90, 17) #Region au3 ; displays the total number of files inside $CV_COLOURSDIR Global $g_idAu3Count_lbl = GUICtrlCreateLabel('0', 95, 32, 30, 17, $SS_CENTER) GUICtrlSetColor(-1, $COLOR_RED) ; select an au3 file with the colour constants Global $idAu3Select_cbo = GUICtrlCreateCombo('', 128, 30, 217, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL)) _GUICtrlComboBox_SetCueBanner(-1, 'Select') ; open the selected au3 file Global $g_idAu3Open_btn = GUICtrlCreateButton('...', 355, 28, 25, 25, $BS_ICON) GUICtrlSetImage(-1, 'C:\Windows\System32\shell32.dll', -56, 0) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetTip(-1, 'View file') GUICtrlCreateLabel('Colour Names', 16, 64, 70, 17) ; displays the total number of colour names in the selected au3 file Global $g_idColourNameCount_lbl = GUICtrlCreateLabel('0', 95, 64, 30, 17, $SS_CENTER) GUICtrlSetColor(-1, $COLOR_RED) ; displays the names listed in the au3 file Global $g_hColourNames_Cbo = _GUICtrlComboBoxEx_Create($g_hGui, '', 127, 61, 220, 200, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL)) _GUICtrlComboBox_SetCueBanner($g_hColourNames_Cbo, 'Select') CV_SetComboBoxState($g_hColourNames_Cbo) ; opens a colour picker dialog Global $g_idColourPicker_btn = GUICtrlCreateButton('...', 355, 60, 25, 25, $BS_ICON) GUICtrlSetImage(-1, 'C:\Windows\System32\shell32.dll', -131, 0) GUICtrlSetTip(-1, 'Choose colour') GUICtrlCreateLabel('Global Constant', 16, 96, 79, 17) ; displays the global const name for the selected color name Global $g_idConstName_lbl = GUICtrlCreateLabel('', 127, 96, 220, 17, BitOR($SS_CENTER, $SS_SUNKEN)) ; copies the constant name to the clipboard Global $g_idConstCopy_btn = GUICtrlCreateButton('...', 355, 93, 25, 25, $BS_ICON) GUICtrlSetImage(-1, 'C:\Windows\System32\shell32.dll', -261, 0) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetTip(-1, 'Copy variable name') GUICtrlCreateGroup('', -99, -99, 1, 1) #EndRegion au3 ;~ #cs #Region triplets GUICtrlCreateGroup('Triplets', 392, 20, 80, 102) GUICtrlCreateLabel('R', 400, 40, 12, 17) GUICtrlSetColor(-1, 0xFF0000) Global $g_idRTriplet_inp = GUICtrlCreateInput('', 416, 38, 35, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_READONLY)) GUICtrlSetBkColor(-1, $COLOR_WHITE) GUICtrlSetLimit(-1, 3) GUICtrlSetCursor(-1, $MCID_HAND) GUICtrlSetTip(-1, 'Select to copy r ,g, b string clipboard') GUICtrlCreateLabel('G', 400, 65, 12, 17) GUICtrlSetColor(-1, 0x008000) Global $g_idGTriplet_inp = GUICtrlCreateInput('', 416, 63, 35, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_READONLY)) GUICtrlSetBkColor(-1, $COLOR_WHITE) GUICtrlSetLimit(-1, 3) GUICtrlSetCursor(-1, $MCID_HAND) GUICtrlSetTip(-1, 'Select to copy r ,g, b string clipboard') GUICtrlCreateLabel('B', 400, 90, 11, 17) GUICtrlSetColor(-1, 0x0000FF) Global $g_idBTriplet_inp = GUICtrlCreateInput('', 416, 88, 35, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_READONLY)) GUICtrlSetBkColor(-1, $COLOR_WHITE) GUICtrlSetLimit(-1, 3) GUICtrlSetCursor(-1, $MCID_HAND) GUICtrlSetTip(-1, 'Select to copy r ,g, b string clipboard') GUICtrlCreateGroup('', -99, -99, 1, 1) #EndRegion triplets ;~ #ce #Region rgb Global $g_idRGB_grp = GUICtrlCreateGroup($CV_RGB, 8, 137, 200, 224) GUICtrlCreateLabel($CV_HEXN, 16, 162, 15, 17, $SS_RIGHT) ; input for the rgb hext colour code Global $g_idRGBHex_inp = GUICtrlCreateInput('', 33, 159, 75, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_UPPERCASE)) GUICtrlSetLimit(-1, 6) GUICtrlCreateLabel('Switch', 116, 162, 31, 17) ; changes the colour format between RGB and BGR probably a useless addition) Global $g_idRGBFormat_btn = GUICtrlCreateButton($CV_BGR, 155, 157, 40, 25) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetTip(-1, 'Switch colour modes') ; displays the colour associated with the code in $g_idRGBHex_inp Global $g_idRGBColour_lbl = GUICtrlCreateLabel('', 16, 198, $CV_BMPWIDTH, $CV_BMPHEIGHT, -1, $WS_EX_STATICEDGE) GUICtrlCreateGroup('', -99, -99, 1, 1) #EndRegion rgb #Region argb Global $g_idARGB_grp = GUICtrlCreateGroup($CV_ARGB, 216, 137, 267, 224) GUICtrlCreateLabel($CV_HEXN, 224, 162, 15, 17, $SS_RIGHT) ; displays the argb hex code associated with the code in $g_idRGBHex_inp #777777 Global $g_idARGBHex_inp = GUICtrlCreateInput('', 241, 159, 75, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_READONLY, $ES_UPPERCASE)) GUICtrlSetLimit(-1, 8) GUICtrlSetBkColor(-1, $COLOR_WHITE) ; copies the hex code from $g_idARGBHex_inp Global $g_idARGBCopyHex_btn = GUICtrlCreateButton('...', 324, 157, 25, 25, $BS_ICON) GUICtrlSetImage(-1, 'C:\Windows\System32\shell32.dll', -261, 0) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetTip(-1, 'Copy hex code') ; displays the colour associated with the code in $g_idARGBHex_inp Global $g_idARGBColour_pic = GUICtrlCreatePic('', 224, 198, $CV_BMPWIDTH, $CV_BMPHEIGHT, -1, $WS_EX_STATICEDGE) GUICtrlCreateGroup('Opacity %', 412, 152, 60, 195, BitOR($GUI_SS_DEFAULT_GROUP, $BS_RIGHT)) ; allows manual alteration of the colours transparency Global $g_idARGBOpacity_inp = GUICtrlCreateInput('100', 420, 174, 45, 17, $SS_CENTER, $WS_EX_STATICEDGE) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetCursor(-1, $MCID_HAND) GUICtrlSetTip(-1, 'Set the opacity percent') ; set the opacity level for the argb colour in $g_idARGBColour_pic Global $g_idARGBOpacity_sld = GUICtrlCreateSlider(423, 196, 38, 142, BitOR($GUI_SS_DEFAULT_SLIDER, $TBS_VERT, $TBS_TOP, $TBS_LEFT, $TBS_FIXEDLENGTH, $TBS_TOOLTIPS)) GUICtrlSetLimit(-1, $CV_ARGBMAXRANGE, 0) GUICtrlSetData(-1, $CV_ARGBMAXRANGE) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetTip(-1, 'Set the opacity level') GUICtrlCreateGroup('', -99, -99, 1, 1) GUICtrlCreateGroup('', -99, -99, 1, 1) #EndRegion argb GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND') GUIRegisterMsg($WM_VSCROLL, 'WM_VSCROLL') GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ;~ CV_InstallAu3() ;_ copy the constant files CV_LoadAu3() ;_ load the au3 files ; to do ; ### argb hex input find a way to work with BGRA colours. Currently shows wrong colour possible? ; ### maybe switch to ex combo for au3 files and add images While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE CV_ExitProgram() Case $idAu3Select_cbo CV_LoadColourArray() Case $g_idAu3Open_btn If FileExists($CV_COLOURSDIR & '\' & GUICtrlRead($idAu3Select_cbo) & '.au3') Then _ ShellExecute($CV_COLOURSDIR & '\' & GUICtrlRead($idAu3Select_cbo) & '.au3') Case $g_idColourPicker_btn CV_LoadUserColour() Case $g_idConstCopy_btn ClipPut(GUICtrlRead($g_idConstName_lbl)) TrayTip('Clipboard Notification', 'Constant copied to clipboard', 5) Case $g_idRGBFormat_btn CV_RGBtoBGR() Case $g_idARGBCopyHex_btn ClipPut($CV_HEXN & GUICtrlRead($g_idARGBHex_inp)) TrayTip('Clipboard Notification', 'Hex value copied to clipboard', 5) Case $g_idARGBOpacity_inp CV_SetARGBOpacityLevel() EndSwitch WEnd Func CV_CalculateOpacityPcent() Return Round((GUICtrlRead($g_idARGBOpacity_sld) / $CV_ARGBMAXRANGE) * 100) EndFunc ;==>CV_CalculateOpacityPcent Func CV_CopyRGBTriplets() Local $iR = GUICtrlRead($g_idRTriplet_inp) Local $iG = GUICtrlRead($g_idGTriplet_inp) Local $iB = GUICtrlRead($g_idBTriplet_inp) ClipPut(($g_sColourFmt = $CV_RGB) ? (StringFormat('%i, %i, %i', $iR, $iG, $iB)) : (StringFormat('%i, %i, %i', $iB, $iG, $iR))) TrayTip('Clipboard Notification', 'Triplets copied to clipboard', 5) EndFunc ;==>CV_CopyRGBTriplets Func CV_CreateARGBBitmap($iColour) Local $hImage = _GDIPlus_BitmapCreateFromScan0($CV_RECTWIDTH, $CV_RECTHEIGHT) Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) Local $hBrush = _GDIPlus_BrushCreateSolid($iColour) _GDIPlus_GraphicsClear($hGraphic, $iColour) _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $CV_RECTWIDTH, $CV_RECTHEIGHT, $hBrush) _GDIPlus_BrushDispose($hBrush) _WinAPI_DeleteObject(GUICtrlSendMsg($g_idARGBColour_pic, $STM_SETIMAGE, 0, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage))) _GDIPlus_BitmapDispose($hImage) _GDIPlus_GraphicsDispose($hGraphic) ; Dispose and recreate the HBITMAP If IsPtr($g_hARGBBmp) Then _WinAPI_DeleteObject($g_hARGBBmp) Local $hBmp = _GDIPlus_BitmapCreateFromScan0($CV_RECTWIDTH, $CV_RECTHEIGHT) $g_hARGBBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp, $iColour) _GDIPlus_BitmapDispose($hBmp) EndFunc ;==>CV_CreateARGBBitmap Func CV_CreateCheckerboardBitmap($width, $height, $checkerSize) Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($width, $height) Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap) Local $hBrush1 = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) ; White Local $hBrush2 = _GDIPlus_BrushCreateSolid(0xFFC2C6C3) ; Black For $y = 0 To $height - 1 Step $checkerSize For $x = 0 To $width - 1 Step $checkerSize If Mod($x / $checkerSize + $y / $checkerSize, 2) = 0 Then _GDIPlus_GraphicsFillRect($hGraphics, $x, $y, $checkerSize, $checkerSize, $hBrush1) Else _GDIPlus_GraphicsFillRect($hGraphics, $x, $y, $checkerSize, $checkerSize, $hBrush2) EndIf Next Next _GDIPlus_BrushDispose($hBrush1) _GDIPlus_BrushDispose($hBrush2) _GDIPlus_GraphicsDispose($hGraphics) Return $hBitmap EndFunc ;==>CV_CreateCheckerboardBitmap Func CV_ExitProgram() _WinAPI_DeleteObject($g_hARGBBmp) _GDIPlus_Shutdown() Exit EndFunc ;==>CV_ExitProgram Func CV_GetLastError($iExtended, $sInfo = '') Local $sErrMsg = 'Unknown error (' & $iExtended & ')' Switch $iExtended Case $GDIP_ERROK $sErrMsg = 'Method call was successful' & ' (' & $sInfo & ')' Case $GDIP_ERRGENERICERROR $sErrMsg = 'Generic method call error' & ' (' & $sInfo & ')' Case $GDIP_ERRINVALIDPARAMETER $sErrMsg = 'One of the arguments passed to the method was not valid' & ' (' & $sInfo & ')' Case $GDIP_ERROUTOFMEMORY $sErrMsg = 'The operating system is out of memory' & ' (' & $sInfo & ')' Case $GDIP_ERROBJECTBUSY $sErrMsg = 'One of the arguments in the call is already in use' & ' (' & $sInfo & ')' Case $GDIP_ERRINSUFFICIENTBUFFER $sErrMsg = 'A buffer is not large enough' & ' (' & $sInfo & ')' Case $GDIP_ERRNOTIMPLEMENTED $sErrMsg = 'The method is not implemented' & ' (' & $sInfo & ')' Case $GDIP_ERRWIN32ERROR $sErrMsg = 'The method generated a Microsoft Win32 error' & ' (' & $sInfo & ')' Case $GDIP_ERRWRONGSTATE $sErrMsg = 'The object is in an invalid state to satisfy the API call' & ' (' & $sInfo & ')' Case $GDIP_ERRABORTED $sErrMsg = 'The method was aborted' & ' (' & $sInfo & ')' Case $GDIP_ERRFILENOTFOUND $sErrMsg = 'The specified image file or metafile cannot be found' & ' (' & $sInfo & ')' Case $GDIP_ERRVALUEOVERFLOW $sErrMsg = 'The method produced a numeric overflow' & ' (' & $sInfo & ')' Case $GDIP_ERRACCESSDENIED $sErrMsg = 'A write operation is not allowed on the specified file' & ' (' & $sInfo & ')' Case $GDIP_ERRUNKNOWNIMAGEFORMAT $sErrMsg = 'The specified image file format is not known' & ' (' & $sInfo & ')' Case $GDIP_ERRFONTFAMILYNOTFOUND $sErrMsg = 'The specified font family cannot be found' & ' (' & $sInfo & ')' Case $GDIP_ERRFONTSTYLENOTFOUND $sErrMsg = 'The specified style is not available for the specified font' & ' (' & $sInfo & ')' Case $GDIP_ERRNOTTRUETYPEFONT $sErrMsg = 'The font retrieved is not a TrueType font' & ' (' & $sInfo & ')' Case $GDIP_ERRUNSUPPORTEDGDIVERSION $sErrMsg = 'The installed GDI+ version is incompatible' & ' (' & $sInfo & ')' Case $GDIP_ERRGDIPLUSNOTINITIALIZED $sErrMsg = 'The GDI+ API is not in an initialized state' & ' (' & $sInfo & ')' Case $GDIP_ERRPROPERTYNOTFOUND $sErrMsg = 'The specified property does not exist in the image' & ' (' & $sInfo & ')' Case $GDIP_ERRPROPERTYNOTSUPPORTED $sErrMsg = 'The specified property is not supported' & ' (' & $sInfo & ')' Case Else EndSwitch Return $sErrMsg EndFunc ;==>CV_GetLastError Func CV_InstallAu3() Local $sDestDir = @TempDir & '\CV\' If Not FileExists($sDestDir) Then DirCreate($sDestDir) FileInstall('V:\AutoIt\Colour Viewer\Files\HTML.au3', $sDestDir, $FC_NOOVERWRITE) FileInstall('V:\AutoIt\Colour Viewer\Files\John December.au3', $sDestDir, $FC_NOOVERWRITE) FileInstall('V:\AutoIt\Colour Viewer\Files\Ral Classic.au3', $sDestDir, $FC_NOOVERWRITE) FileInstall('V:\AutoIt\Colour Viewer\Files\Ral Design.au3', $sDestDir, $FC_NOOVERWRITE) FileInstall('V:\AutoIt\Colour Viewer\Files\Ral Effect.au3', $sDestDir, $FC_NOOVERWRITE) FileInstall('V:\AutoIt\Colour Viewer\Files\Ral Plastics P1.au3', $sDestDir, $FC_NOOVERWRITE) FileInstall('V:\AutoIt\Colour Viewer\Files\Ral Plastics P2.au3', $sDestDir, $FC_NOOVERWRITE) FileInstall('V:\AutoIt\Colour Viewer\Files\transparent.bmp', $sDestDir, $FC_NOOVERWRITE) EndFunc ;==>CV_InstallAu3 Func CV_LoadAu3() Local $aFLTA = _FileListToArray($CV_COLOURSDIR, '*.au3', $FLTA_FILES) If Not IsArray($aFLTA) Then ; clear the combo, no files found _GUICtrlComboBox_ResetContent($idAu3Select_cbo) Else ; get the files names to a string Local $sData = _ArrayToString($aFLTA, '|', 1) If @error Then ; error getting file names _GUICtrlComboBox_ResetContent($idAu3Select_cbo) Else ; trim the file ext and add the filenames to the combo GUICtrlSetData($idAu3Select_cbo, '|' & StringReplace($sData, '.au3', '')) EndIf EndIf ; update the count label with the number of files GUICtrlSetData($g_idAu3Count_lbl, _GUICtrlComboBox_GetCount($idAu3Select_cbo)) EndFunc ;==>CV_LoadAu3 Func CV_LoadColourArray() Local $sErr = '' Local $sFile = $CV_COLOURSDIR & GUICtrlRead($idAu3Select_cbo) & '.au3' If FileExists($sFile) Then CV_SetCtrlState($g_idAu3Open_btn) ; enable the open button Local $sFileRead = FileRead($sFile) ; Read the file into a string ; Regular expression to match the constants and their values Local $sPattern = 'Global Const\s+(\$[\w_]+)\s*=\s*(0x[0-9A-F]+)\s*;\s*(.+)' Local $aMatches = StringRegExp($sFileRead, $sPattern, 3) ; Find all matches If Not @error Then ; color constants found Local $iNumMatches = UBound($aMatches) / 3 ;_ Calculate the number of matches Local $aResults[$iNumMatches][3] ;_ Initialize a 2D array ; Fill the 2D array with the matches For $i = 0 To $iNumMatches - 1 $aResults[$i][0] = $aMatches[$i * 3] ;_ colour constant name - $JDC_VIOLETFLOWER $aResults[$i][1] = $aMatches[$i * 3 + 1] ;_ colour constant value - 0xBF5FFF $aResults[$i][2] = $aMatches[$i * 3 + 2] ;_ colour name - Violet Flower Next _ArraySort($aResults, 0, 0, 0, $CV_NAMECOL) ;_ sort by colour names $g_aColours = $aResults ;_ load the global array CV_LoadColourNames() ; load the colour names If Not @error Then GUICtrlSetData($g_idColourNameCount_lbl, _GUICtrlComboBox_GetCount($g_hColourNames_Cbo)) GUICtrlSetData($g_idConstName_lbl, '') CV_SetComboBoxState($g_hColourNames_Cbo, True) Return Else $sErr = 'An error occurred loading the colour names' EndIf Else $sErr = 'No colour constants found in the selected file' EndIf Else CV_SetCtrlState($g_idAu3Open_btn, $GUI_DISABLE) ; disable the open button $sErr = $sFile & ' was not found' EndIf _GUICtrlComboBoxEx_ResetContent($g_hColourNames_Cbo) CV_SetComboBoxState($g_hColourNames_Cbo) GUICtrlSetData($g_idColourNameCount_lbl, _GUICtrlComboBox_GetCount($g_hColourNames_Cbo)) Return SetError(1, 0, CV_ShowErrorMsg('CV_LoadColourArray', $sErr)) EndFunc ;==>CV_LoadColourArray Func CV_LoadColourConstantName() ; get the combo index of the current selection Local $iIndex = _GUICtrlComboBoxEx_GetCurSel($g_hColourNames_Cbo) If $iIndex <> -1 Then ; update the controls state GUICtrlSetData($g_idConstName_lbl, $g_aColours[$iIndex][$CV_CONSTCOL]) ;_ set the constant name CV_SetCtrlState($g_idConstCopy_btn) ;_ enable the copy constants button $g_sRGBHexValue = ($g_sColourFmt = $CV_RGB) ? _ ;_ check which colour mode is selected (CV_SetHexValue($g_aColours[$iIndex][$CV_HEXCOL])) : _ ;_ leave as rgb for input control (CV_SwitchColourFormat($g_aColours[$iIndex][$CV_HEXCOL])) ;_ convert to bgr colour CV_SetHexValueInputs() ; use $g_sRGBHexValue CV_ValidateRGBHex() Else CV_SetCtrlState($g_idConstCopy_btn, $GUI_DISABLE) ;_ disable the copy constants button EndIf EndFunc ;==>CV_LoadColourConstantName Func CV_LoadColourNames() If Not IsArray($g_aColours) Then Return Local $iW = 25 Local $iH = 14 Local $iIndex = 0 Local $hImage = _GUIImageList_Create($iW, $iH, 5, 3, UBound($g_aColours)) If $hImage = 0 Then ConsoleWrite('Failed to create image list' & @CRLF) _GUICtrlComboBoxEx_SetImageList($g_hColourNames_Cbo, $hImage) _GUICtrlComboBox_BeginUpdate($g_hColourNames_Cbo) _GUICtrlComboBoxEx_ResetContent($g_hColourNames_Cbo) For $i = 0 To UBound($g_aColours) - 1 $iIndex = _GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($g_hColourNames_Cbo, $g_aColours[$i][$CV_HEXCOL], $iW, $iH)) _GUICtrlComboBoxEx_AddString($g_hColourNames_Cbo, $g_aColours[$i][$CV_NAMECOL], $iIndex, $iIndex) Next _GUICtrlComboBox_EndUpdate($g_hColourNames_Cbo) EndFunc ;==>CV_LoadColourNames Func CV_LoadUserColour() Local $iReturnType = ($g_sColourFmt = $CV_RGB) ? (2) : (1) Local $sHex = _ChooseColor($iReturnType, 0, $iReturnType, $g_hGui) ; choose a colour and return it's hex code -0x If Not @error Then CV_SetRGBHexValue(CV_SetHexValue($sHex)) EndFunc ;==>CV_LoadUserColour Func CV_ProgramStartup() ; initialise gdip _GDIPlus_Startup() If @error Then _WinAPI_FatalAppExit('Unable to initialise GDI+. ' & CV_GetLastError(@extended, '_GDIPlus_CV_ProgramStartup')) EndFunc ;==>CV_ProgramStartup Func CV_ResetARGBGroup() CV_CreateARGBBitmap(0xFFF0F0F0) CV_SetCtrlState($g_idARGBCopyHex_btn, $GUI_DISABLE) ;_ disable the copy hex button CV_SetCtrlState($g_idARGBOpacity_inp, $GUI_DISABLE) ;_ disable the percentage input CV_SetCtrlState($g_idARGBOpacity_sld, $GUI_DISABLE) ;_ disable the slider GUICtrlSetData($g_idARGBOpacity_sld, $CV_ARGBMAXRANGE) ;_ reset to 0 opacity GUICtrlSetData($g_idARGBOpacity_inp, CV_UpdateOpacityLabel()) ;_ reset the percentage label EndFunc ;==>CV_ResetARGBGroup Func CV_ResetRGBGroup() CV_SetRGBHexValue('') CV_SetCtrlState($g_idRGBFormat_btn, $GUI_DISABLE) GUICtrlSetBkColor($g_idRGBColour_lbl, 0xF0F0F0) EndFunc ;==>CV_ResetRGBGroup Func CV_RGBtoBGR() ;needs argb hex updates ; set the current colour mode RGB or BGR $g_sColourFmt = ($g_sColourFmt = $CV_RGB) ? ($CV_BGR) : ($CV_RGB) ; set the rgb controls text GUICtrlSetData($g_idRGBFormat_btn, ($g_sColourFmt = $CV_RGB) ? ($CV_BGR) : ($CV_RGB)) GUICtrlSetData($g_idRGB_grp, $g_sColourFmt) If $g_sRGBHexValue <> -1 Then CV_SetRGBHexValue(CV_SwitchColourFormat($g_sRGBHexValue)) ; set the argb controls text GUICtrlSetData($g_idARGB_grp, ($g_sColourFmt = $CV_RGB) ? ($CV_ARGB) : ($CV_BGRA)) EndFunc ;==>CV_RGBtoBGR Func CV_SetARGBGroup() ; needs changing to allow bgra mode CV_CreateARGBBitmap(CV_SetHexValue(GUICtrlRead($g_idARGBHex_inp), True)) ;_ draw the colour CV_SetCtrlState($g_idARGBCopyHex_btn) ;_ enable the copy hex button CV_SetCtrlState($g_idARGBOpacity_inp) ;_ enable the opacity level input CV_SetCtrlState($g_idARGBOpacity_sld) ;_ enable the slider GUICtrlSetData($g_idARGBOpacity_sld, $CV_ARGBMAXRANGE) ;_ set opacity to max GUICtrlSetData($g_idARGBOpacity_inp, CV_UpdateOpacityLabel()) ;_ set label to slider value EndFunc ;==>CV_SetARGBGroup Func CV_SetARGBHexValue() ; sets the argb input value GUICtrlSetData($g_idARGBHex_inp, ($g_sColourFmt = $CV_RGB) ? ($CV_ALPHA & $g_sRGBHexValue) : ($g_sRGBHexValue & $CV_ALPHA)) EndFunc ;==>CV_SetARGBHexValue Func CV_SetARGBOpacity($hWnd, $hBitmap, $iAlpha) ; Check if the input is a handle; if not, get the handle from control ID If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) ; If unable to get the handle, return 0 If Not $hWnd Then Return SetError(1, 0, 0) EndIf ; Get the device context (DC) of the window Local $hDC = _WinAPI_GetDC($hWnd) ; Create a compatible DC and bitmap Local $hDestDC = _WinAPI_CreateCompatibleDC($hDC) ;~ Local $g_hBitmap = _WinAPI_LoadImage(0, @ScriptDir & '\transparent.bmp', $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE) ; use an external image Local $g_hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap(CV_CreateCheckerboardBitmap($CV_RECTWIDTH, $CV_RECTHEIGHT, 5)) ; Select the created bitmap into the destination DC Local $hDestSv = _WinAPI_SelectObject($hDestDC, $g_hBitmap) Local $hSrcDC = _WinAPI_CreateCompatibleDC($hDC) Local $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBitmap) _WinAPI_AlphaBlend($hDestDC, 0, 0, $CV_RECTWIDTH, $CV_RECTHEIGHT, $hSrcDC, 0, 0, $CV_RECTWIDTH, $CV_RECTHEIGHT, $iAlpha, 0) ; Clean up: restore original objects and delete DCs _WinAPI_SelectObject($hDestDC, $hDestSv) _WinAPI_DeleteDC($hDestDC) _WinAPI_SelectObject($hSrcDC, $hSrcSv) _WinAPI_DeleteDC($hSrcDC) _WinAPI_ReleaseDC($hWnd, $hDC) ; Set the blended bitmap to the control Local $hObj = _SendMessage($hWnd, $STM_SETIMAGE, $IMAGE_BITMAP, $g_hBitmap) If $hObj Then _WinAPI_DeleteObject($hObj) ; Ensure the bitmap is correctly set and clean up if necessary $hObj = _SendMessage($hWnd, $STM_GETIMAGE) If $hObj <> $g_hBitmap Then _WinAPI_DeleteObject($g_hBitmap) Return 1 EndFunc ;==>CV_SetARGBOpacity Func CV_SetARGBOpacityLevel() GUICtrlSetData($g_idARGBOpacity_sld, Round((GUICtrlRead($g_idARGBOpacity_inp) / 100) * 255)) CV_SetARGBPictureOpacity() ControlFocus('', '', $g_idARGBOpacity_sld) EndFunc ;==>CV_SetARGBOpacityLevel Func CV_SetARGBPictureOpacity() CV_UpdateAlphaChannel() ; update the alpha channel based on slider percentage ; adjust the alpha channel CV_SetARGBOpacity($g_idARGBColour_pic, $g_hARGBBmp, GUICtrlRead($g_idARGBOpacity_sld)) EndFunc ;==>CV_SetARGBPictureOpacity Func CV_SetComboBoxState($hCombo, $bEnable = False) ; disables or enables the colour names combo $hCombo = (IsHWnd($hCombo)) ? ($hCombo) : (GUICtrlGetHandle($hCombo)) If Not $hCombo Then Return SetError(1, 0, 1) DllCall("user32.dll", "int", "EnableWindow", "hwnd", $hCombo, "int", $bEnable) If @error Then Return SetError(2, 0, @error) EndFunc ;==>CV_SetComboBoxState Func CV_SetCtrlState($i_CtrlID, $i_State = $GUI_ENABLE) If BitAND(GUICtrlGetState($i_CtrlID), $i_State) = $i_State Then Return 1 ; skip state change if already in required state Return GUICtrlSetState($i_CtrlID, $i_State) EndFunc ;==>CV_SetCtrlState Func CV_SetHexValue($sHex, $bHEXN = False) ; sets the hex value for use in an input or pic control If $bHEXN Then Return $CV_HEXN & $sHex ; _ add '0x' Return StringReplace($sHex, $CV_HEXN, '') ; _ remove '0x' EndFunc ;==>CV_SetHexValue Func CV_SetHexValueInputs() ; set the value of both hex inputs CV_SetRGBHexValue() ; update the rgb input CV_SetARGBHexValue() ; update the argb input CV_SetRGBTriplets() EndFunc ;==>CV_SetHexValueInputs Func CV_SetRGBGroup() ; set the values for the rgb group controls GUICtrlSetBkColor($g_idRGBColour_lbl, CV_SetHexValue($g_sRGBHexValue, True)) ;_ load the colour in the label CV_SetCtrlState($g_idRGBFormat_btn) EndFunc ;==>CV_SetRGBGroup Func CV_SetRGBHexValue($vData = '') ; set a new value for the rgb input control $vData = ($vData = '') ? ($g_sRGBHexValue) : ($vData) GUICtrlSetData($g_idRGBHex_inp, $vData) EndFunc ;==>CV_SetRGBHexValue Func CV_SetRGBTriplets() ; load the individual r, g, b values Local $aColour = _ColorGetRGB($CV_HEXN & $g_sRGBHexValue) If @error Then Return SetError(1) GUICtrlSetData($g_idRTriplet_inp, $aColour[0]) GUICtrlSetData($g_idGTriplet_inp, $aColour[1]) GUICtrlSetData($g_idBTriplet_inp, $aColour[2]) EndFunc ;==>CV_SetRGBTriplets Func CV_ShowErrorMsg($sTitle, $sError) ; show an error message box MsgBox(BitOR($MB_ICONERROR, $MB_TASKMODAL), $sTitle, $sError, 0, $g_hGui) EndFunc ;==>CV_ShowErrorMsg Func CV_SwitchColourFormat($iColour) ; switch from rgb to bgr and vice versa ##check this# $iColour = (StringLeft($iColour, 2) = '0x') ? ($iColour) : (CV_SetHexValue($iColour, True)) Return Hex(_WinAPI_SwitchColor($iColour), 6) ; Update the global variable EndFunc ;==>CV_SwitchColourFormat Func CV_UpdateAlphaChannel() ; call this update alpha channel Local $sARGB = GUICtrlRead($g_idARGBHex_inp) Local $sPattern = '^.{2}' ;_ replace first two characters - ARGB Local $sFormat = '%02X' ; If GUICtrlRead($g_idARGB_grp) = $CV_BGRA Then $sPattern = '.{2}$' ;_ replace last two characters BGRA ; $sFormat = '%00000002X' ;_ EndIf ; Display hex value. replace first two characters with alpha hex or last two depending on colour mode ARGB or BGRA GUICtrlSetData($g_idARGBHex_inp, StringRegExpReplace($sARGB, $sPattern, StringFormat($sFormat, Round($CV_ARGBMAXRANGE * CV_CalculateOpacityPcent() / 100)))) GUICtrlSetData($g_idARGBOpacity_inp, CV_UpdateOpacityLabel()) EndFunc ;==>CV_UpdateAlphaChannel Func CV_UpdateOpacityLabel() ; update the opacity label reading Return StringFormat('%d', CV_CalculateOpacityPcent()) EndFunc ;==>CV_UpdateOpacityLabel Func CV_ValidateRGBHex() ; If StringLen($g_sRGBHexValue) = 6 Then CV_SetRGBGroup() CV_SetARGBGroup() Else CV_ResetRGBGroup() CV_ResetARGBGroup() EndIf EndFunc ;==>CV_ValidateRGBHex Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam Local $n_NotifyCode = _WinAPI_HiWord($wParam) Local $hWndFrom = $lParam Switch $hWndFrom Case GUICtrlGetHandle($g_idRTriplet_inp), GUICtrlGetHandle($g_idGTriplet_inp), GUICtrlGetHandle($g_idBTriplet_inp) Switch $n_NotifyCode Case $EN_SETFOCUS CV_CopyRGBTriplets() EndSwitch Case GUICtrlGetHandle($g_idRGBHex_inp) Switch $n_NotifyCode Case $EN_CHANGE $g_sRGBHexValue = StringRegExpReplace(GUICtrlRead($g_idRGBHex_inp), '[^a-fA-F0-9]', '') ; update the rgb hex value global variable CV_SetHexValueInputs() CV_ValidateRGBHex() EndSwitch Case $g_hColourNames_Cbo Switch $n_NotifyCode Case $CBN_SELCHANGE CV_LoadColourConstantName() ; doesn't fire $EN_CHANGE when copying to input EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Switch $lParam Case GUICtrlGetHandle($g_idARGBOpacity_sld) CV_SetARGBPictureOpacity() EndSwitch EndFunc ;==>WM_VSCROLL