Jump to content

can't get a combobox background color to work right


kor
 Share

Recommended Posts

; Includes
#NoTrayIcon
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
;#include <StaticConstants.au3>
;#include <EditConstants.au3>
#include <ComboConstants.au3>
;#Include <Array.au3>
;#Include <WinAPI.au3>
;#include <Constants.au3>
;#Include <GuiListView.au3>
;#Include <File.au3>

; Custom includes
#include <Controls.au3>
;#include <Panel1.au3>
;#include <Panel2.au3>

; Global variables
Global $sTemp = @TempDir & "\ADAM", $sName = "ADAM", $sVersion = "4.0.0"

If WinExists($sName) Then Exit MsgBox(48, " Error", $sName & " is already running")

_InstallFiles()
_GUI()

Func _InstallFiles()
    If Not FileExists($sTemp) Then DirCreate($sTemp)
    If Not FileExists($sTemp & "\app.ico") Then FileInstall("img\app.ico", $sTemp & "\app.ico", 1)
    If Not FileExists($sTemp & "\check.ico") Then FileInstall("img\check.ico", $sTemp & "\check.ico", 1)
    If Not FileExists($sTemp & "\close.ico") Then FileInstall("img\close.ico", $sTemp & "\close.ico", 1)
    If Not FileExists($sTemp & "\back.ico") Then FileInstall("img\back.ico", $sTemp & "\back.ico", 1)
    If Not FileExists($sTemp & "\next.ico") Then FileInstall("img\next.ico", $sTemp & "\next.ico", 1)
    If Not FileExists($sTemp & "\go.ico") Then FileInstall("img\go.ico", $sTemp & "\go.ico", 1)
    If Not FileExists($sTemp & "\warning.ico") Then FileInstall("img\warning.ico", $sTemp & "\warning.ico", 1)
EndFunc   ;==>_InstallFiles

Func _GUI()
    Global $iWidth = 495, $iHeight = 500
    Global $oGUI = GUICreate($sName, $iWidth, $iHeight, -1, -1) ; create main gui window
    GUISetBkColor(0xFFFFFF, $oGUI) ; set background color
    GUICtrlCreateGraphic(0, 1, 1, $iHeight - 1) ; left border
    GUICtrlSetColor(-1, 0x8C8C8C)
    GUICtrlCreateGraphic(0, 0, $iWidth, 1) ; top border
    GUICtrlSetColor(-1, 0x8C8C8C)
    GUICtrlCreateGraphic($iWidth - 1, 1, 1, $iHeight - 1) ; right border
    GUICtrlSetColor(-1, 0x8C8C8C)
    GUICtrlCreateGraphic(0, $iHeight - 1, $iWidth, 1) ; bottom border
    GUICtrlSetColor(-1, 0x8C8C8C)
    GUISetState(@SW_SHOW, $oGUI) ; show gui
    ; gui loop
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case Else
                _ADAM($oGUI)
        EndSwitch
    WEnd
EndFunc   ;==>_GUI

Func _ADAM($oGUI)
    Local $aSubControls[30]
    Local $iAccountLeft = 50, $iAccountTop = 35, $iActionLeft = $iAccountLeft + 180, $iActionTop = $iAccountTop ; radio group
    Local $iLabelHeight = 92 ; bottom labels start height
    _CreateHeader("Active Directory Account Manager  (Build " & $sVersion & ")", $iWidth)
    $aSubControls[0] = GUICtrlCreateGroup("Account Type", $iAccountLeft, $iAccountTop, 155, 60) ; left, top, width, heigth
    $aSubControls[0] = GUICtrlCreateRadio("&Staff", $iAccountLeft + 20, $iAccountTop + 22, 60, 25)
    $aSubControls[0] = GUICtrlCreateRadio("&Student", $iAccountLeft + 80, $iAccountTop + 22, 60, 25)
    $aSubControls[0] = GUICtrlCreateGroup("Action", $iActionLeft, $iActionTop, 215, 60)
    $aSubControls[0] = GUICtrlCreateRadio("&Add", $iActionLeft + 20, $iAccountTop + 22, 60, 25)
    $aSubControls[0] = GUICtrlCreateRadio("&Delete", $iActionLeft + 80, $iActionTop + 22, 60, 25)
    $aSubControls[0] = GUICtrlCreateRadio("&Move", $iActionLeft + 150, $iActionTop + 22, 60, 25)
    $aSubControls[0] = _CreateLine(10, 108, $iWidth)
    $aSubControls[0] = _CreateLabel("First Name :", 30, $iLabelHeight + 30)
    $aSubControls[0] = _CreateInput("", 100, $iLabelHeight + 30)
    ;_CreateIcon("warning", 228, 121)
    $aSubControls[0] = _CreateLabel("Last Name :", 30, $iLabelHeight + 60)
    $aSubControls[1] = _CreateInput("", 100, $iLabelHeight + 60)
    ;_CreateIcon("warning", 228, 151)
    $aSubControls[0] = _CreateLabel("Username :", 260, $iLabelHeight + 30)
    $aSubControls[2] = _CreateInput("", 330, $iLabelHeight + 30)
    ;_CreateIcon("warning", 458, 121)
    $aSubControls[0] = _CreateLine(10, 185, $iWidth)
    $aSubControls[0] = _CreateLabel("Staff ID :", 30, $iLabelHeight + 107)
    $aSubControls[2] = _CreateInput("", 100, $iLabelHeight + 107)
    $aSubControls[2] = _CreateLabel("Badge ID* :", 30, $iLabelHeight + 137)
    $aSubControls[2] = _CreateInput("", 100, $iLabelHeight + 137)
    $aSubControls[2] = _CreateLabel("Extension* :", 260, $iLabelHeight + 107)
    $aSubControls[2] = _CreateInput("", 330, $iLabelHeight + 107)
    $aSubControls[2] = _CreateLine(10, 262, $iWidth)
    $aSubControls[2] = _CreateLabel("Location : ", 30, $iLabelHeight + 184)
    $aSubControls[2] = _CreateComboBox(100, 276, "option 3|option2", "")


    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>_ADAM

You will also need this (controls.au3)

#include-once

#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#Include <WinAPI.au3>
#include <Constants.au3>a

Global $iWidth, $iHeigth, $sTemp, $oGUI



Func _CreateHeader($sText = "", $iWidth = 0)
    Local $iHeight = 5
    Dim $aHeaderControl[2]
    $aHeaderControl[0] = GUICtrlCreateLabel($sText, 12, $iHeight, $iWidth - 13, 20, $SS_CENTERIMAGE) ; left, top, width, height
    GUICtrlSetColor($aHeaderControl[0], 0x000000)
    $aHeaderControl[1] = GUICtrlCreateGraphic(10, $iHeight + 20, $iWidth - 20, 1)
    GUICtrlSetColor($aHeaderControl[1], 0x8C8C8C)
    Return $aHeaderControl
EndFunc   ;==>_CreateHeader

Func _CreateLine($iLeft, $iTop, $iWidth, $iHeight = 1)
    Local $oControl = GUICtrlCreateGraphic($iLeft, $iTop, $iWidth - 20, $iHeight)
    GUICtrlSetColor($oControl, 0x8C8C8C)
    Return $oControl
EndFunc   ;==>_CreateLine

Func _CreateLabel($sText = "", $iLeft = 0, $iTop = 0, $iWidth = 60, $iHeight = 20)
    Local $oControl = GUICtrlCreateLabel($sText, $iLeft, $iTop, $iWidth, $iHeight, BitOR($SS_RIGHT, $SS_CENTERIMAGE))
    Return $oControl
EndFunc   ;==>_CreateLabel

Func _CreateInput($sText = "", $iLeft = 0, $iTop = 0, $iWidth = 120, $iHeight = 20)
    Local $oControl = GUICtrlCreateInput($sText, $iLeft, $iTop, $iWidth, $iHeight, BitOR($SS_CENTERIMAGE, $ES_AUTOHSCROLL))
    GUICtrlSetBkColor($oControl, 0xE5F5E5)
    Return $oControl
EndFunc   ;==>_CreateInput

Func _CreateLabelStatus($iStatus, $iLeft, $iTop, $sText = "", $iWidth = 100, $iHeight = 20)
    Local $oControl = GUICtrlCreateLabel($sText, $iLeft, $iTop, $iWidth, $iHeight, BitOR($SS_LEFT, $SS_CENTERIMAGE))
    GUICtrlSetFont($oControl, 10, 400, 0, "Tahoma")
    If $iStatus = 0 Then GUICtrlSetColor($oControl, 0xDE4018)
    If $iStatus = 1 Then GUICtrlSetColor($oControl, 0x32A55E)
    If $iStatus = 2 Then GUICtrlSetColor($oControl, 0x625F5D)
    Return $oControl
EndFunc   ;==>_CreateLabelStatus

Func _CreateIcon($sIcon, $iLeft, $iTop, $iWidth = 24, $iHeight = 24)
    Local $oControl = GUICtrlCreateIcon($sTemp & "\" & $sIcon & ".ico", "", $iLeft, $iTop - 2, $iWidth, $iHeight)
    Return $oControl
EndFunc   ;==>_CreateIcon

Func _CreateComboBox($iLeft, $iTop, $sText = "", $sTextDefault = "", $iWidth = 121, $iHeight = 20)
    Local $oControl = GUICtrlCreateCombo("", $iLeft, $iTop, $iWidth, $iHeight)
    ;DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($oControl), "wstr", 0, "wstr", 0)
    GUICtrlSetData($oControl, $sText, $sTextDefault)
    GUICtrlSetBkColor($oControl, 0x000000)
    Return $oControl
EndFunc   ;==>_CreateComboBox

If you notice when running the combobox's default background seems to be white. If you click on the combo box the background will change to the color im trying to make it (just using black as a test color)

Don't understand where I'm messing up.

Link to comment
Share on other sites

No idea why is this happening

But u can correct it

Just change this Function

Func _CreateComboBox($iLeft, $iTop, $sText = "", $sTextDefault = "", $iWidth = 121, $iHeight = 20)
Local $oControl = GUICtrlCreateCombo("", $iLeft, $iTop, $iWidth, $iHeight)
;DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($oControl), "wstr", 0, "wstr", 0)
GUICtrlSetBkColor($oControl, 0)
GUICtrlSetData($oControl, $sText, $sTextDefault)
ControlClick('','',$oControl)
Return $oControl
EndFunc ;==>_CreateComboBox

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Can you post a short reproducer script that demonstrates the problem and doesn't require any non-standard files, such as your icon files or the controls.au3 file? Much easier to trouble shoot the problem with something we can actually run.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

that's not really a solution since it makes the focus set to the combo box which is not where the focus should be set when the script launches.

Before showing the GUI u can use ControlFocus to give focus to the required control

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Can you post a short reproducer script that demonstrates the problem and doesn't require any non-standard files, such as your icon files or the controls.au3 file? Much easier to trouble shoot the problem with something we can actually run.

you don't actually need the icon files. They aren't being used. you can just comment out the whole function if you wanted.

The controls.au3 is just storing all the functions.

you could just copy the functions from controls into the main script.

Link to comment
Share on other sites

Or...you could do it as you're the one asking for help.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Or...you could do it as you're the one asking for help.

; Includes
#NoTrayIcon
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>
;#Include <Array.au3>
#Include <WinAPI.au3>
#include <Constants.au3>
#Include <GuiListView.au3>
;#Include <File.au3>

; Custom includes
;#include <Controls.au3>
;#include <Panel1.au3>
;#include <Panel2.au3>

; Global variables
Global $sTemp = @TempDir & "ADAM", $sName = "ADAM", $sVersion = "4.0.0"

If WinExists($sName) Then Exit MsgBox(48, " Error", $sName & " is already running")

_InstallFiles()
_GUI()

Func _InstallFiles()
If Not FileExists($sTemp) Then DirCreate($sTemp)
If Not FileExists($sTemp & "app.ico") Then FileInstall("imgapp.ico", $sTemp & "app.ico", 1)
If Not FileExists($sTemp & "check.ico") Then FileInstall("imgcheck.ico", $sTemp & "check.ico", 1)
If Not FileExists($sTemp & "close.ico") Then FileInstall("imgclose.ico", $sTemp & "close.ico", 1)
If Not FileExists($sTemp & "back.ico") Then FileInstall("imgback.ico", $sTemp & "back.ico", 1)
If Not FileExists($sTemp & "next.ico") Then FileInstall("imgnext.ico", $sTemp & "next.ico", 1)
If Not FileExists($sTemp & "go.ico") Then FileInstall("imggo.ico", $sTemp & "go.ico", 1)
If Not FileExists($sTemp & "warning.ico") Then FileInstall("imgwarning.ico", $sTemp & "warning.ico", 1)
EndFunc   ;==>_InstallFiles

Func _GUI()
Global $iWidth = 495, $iHeight = 500
Global $oGUI = GUICreate($sName, $iWidth, $iHeight, -1, -1) ; create main gui window
GUISetBkColor(0xFFFFFF, $oGUI) ; set background color
GUICtrlCreateGraphic(0, 1, 1, $iHeight - 1) ; left border
GUICtrlSetColor(-1, 0x8C8C8C)
GUICtrlCreateGraphic(0, 0, $iWidth, 1) ; top border
GUICtrlSetColor(-1, 0x8C8C8C)
GUICtrlCreateGraphic($iWidth - 1, 1, 1, $iHeight - 1) ; right border
GUICtrlSetColor(-1, 0x8C8C8C)
GUICtrlCreateGraphic(0, $iHeight - 1, $iWidth, 1) ; bottom border
GUICtrlSetColor(-1, 0x8C8C8C)
GUISetState(@SW_SHOW, $oGUI) ; show gui
; gui loop
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case Else
_ADAM($oGUI)
EndSwitch
WEnd
EndFunc   ;==>_GUI

Func _ADAM($oGUI)
Local $aSubControls[30]
Local $iAccountLeft = 50, $iAccountTop = 35, $iActionLeft = $iAccountLeft + 180, $iActionTop = $iAccountTop ; radio group
Local $iLabelHeight = 92 ; bottom labels start height
_CreateHeader("Active Directory Account Manager  (Build " & $sVersion & ")", $iWidth)
$aSubControls[5] = GUICtrlCreateGroup("Account Type", $iAccountLeft, $iAccountTop, 155, 60) ; left, top, width, heigth
$aSubControls[0] = GUICtrlCreateRadio("&Staff", $iAccountLeft + 20, $iAccountTop + 22, 60, 25)
$aSubControls[0] = GUICtrlCreateRadio("&Student", $iAccountLeft + 80, $iAccountTop + 22, 60, 25)
$aSubControls[0] = GUICtrlCreateGroup("Action", $iActionLeft, $iActionTop, 215, 60)
$aSubControls[0] = GUICtrlCreateRadio("&Add", $iActionLeft + 20, $iAccountTop + 22, 60, 25)
$aSubControls[0] = GUICtrlCreateRadio("&Delete", $iActionLeft + 80, $iActionTop + 22, 60, 25)
$aSubControls[0] = GUICtrlCreateRadio("&Move", $iActionLeft + 150, $iActionTop + 22, 60, 25)
$aSubControls[0] = _CreateLine(10, 108, $iWidth)
$aSubControls[0] = _CreateLabel("First Name :", 30, $iLabelHeight + 30)
$aSubControls[0] = _CreateInput("", 100, $iLabelHeight + 30)
;_CreateIcon("warning", 228, 121)
$aSubControls[0] = _CreateLabel("Last Name :", 30, $iLabelHeight + 60)
$aSubControls[1] = _CreateInput("", 100, $iLabelHeight + 60)
;_CreateIcon("warning", 228, 151)
$aSubControls[0] = _CreateLabel("Username :", 260, $iLabelHeight + 30)
$aSubControls[2] = _CreateInput("", 330, $iLabelHeight + 30)
;_CreateIcon("warning", 458, 121)
$aSubControls[0] = _CreateLine(10, 185, $iWidth)
$aSubControls[0] = _CreateLabel("Staff ID :", 30, $iLabelHeight + 107)
$aSubControls[2] = _CreateInput("", 100, $iLabelHeight + 107)
$aSubControls[2] = _CreateLabel("Badge ID* :", 30, $iLabelHeight + 137)
$aSubControls[2] = _CreateInput("", 100, $iLabelHeight + 137)
$aSubControls[2] = _CreateLabel("Extension* :", 260, $iLabelHeight + 107)
$aSubControls[2] = _CreateInput("", 330, $iLabelHeight + 107)
$aSubControls[2] = _CreateLine(10, 262, $iWidth)
$aSubControls[2] = _CreateLabel("Location : ", 30, $iLabelHeight + 184)
$aSubControls[2] = _CreateComboBox(100, 276, "option 3|option2", "")


While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
EndFunc   ;==>_ADAM



Func _CreateHeader($sText = "", $iWidth = 0)
Local $iHeight = 5
Dim $aHeaderControl[2]
$aHeaderControl[0] = GUICtrlCreateLabel($sText, 12, $iHeight, $iWidth - 13, 20, $SS_CENTERIMAGE) ; left, top, width, height
GUICtrlSetColor($aHeaderControl[0], 0x000000)
$aHeaderControl[1] = GUICtrlCreateGraphic(10, $iHeight + 20, $iWidth - 20, 1)
GUICtrlSetColor($aHeaderControl[1], 0x8C8C8C)
Return $aHeaderControl
EndFunc   ;==>_CreateHeader

Func _CreateLine($iLeft, $iTop, $iWidth, $iHeight = 1)
Local $oControl = GUICtrlCreateGraphic($iLeft, $iTop, $iWidth - 20, $iHeight)
GUICtrlSetColor($oControl, 0x8C8C8C)
Return $oControl
EndFunc   ;==>_CreateLine

Func _CreateLabel($sText = "", $iLeft = 0, $iTop = 0, $iWidth = 60, $iHeight = 20)
Local $oControl = GUICtrlCreateLabel($sText, $iLeft, $iTop, $iWidth, $iHeight, BitOR($SS_RIGHT, $SS_CENTERIMAGE))
Return $oControl
EndFunc   ;==>_CreateLabel

Func _CreateInput($sText = "", $iLeft = 0, $iTop = 0, $iWidth = 120, $iHeight = 20)
Local $oControl = GUICtrlCreateInput($sText, $iLeft, $iTop, $iWidth, $iHeight, BitOR($SS_CENTERIMAGE, $ES_AUTOHSCROLL))
GUICtrlSetBkColor($oControl, 0xE5F5E5)
Return $oControl
EndFunc   ;==>_CreateInput

Func _CreateLabelStatus($iStatus, $iLeft, $iTop, $sText = "", $iWidth = 100, $iHeight = 20)
Local $oControl = GUICtrlCreateLabel($sText, $iLeft, $iTop, $iWidth, $iHeight, BitOR($SS_LEFT, $SS_CENTERIMAGE))
GUICtrlSetFont($oControl, 10, 400, 0, "Tahoma")
If $iStatus = 0 Then GUICtrlSetColor($oControl, 0xDE4018)
If $iStatus = 1 Then GUICtrlSetColor($oControl, 0x32A55E)
If $iStatus = 2 Then GUICtrlSetColor($oControl, 0x625F5D)
Return $oControl
EndFunc   ;==>_CreateLabelStatus

Func _CreateIcon($sIcon, $iLeft, $iTop, $iWidth = 24, $iHeight = 24)
Local $oControl = GUICtrlCreateIcon($sTemp & "" & $sIcon & ".ico", "", $iLeft, $iTop - 2, $iWidth, $iHeight)
Return $oControl
EndFunc   ;==>_CreateIcon

Func _CreateComboBox($iLeft, $iTop, $sText = "", $sTextDefault = "", $iWidth = 121, $iHeight = 20)
Local $oControl = GUICtrlCreateCombo("", $iLeft, $iTop, $iWidth, $iHeight)
;DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($oControl), "wstr", 0, "wstr", 0)
GUICtrlSetData($oControl, $sText, $sTextDefault)
GUICtrlSetBkColor($oControl, 0x000000)
;ControlClick('','',$oControl)
Return $oControl
EndFunc   ;==>_CreateComboBox
Link to comment
Share on other sites

I'm not sure why it's not coloring it correctly, but I foresee many problems with this script in the future if this isn't just a proof-of-concept script.

All of your controls are being assigned to the same location in the $asubcontrols array, which means you'll never be able to access them later in the script.

Plus unless you actually need the control ids from the labels and group items, there's no need to preserve them in the array, i.e. if you're not going to change them or access them later you don't need to care what the ids are.

As to having the combobox colored when the script starts, and having the focus on the correct control instead of the Combo, try this mod to your script. See the lines marked with ; <<<<<<<<<<<<<<<<<<<<<<

; Includes
#NoTrayIcon
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>
;#Include <Array.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include <GuiListView.au3>
;#Include <File.au3>
; Custom includes
;#include <Controls.au3>
;#include <Panel1.au3>
;#include <Panel2.au3>
; Global variables
Global $sTemp = @TempDir & "ADAM", $sName = "ADAM", $sVersion = "4.0.0", $iWidth
If WinExists($sName) Then Exit MsgBox(48, " Error", $sName & " is already running")
_InstallFiles()
_GUI()
Func _ADAM($oGUI)
     Local $aSubControls[30]
     Local $iAccountLeft = 50, $iAccountTop = 35, $iActionLeft = $iAccountLeft + 180, $iActionTop = $iAccountTop ; radio group
     Local $iLabelHeight = 92 ; bottom labels start height
     _CreateHeader("Active Directory Account Manager  (Build " & $sVersion & ")", $iWidth)
     $aSubControls[5] = GUICtrlCreateGroup("Account Type", $iAccountLeft, $iAccountTop, 155, 60) ; left, top, width, heigth
     $aSubControls[1] = GUICtrlCreateRadio("&Staff", $iAccountLeft + 20, $iAccountTop + 22, 60, 25); <<<<<<<<<<<<< I am going to set focus to this control, so need a unique array setting
     $aSubControls[0] = GUICtrlCreateRadio("&Student", $iAccountLeft + 80, $iAccountTop + 22, 60, 25)
     $aSubControls[0] = GUICtrlCreateGroup("Action", $iActionLeft, $iActionTop, 215, 60)
     $aSubControls[0] = GUICtrlCreateRadio("&Add", $iActionLeft + 20, $iAccountTop + 22, 60, 25)
     $aSubControls[0] = GUICtrlCreateRadio("&Delete", $iActionLeft + 80, $iActionTop + 22, 60, 25)
     $aSubControls[0] = GUICtrlCreateRadio("&Move", $iActionLeft + 150, $iActionTop + 22, 60, 25)
     $aSubControls[0] = _CreateLine(10, 108, $iWidth)
     $aSubControls[0] = _CreateLabel("First Name :", 30, $iLabelHeight + 30)
     $aSubControls[0] = _CreateInput("", 100, $iLabelHeight + 30)
     ;_CreateIcon("warning", 228, 121)
     $aSubControls[0] = _CreateLabel("Last Name :", 30, $iLabelHeight + 60)
     $aSubControls[0] = _CreateInput("", 100, $iLabelHeight + 60)
     ;_CreateIcon("warning", 228, 151)
     $aSubControls[0] = _CreateLabel("Username :", 260, $iLabelHeight + 30)
     $aSubControls[2] = _CreateInput("", 330, $iLabelHeight + 30)
     ;_CreateIcon("warning", 458, 121)
     $aSubControls[0] = _CreateLine(10, 185, $iWidth)
     $aSubControls[0] = _CreateLabel("Staff ID :", 30, $iLabelHeight + 107)
     $aSubControls[2] = _CreateInput("", 100, $iLabelHeight + 107)
     $aSubControls[2] = _CreateLabel("Badge ID* :", 30, $iLabelHeight + 137)
     $aSubControls[2] = _CreateInput("", 100, $iLabelHeight + 137)
     $aSubControls[2] = _CreateLabel("Extension* :", 260, $iLabelHeight + 107)
     $aSubControls[2] = _CreateInput("", 330, $iLabelHeight + 107)
     $aSubControls[2] = _CreateLine(10, 262, $iWidth)
     $aSubControls[2] = _CreateLabel("Location : ", 30, $iLabelHeight + 184)
     $aSubControls[2] = _CreateComboBox(100, 276, "option 3|option2", "")
     ControlFocus($sName, "", $aSubControls[1]) ; <<<<<<<<<<<<<<<<<<< sets focus to the control marked above
     While 1
          Switch GUIGetMsg()
               Case $GUI_EVENT_CLOSE
                    Exit
          EndSwitch
     WEnd
EndFunc   ;==>_ADAM
Func _CreateComboBox($iLeft, $iTop, $sText = "", $sTextDefault = "", $iWidth = 121, $iHeight = 20)
     Local $oControl = GUICtrlCreateCombo("", $iLeft, $iTop, $iWidth, $iHeight)
     GUICtrlSetData($oControl, $sText, $sTextDefault)
     GUICtrlSetBkColor($oControl, 0x00FF00)
     ControlClick('','',$oControl) ; <<<<<<<<<<<<<<<<<<<<<< uncomment this line
     Return $oControl
EndFunc   ;==>_CreateComboBox
Func _CreateHeader($sText = "", $iWidth = 0)
     Local $iHeight = 5
     Dim $aHeaderControl[2]
     $aHeaderControl[0] = GUICtrlCreateLabel($sText, 12, $iHeight, $iWidth - 13, 20, $SS_CENTERIMAGE) ; left, top, width, height
     GUICtrlSetColor($aHeaderControl[0], 0x000000)
     $aHeaderControl[1] = GUICtrlCreateGraphic(10, $iHeight + 20, $iWidth - 20, 1)
     GUICtrlSetColor($aHeaderControl[1], 0x8C8C8C)
     Return $aHeaderControl
EndFunc   ;==>_CreateHeader
Func _CreateIcon($sIcon, $iLeft, $iTop, $iWidth = 24, $iHeight = 24)
     Local $oControl = GUICtrlCreateIcon($sTemp & "" & $sIcon & ".ico", "", $iLeft, $iTop - 2, $iWidth, $iHeight)
     Return $oControl
EndFunc   ;==>_CreateIcon
Func _CreateInput($sText = "", $iLeft = 0, $iTop = 0, $iWidth = 120, $iHeight = 20)
     Local $oControl = GUICtrlCreateInput($sText, $iLeft, $iTop, $iWidth, $iHeight, BitOR($SS_CENTERIMAGE, $ES_AUTOHSCROLL))
     GUICtrlSetBkColor($oControl, 0xE5F5E5)
     Return $oControl
EndFunc   ;==>_CreateInput
Func _CreateLabel($sText = "", $iLeft = 0, $iTop = 0, $iWidth = 60, $iHeight = 20)
     Local $oControl = GUICtrlCreateLabel($sText, $iLeft, $iTop, $iWidth, $iHeight, BitOR($SS_RIGHT, $SS_CENTERIMAGE))
     Return $oControl
EndFunc   ;==>_CreateLabel
Func _CreateLabelStatus($iStatus, $iLeft, $iTop, $sText = "", $iWidth = 100, $iHeight = 20)
     Local $oControl = GUICtrlCreateLabel($sText, $iLeft, $iTop, $iWidth, $iHeight, BitOR($SS_LEFT, $SS_CENTERIMAGE))
     GUICtrlSetFont($oControl, 10, 400, 0, "Tahoma")
     If $iStatus = 0 Then GUICtrlSetColor($oControl, 0xDE4018)
     If $iStatus = 1 Then GUICtrlSetColor($oControl, 0x32A55E)
     If $iStatus = 2 Then GUICtrlSetColor($oControl, 0x625F5D)
     Return $oControl
EndFunc   ;==>_CreateLabelStatus
Func _CreateLine($iLeft, $iTop, $iWidth, $iHeight = 1)
     Local $oControl = GUICtrlCreateGraphic($iLeft, $iTop, $iWidth - 20, $iHeight)
     GUICtrlSetColor($oControl, 0x8C8C8C)
     Return $oControl
EndFunc   ;==>_CreateLine
Func _GUI()
     Global $iWidth = 495, $iHeight = 500
     Global $oGUI = GUICreate($sName, $iWidth, $iHeight, -1, -1) ; create main gui window
     GUISetBkColor(0xFFFFFF, $oGUI) ; set background color
     GUICtrlCreateGraphic(0, 1, 1, $iHeight - 1) ; left border
     GUICtrlSetColor(-1, 0x8C8C8C)
     GUICtrlCreateGraphic(0, 0, $iWidth, 1) ; top border
     GUICtrlSetColor(-1, 0x8C8C8C)
     GUICtrlCreateGraphic($iWidth - 1, 1, 1, $iHeight - 1) ; right border
     GUICtrlSetColor(-1, 0x8C8C8C)
     GUICtrlCreateGraphic(0, $iHeight - 1, $iWidth, 1) ; bottom border
     GUICtrlSetColor(-1, 0x8C8C8C)
     GUISetState(@SW_SHOW, $oGUI) ; show gui
     ; gui loop
     While 1
          Switch GUIGetMsg()
               Case $GUI_EVENT_CLOSE
                    Exit
               Case Else
                    _ADAM($oGUI)
          EndSwitch
     WEnd
EndFunc   ;==>_GUI
Func _InstallFiles()
     If Not FileExists($sTemp) Then DirCreate($sTemp)
     If Not FileExists($sTemp & "app.ico") Then FileInstall("imgapp.ico", $sTemp & "app.ico", 1)
     If Not FileExists($sTemp & "check.ico") Then FileInstall("imgcheck.ico", $sTemp & "check.ico", 1)
     If Not FileExists($sTemp & "close.ico") Then FileInstall("imgclose.ico", $sTemp & "close.ico", 1)
     If Not FileExists($sTemp & "back.ico") Then FileInstall("imgback.ico", $sTemp & "back.ico", 1)
     If Not FileExists($sTemp & "next.ico") Then FileInstall("imgnext.ico", $sTemp & "next.ico", 1)
     If Not FileExists($sTemp & "go.ico") Then FileInstall("imggo.ico", $sTemp & "go.ico", 1)
     If Not FileExists($sTemp & "warning.ico") Then FileInstall("imgwarning.ico", $sTemp & "warning.ico", 1)
EndFunc   ;==>_InstallFiles

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...