Page 1 of 1

SetGadgetColor and StringGadget problem

Posted: Sun Nov 11, 2012 2:01 pm
by silvercover
Hi,

I have simple dll file with 2 simple procedure that receive external window handle and make a StringGadget on that window. everythings work fine except changing background color and text color of created StringGadgets. what's wrong?

Here is sample code for StringGadget creation:

Code: Select all

ProcedureCDLL.s SetEditBoxBGColor()
  
  If (io$ <> "") ; io$ is passed parameters from host window and that is global.
    UseGadgetList(h.l) ; h.l is destination window handle which is global.
    Delimiter$  = "|"
    ObjectID    = Val(StringField(io$, 1, Delimiter$))
    ColorRed.l   = Val(StringField(io$, 2, Delimiter$))
    ColorGreen.l = Val(StringField(io$, 3, Delimiter$))
    ColorBlue.l  = Val(StringField(io$, 4, Delimiter$))
    
    Color = RGB(ColorRed, ColorGreen, ColorBlue)
    StringGadget(1, 8,  35, 306, 20, "1234567", #PB_String_Numeric)
    SetGadgetColor(1, #PB_Gadget_BackColor, Color)
  EndIf
 
EndProcedure


This method works perfect for some gadgets such as TreeGadget!

Re: SetGadgetColor and StringGadget problem

Posted: Sat Nov 17, 2012 5:40 am
by TI-994A
silvercover wrote:...everythings work fine except changing background color and text color of created StringGadgets...
Hi silvercover. Based on your code and the comments in it, I made a simple test routine, replacing ProcedureCDLL() with a standard procedure, and it seems to work:

Code: Select all

Global h.l, io$   ;<--- based on your comments
Global fColor.i   ;<--- I added this for the front colour

Procedure.s SetEditBoxBGColor()   ;<--- changed to standard procedure for testing
  If (io$ <> "") ; io$ is passed parameters from host window and that is global.
    UseGadgetList(h) ; h.l is destination window handle which is global.
    Delimiter$  = "|"
    ObjectID    = Val(StringField(io$, 1, Delimiter$))
    ColorRed.l   = Val(StringField(io$, 2, Delimiter$))
    ColorGreen.l = Val(StringField(io$, 3, Delimiter$))
    ColorBlue.l  = Val(StringField(io$, 4, Delimiter$))
    Color = RGB(ColorRed, ColorGreen, ColorBlue)
    StringGadget(1, 8,  35, 306, 20, "1234567", #PB_String_Numeric)
    SetGadgetColor(1, #PB_Gadget_BackColor, Color)
    SetGadgetColor(1, #PB_Gadget_FrontColor, fColor)   ;<--- I added this
  EndIf
EndProcedure

;my test routine to call the procedure

#MainWindow = 1
wFlags.i = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, 0, 0, 330, 100, "Set Gadget Color", wFlags)

h = WindowID(#MainWindow)
fColor = #Red
io$ = Str(1) + "|" + Str(Red(#Cyan)) + "|" + Str(Green(#Cyan)) + "|" + Str(Blue(#Cyan))
SetEditBoxBGColor()

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
However, I believe that the problem is in the use of Global variables, which are not accessible to external DLL procedures. You'd have to pass them as parameters when calling the function, something like this:

Code: Select all

Procedure.s SetEditBoxBGColor(h.l, io$, io2$)   ;<--- data passed as parameters
  If (io$ <> "")
    UseGadgetList(h)
    StringGadget(1, 8,  35, 306, 20, "1234567", #PB_String_Numeric)
    Delimiter$  = "|"
    gadgetColor.i = #PB_Gadget_BackColor
    For L = 1 To 2
      If L = 2
        gadgetColor = #PB_Gadget_FrontColor
        io$ = io2$
      EndIf
      ObjectID    = Val(StringField(io$, 1, Delimiter$))
      ColorRed.l   = Val(StringField(io$, 2, Delimiter$))
      ColorGreen.l = Val(StringField(io$, 3, Delimiter$))
      ColorBlue.l  = Val(StringField(io$, 4, Delimiter$))
      Color = RGB(ColorRed, ColorGreen, ColorBlue)
      SetGadgetColor(1, gadgetColor, Color)
    Next L
  EndIf
EndProcedure

#MainWindow = 1
wFlags.i = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, 0, 0, 330, 100, "Set Gadget Color", wFlags)

h.l = WindowID(#MainWindow)
io$ = Str(1) + "|" + Str(Red(#Cyan)) + "|" + Str(Green(#Cyan)) + "|" + Str(Blue(#Cyan))
io2$ = Str(1) + "|" + Str(Red(#Red)) + "|" + Str(Green(#Red)) + "|" + Str(Blue(#Red))
SetEditBoxBGColor(h, io$, io2$)   ;<--- local variables passed as function parameters

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
You'll notice that no Global variables are used, and the data is being passed as parameters to the function. I made some small changes to your code to accommodate this, and to set the front colour as well.

In any case, without more details on the rest of your code, it's really just a stab in the dark. If it still doesn't work from your DLL, please let me know.

Re: SetGadgetColor and StringGadget problem

Posted: Sat Nov 17, 2012 10:38 am
by silvercover
Thank you TI-994A for your answer, but it doesn't help. here is the story:

There is a program that let other developers make plug-in for it and it provides simple SDK. that's why I use ProcedureCDLL in my code and this is not the
first time I write plug-in for that program.

According to its SDK there must be 3 procedure with predefined name in which they do communication between program and its plug-ins, so that's why I made those variable global to let all procedures access required data. these 3 procedures triggers on program start-up or when ever user wants to send/receive data.

I used the routine I've put here for making Tree Gadget and everything work perfect, but no chance for string gadget ! I've also double checked for sent parameters from host program and data reception was OK.

Re: SetGadgetColor and StringGadget problem

Posted: Sat Nov 17, 2012 2:14 pm
by TI-994A
silvercover wrote:...According to its SDK there must be 3 procedure with predefined name in which they do communication between program and its plug-ins, so that's why I made those variable global to let all procedures access required data. these 3 procedures triggers on program start-up or when ever user wants to send/receive data...
Hello again silvercover. I could have misunderstood your usage of global variables. So, these global variables are all used only within the DLL, for the three procedures; is that correct?

Perhaps if you could list the code that calls the SetEditBoxBGColor() function, in addition to the global definitions, we can have a better idea of what's going wrong. As I'm sure you know, without more details on the rest of your code, we'll be working in the dark.