Sign in to follow this  
Followers 0
CodyBarrett

Changing Bkcolor of Edits using CLASSNAMENN

12 posts in this topic

i'm making some Dynamic GUI's and Dynamic Edits... and not recording ANY handles except for the GUI handle... now.. i was wondering WHY this wasn't working

Guictrlsetbkcolor (Controlgethandle ($GUI,'','Edit1'),0x0)

that is just an example.. yet that is EXACTLY the thing i want to happen but its not working.. any ideas on what else i could use? or something that would work? i can't seem to find WINAPI funcs... or Control commands or anything... i'm stumped

things i have :

GUI hWnd

Edit ClassNameNN

Color

things i NEED for guictrlsetbkcolor to work :

CtrlID\Handle\ClassNameNN

Color

(but i need to specify the window...)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

For this you must probably use subclassing with help of callbacks.

Here is example from Callback UDF:

http://www.autoitscript.com/forum/index.php?showtopic=50768

#include <GUIConstantsEx.au3>
#include "DllCallBack.au3"

; some windows constants
Global Const $WM_RBUTTONDOWN = 0x0204
Global Const $WM_RBUTTONUP = 0x0205
Global Const $WM_RBUTTONDBLCLK = 0x0206
Global Const $WM_MOUSEMOVE = 0x0200

Global $pOriginalWindowProc, $sDbg, $hCtrl_Edit, $nMoveTimer, $fMoveSet = False

; Create a GUI with an edit box
$hWnd_ui = GUICreate("Try Right-clicking in the edit box", 310, 135)
$hCtrl_Edit = GUICtrlCreateEdit("", 5, 5, 300, 100)
$hCtrl_Label = GUICtrlCreateLabel("", 5, 110, 300, 20)

; Register callback function
$pMyWindowProc = _DllCallBack ("_MyWindowProc", "hwnd;uint;long;ptr", $_DllCallBack_Subclass)

; Retrieve a pointer to the original WindowProc and set the new one to our
; Callback function - Make sure to use a handle and not the internal id!
$pOriginalWindowProc = _WinSubclass(GUICtrlGetHandle($hCtrl_Edit), $pMyWindowProc)

GUISetState()
While 1
 If $GUI_EVENT_CLOSE = GUIGetMsg() Then
    _DllCallBack_Free ($pOriginalWindowProc)
    Exit
 EndIf
 Sleep(10) ; Gimme a break :)
 If $sDbg Then
    ConsoleWrite($sDbg)
    $sDbg = ""
 EndIf
 If TimerDiff($nMoveTimer) < 350 Then
    If Not $fMoveSet Then
        GUICtrlSetData($hCtrl_Label, "I saw your mouse move...")
        $fMoveSet = True
    EndIf
 Else
    If $fMoveSet Then
        GUICtrlSetData($hCtrl_Label, " ")
        $fMoveSet = False
    EndIf
 EndIf
WEnd

Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam)
 $sDbg &= StringFormat("hWnd: 0x%X \t uiMsg: 0x%X \t wParam: 0x%X \t lParam: 0x%X \n", $hWnd, $uiMsg, $wParam, $lParam)

 ; Disable the right mouse button
 If $uiMsg = $WM_RBUTTONDOWN Or $uiMsg = $WM_RBUTTONUP Or $uiMsg = $WM_RBUTTONDBLCLK Then
    $sDbg &= StringFormat("! No Right mouse Clicks in this Editbox !\n")
  
    ; Set background to RED while button is down
    If $uiMsg = $WM_RBUTTONDOWN Or $WM_RBUTTONDBLCLK = $uiMsg Then GUICtrlSetBkColor($hCtrl_Edit, 0xFF0000)
    If $uiMsg = $WM_RBUTTONUP Then GUICtrlSetBkColor($hCtrl_Edit, 0xFFFFFF)
  
    ; Returning NULL means: We Processed this message
    Return 0
 EndIf
 
 ; i Saw your mouse move by :)
 If $uiMsg = $WM_MOUSEMOVE Then $nMoveTimer = TimerInit()

 ; Returning a Pointer to the original WindowProc means: We did not process this message.
 ; Do not call CallWindowProc() api yourself, the stub will do that for you!
 Return $pOriginalWindowProc
EndFunc   ;==>_MyWindowProc

;-- Wrapper for SetWindowLong API
Func _WinSubclass($hWnd, $lpNewWindowProc)
 ;#define GWL_WNDPROC (-4)
 Local $aTmp = DllCall("user32.dll", "ptr", "SetWindowLong", "hwnd", $hWnd, "int", -4, "ptr", $lpNewWindowProc)
 If @error Then Return SetError(1, 0, 0)
 If $aTmp[0] = 0 Then Return SetError(1, 0, 0)
 Return $aTmp[0]
EndFunc   ;==>_WinSubclass

EDIT:

There is used GUICtrlSetBkColor($hCtrl_Edit, 0xFF0000) so maybe subclassing will not be neccessary for you.

Edited by Zedna

Share this post


Link to post
Share on other sites

There is used GUICtrlSetBkColor($hCtrl_Edit, 0xFF0000) so maybe subclassing will not be neccessary for you.

uhmm... yeah

i don't know the hWnd of the Edit, Nor the CtrlID BUT i know the CLASSNAMENN...

i thought of specifying the hWnd of the window with GuiSwitch () then simply using the ClassNameNN of the edit in Guictrlsetbkcolor () but no still didn't work... the GUI window background color change DOES work... but not the Controls :\ anyone have any ideas?

$hWnd[][0] = Main GUI handle

$hWnd[][1] = Child GUI handle

'Edit1' = Edit Control on Both GUIs

;THIS DOESN'T WORK
Func _ChangeBKColor ()
    $a = _ChooseColor (2,$BK,2,WinGetHandle ('[active]',''))
    If $a = -1 Then Return
    $BK = $a
    $FILE = FileOpen ($TEMP,2)
    FileWrite ($FILE,$BK)
    FileClose ($FILE)    
    For $a = 0 To UBound ($hWnd) - 1
        If $hWnd[$a][0] <> 0 Then
            GUISwitch ($hWnd[$a][0])
            GUISetBkColor ($BK, $hWnd[$a][0])
            GUICtrlSetBkColor ('Edit1',$BK)
            If $hWnd[$a][1] <> 0 Then
                GUISwitch ($hWnd[$a][1])
                GUISetBkColor ($BK, $hWnd[$a][1])
                GUICtrlSetBkColor ('Edit1',$BK)
            EndIf
        EndIf
    Next
EndFunc

Share this post


Link to post
Share on other sites

The GuiCtrlSetBkColor() function looks like it needs the ControlID. Your only choice may be to save the control IDs in an array along with some other identifiable piece of information so you can search out the control ID later.

Share this post


Link to post
Share on other sites

As wraithdu said

GUICtrlSetBkColor ('Edit1',$BK)

this is totally bad

GUICtrlSetBkColor can be used only with ControlID for controls inside your GUI and not for controls of external application.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

but its a GUI AUTOIT made... i just did NOT record the CtrlID into a variable.. but i know its Classname... Autoit helpfile says hWnd\CtrlID\ClassNameNN are all interchangable.... but i guess the GUI functions are specifcally confined to hWnd and CtrlID... right?

Edit... some typos

Edited by CodyBarrett

Share this post


Link to post
Share on other sites

GuiCtrlSetBkColor() NEEDS the control ID. It will not work with anything else. Read the doc for the function.

Share this post


Link to post
Share on other sites

i guess the only way is to make a variable for the Id's.... eh maybe i won't have to even color the Edits. hmmm

BTW the Control () functions use hWnd\ID\ClassNN.... i'm curious why Guictrlset...() uses specifically IDs and not hWnds or ClassNNs hmmmm :D

Share this post


Link to post
Share on other sites

BTW the Control () functions use hWnd\ID\ClassNN.... i'm curious why Guictrlset...() uses specifically IDs and not hWnds or ClassNNs hmmmm  :D

Becuase first one can be used also for external applications but GUICtrl...() only for your own application.

Share this post


Link to post
Share on other sites

it IS my application... i made the edit with Autoit... but didn't reccord the CtrlID... but i guess that doesn't make a difference dos it?

Share this post


Link to post
Share on other sites

it IS my application... i made the edit with Autoit... but didn't reccord the CtrlID... but i guess that doesn't make a difference dos it?

If you created that edit control in your GUI then definitely store it's ControlID (returned by GUICtrCreate) into variable and use that variable later! End of problem :-)

Share this post


Link to post
Share on other sites

lol yeah that solves it...thanks

Share this post


Link to post
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
Sign in to follow this  
Followers 0