Problem with TGClient::GetColorByName on Windows


I created a TGHProgressBar with help from the TGuiBuilder - the code segment looks like this:

fHProgressBar = new TGHProgressBar(fMainFrame,408);
fHProgressBar->ChangeOptions(kSunkenFrame | kDoubleBorder | kOwnBackground);

ULong_t ucolor;        // will reflect user color changes                                                                                                        

fMainFrame->AddFrame(fHProgressBar, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
fHProgressBar->SetRange(0, 100);

This compiles and runs ok on my mac, but when run in windows I get the following error:

Error in TGClient::GetColorByName: couldn’t parse color #ffffff

System details are:
root v5.27.02 on Windows XP (SP 2) built on Visual C++ 2008 Express Edition. I also built a dictionary using rootcint and compiled in VC++



Sorry, but I don’t see the problem on Windows (Vitsa and XP):

root [3] ULong_t ucolor;
root [4] gClient->GetColorByName("#ffffff", ucolor)
(const Bool_t)1
root [5] ucolor
(unsigned long)16777215
root [6]

And this method is widely used in the ROOT GUI…
Could you try to run $ROOTSYS/tutorials/guitest.C (or $ROOTSYS/test/guitest.exe), open the editor by clicking on the “Open Editor” button (as the editor constructor calls gClient->GetColorByName("#ccccff", pxl)) and let me know if it works, please?
BTW, which version of Windows are you working on? And what is the screen configuration (e.g. color depth)?

Cheers, Bertrand.

Hi Bertrand.

I am also able to run the GetColorByName command from the root session, and I could run the guiTest suite without problem - including the progress bars. Although I notice that the progress bar tests do not invoke directly the GetColorByName command, although others do.

The screen settings are 1024x768 with color quality Highest (32 bit)

I’ll play around a bit more and see if I can figure what is going wrong - unless you have other ideas :confused:


Hi Peter,

Well, I don’t really see what could be the problem, since the Windows version is using this method to decode the colors with a format like “#rrggbb”:

if (spec[0] == ‘#’) {
char fmt[16];
int i, red, green, blue;

  if ((i = strlen(spec + 1)) % 3) {
     return 0;
  i /= 3;

  sprintf(fmt, "%%%dx%%%dx%%%dx", i, i, i);
  if (sscanf(spec + 1, fmt, &red, &green, &blue) != 3) {
     return 0;

[/code] The “return 0;” are the cases where something went wrong (which is apparently your case). If you have a debug version, you can try to put a breakpoint in the TGClient::GetColorByName() method, to see why (and where it fails)
But if it works everywhere else… :-k

Cheers, Bertrand.