how to convert DWORD to COLORREF

medu

Member
what do you want to do with the COLORREF... it's still a DWORD what you get from GetSysColor and it looks to me it has the right format although i've found a reference on internat stating that the order is BGR instead of RGB.

Code:
PROCEDURE GetSysColor EXTERNAL 'User32.dll':
    DEF INPUT PARAMETER idx AS LONG    NO-UNDO.
    DEF RETURN PARAMETER rgb AS LONG  NO-UNDO.
END PROCEDURE.

DEF VAR rgb AS INTEGER NO-UNDO.


RUN GetSysColor(13, OUTPUT rgb).


MESSAGE 'RED: ' GET-BITS(RGB, 1, 8) SKIP 
    'GREEN: ' GET-BITS(RGB, 9, 8) SKIP 
    'BLUE: ' GET-BITS(RGB, 17, 8) SKIP
    'ALFA:' GET-BITS(RGB, 25, 8)
    VIEW-AS ALERT-BOX INFO BUTTONS OK.
 
i need the COLORREF variable to change the menu color of an external program i start
it has a function for that, that takes COLORREF as input

when i try COLORREF NewColor = RGB(214, 211, 206); in an c# programm (214,211,206 are my system colors in rgb) the value of NewColor is 13554646
when i use 13554646 with the function of my external program it has exactly my system color...

the problem is that the RGB() function is a macro somewhere in windows.h...
i basically need the RGC convert function in OE....
 

medu

Member
there you go... you can call it a macro if you like :)

Code:
FUNCTION RGB RETURNS INTEGER (r AS INTEGER, g AS INTEGER, b AS INTEGER):
    DEF VAR rgb AS INTEGER NO-UNDO.

    IF r EQ ? OR r LT 0 OR r GT 255 OR
       g EQ ? OR g LT 0 OR g GT 255 OR 
       b EQ ? OR b LT 0 OR b GT 255 THEN RETURN ?.

    PUT-BITS(rgb, 1, 8) = r.
    PUT-BITS(rgb, 9, 8) = g.
    PUT-BITS(rgb, 17, 8) = b.

    RETURN rgb.
END FUNCTION.

MESSAGE RGB(214, 211, 206) SKIP 13554646
    VIEW-AS ALERT-BOX INFO BUTTONS OK.
 
Top