May 05, 2024, 09:16:55 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


SetControlColor() or RGB() bug?

Started by BumbleBee, July 11, 2007, 04:26:03 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

BumbleBee

What can be the problem?


DEF w1 :Window

OpenWindow w1,0,0,200,130,@MinBox,0,"Gadget Error",&w1_handler
EnableTabs w1,1
SetWindowColor w1,RGB(200,200,200)
SetFont  w1, "Arial", 9, 700
BackPen  w1,RGB(200,200,200)
FrontPen w1,RGB(0,0,0)

CONTROL w1,@Button  ,"Do It",10,70,150, 25,@CTLBTNDEFAULT|@BORDER,1

CONTROL w1,@EDIT    ,""     ,10,10,150, 25,@TabStop|@CTEDITNUMBER,10

Move w1,165,44 : Print w1, "<= !!!"
CONTROL w1,@ComboBox,""     ,10,40,150,100,@TabStop|@CTCOMBOSORT|@CTCOMBODROPLIST|@VSCROLL,20
addstring w1,20,"a"
addstring w1,20,"b"
addstring w1,20,"c"

SetFont w1,"Arial", 9, 700,0,1
SetFont w1,"Arial", 9, 700,0,10
SetFont w1,"Arial", 9, 700,0,20

SetControlText(w1,10,"1000")
SetFocus w1,10

run = 1
waituntil run=0
End

/************************/

SUB w1_handler
DEF x, y :UINT
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW w1

CASE @IDCLOSEWINDOW
CLOSEWINDOW w1
run = 0

CASE @IDControl
If @ControlID = 1
y = Val(GetControlText(w1,10))
for x = 1 to y
SetControlColor w1,20,RGB(0,0,250),RGB(255,1,0) :'FG = Blue, BG = Red
'Foreground RGB values: can be anything
'Background RGB values: only 0 or 255 allowed, other values cause trouble
next x
messagebox w1,Str$(y) + " for-next ended","info"
EndIf
EndSelect
Return
EndSub

Ionic Wind Support Team

Not sure what you're asking.  RGB values can only range from 0 to 255 for each component since each value is a byte, even though the parameters are integers, an RGB value is just a packed integer of 3 bytes. 

Why the loop?

Also you need to check the notification codes when dealing with buttons, especially on XP systems with themes.

If @ControlID = 1
    if @NOTIFYCODE = 0 : 'button click
...

On XP buttons can also send mouse hover messages, tooltip messages, etc.

Paul.
Ionic Wind Support Team

BumbleBee

Sorry, I was a bit short...

Under win98 if you do a loop with 1000 units and the BackGround RGB values are not 255 or 0,
the window and the combobox will change. They get strange effects.

Under w2k you need to set higher loop value. 10000 should be enough.

Ionic Wind Support Team

Again the question remains...why the loop?  It is not doing anything but filling up your message queue for the window.  When you change a controls color you are sending it a message, and the control sends messages back to your window, which is how Windows commincates.

If you remain in a loop you are not giving the default message handlers of controls a chance to process.  Which might be why you are seeing weird effects on 98.  Can't test it here as I haven't had a working 9x for about 3 years.

I can't think of a valid reason to have the loop, but if you must experiment stick a WAIT 1 in the loop to allow Windows to continue to handle messages for your process.

Paul.
Ionic Wind Support Team

BumbleBee

I have a larger program where I have this problem. It doesn't have this loop.
In this case the loop is only for simulating 1000 or more action.

Strange but it seems like something counts the SetControlColor calls :)
If I call it 10 times, it works perfectly. If I call it 1000 * 10 times it fails.

If I put "WAIT 1" after the SetControlColor the loops slows down but the result is the same.
The effect is "working" on win2000 too, so it should be XP compatible :)
Use larger loop counter, eg 10000, then you will see.

Ionic Wind Support Team

Ehhh it's a bug in setcontrolcolor.  Here is a replacement:


DECLARE IMPORT,GetDlgItem(hParent as UINT,id as UINT),UINT
DECLARE IMPORT,SetPropA(hwnd as UINT,lpString as STRING,hData as UINT),INT
DECLARE IMPORT,GetPropA(hwnd as UINT,lpString as STRING),UINT
DECLARE IMPORT,CreateSolidBrush(colr as UINT),UINT
DECLARE IMPORT,DeleteObject(hObject as UINT),INT
DECLARE IMPORT,InvalidateRect(hWnd as UINT,lpRect as POINTER,bErase as INT),INT

SUB MYSETCONTROLCOLOR(win as WINDOW,id as INT,fg as UINT,bg as UINT)
DEF hControl,hBrush as UINT
IF win.hwnd
hControl = GetDlgItem(win.hwnd,id)
IF hControl
SetPropA(hControl,"FGRND",fg)
SetPropA(hControl,"BGRND",bg)
hBrush = GetPropA(hControl,"BBRUSH")
SetPropA(hControl,"BBRUSH",CreateSolidBrush(bg))
IF hBrush THEN DeleteObject(hBrush)
InvalidateRect(hControl,0,1)
ENDIF
ENDIF
RETURN
ENDSUB


I'll fix it eventually ;)
Ionic Wind Support Team

BumbleBee

Thank you Paul, it works perfectly ;)

Ionic Wind Support Team

You are welcome.  Amazing a simple typo can go so long unnoticed ;).  The "effect" as you were calling it was the process running out of resource handles.

Paul.
Ionic Wind Support Team