News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

ChooseColor Dialog

Started by cman, March 25, 2014, 07:54:25 AM

Previous topic - Next topic

cman

When using a ChooseColor generated dialog , the Windows Api takes as a parameter a "CHOOSECOLOR" struct:


typedef struct ;from win32.hlp
{   // cc 
    DWORD        lStructSize;
    HWND         hwndOwner;
    HWND         hInstance;
    COLORREF     rgbResult;
    COLORREF*    lpCustColors;
    DWORD        Flags;
    LPARAM       lCustData;
    LPCCHOOKPROC lpfnHook;
    LPCTSTR      lpTemplateName;
} CHOOSECOLOR;



The color that was chosen by the user ( as I understand ) is stored in the struct field "rgbResult". Is this value ( rgbResult ) the chosen color in the format : "RRRRRRRRGGGGGGGGGBBBBBBBB"  , where R is a bit of the red component of the color and so on? Thanks for any information...

x64Core

Correct, it's a RGB color format, You can take a look at the MSDN:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646830(v=vs.85).aspx


MichaelW

#2
Your format string shows 9 green bits, instead of 8.

COLORREF

And in case you're curious about the RGB and Get?Value macros, from WinGDI.h:

#define RGB(r,g,b)          ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16)))
#define GetRValue(rgb)      (LOBYTE(rgb))
#define GetGValue(rgb)      (LOBYTE(((WORD)(rgb)) >> 8))
#define GetBValue(rgb)      (LOBYTE((rgb)>>16))

Well Microsoft, here's another nice mess you've gotten us into.

cman

Ok , thanks for the information!

Quote
Your format string shows 9 green bits, instead of 8.

I think my vision is going down hill a little bit ( my laptop screen is somewhat small ! ).

Is there a way to center the "Color Chooser" dialog on the screen? When I call the api the dialog jumps to the upper left-hand corner of my screen ( this is annoying ).

jj2007

Quote from: cman on March 26, 2014, 01:58:43 AM
Is there a way to center the "Color Chooser" dialog on the screen?
Yes, you can specify a callback:

QuotelpfnHook: Pointer to a CCHookProc hook procedure that can process messages intended for the dialog box

MichaelW

I didn't have time to get my hook code working, but if you set the CC dialog owner window, at least under Windows XP SP3 the CC dialog will be positioned just below the owner window title bar, shifted slightly to the right, a good choice IMO.

;===============================================================================
include \masm32\include\masm32rt.inc
;===============================================================================
.data
    hInst dd ?
    cust  COLORREF 16 dup(0)
    cc    CHOOSECOLOR <>
.code
;===============================================================================
DialogProc proc  hwndDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
    SWITCH uMsg
        CASE WM_COMMAND

            .IF wParam == 1000

                invoke RtlZeroMemory, ADDR cc, SIZEOF cc
                mov cc.lStructSize, SIZEOF CHOOSECOLOR
                push hwndDlg
                pop cc.hwndOwner

                ;-------------------------------------------
                ; Leaving this off will cause the CC dialog
                ; to trigger an access violation exception.
                ;-------------------------------------------

                mov cc.lpCustColors, OFFSET cust

                invoke ChooseColor, ADDR cc

            .ENDIF

        CASE WM_CLOSE

            invoke EndDialog, hwndDlg, 0

    ENDSW
    return 0
DialogProc endp
;===============================================================================
start:
;===============================================================================
    mov hInst, rv(GetModuleHandle,NULL)
    Dialog "Test","MS Sans Serif",8,WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \
            1,0,0,100,75,1024
    DlgButton "Choose Color",0,21,20,50,12,1000
    CallModalDialog hInst, 0, DialogProc, 0
    exit
end start


Well Microsoft, here's another nice mess you've gotten us into.