Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Persistence in CExtColorDlg? Collapse All
Subject Author Date
Robert Webb Dec 16, 2008 - 8:30 PM

Hi,

Is there a way to make the CExtColorDlg remember its previous size/location and

which colour model was previously used?  Currently it looks nice, but would be

annoying to use in practice if the user had to re-establish these every time

the dialog was opened.

I’d also like a way to set these choices initially.

Thanks,

Rob.

Technical Support Dec 19, 2008 - 11:21 AM

It’s possible if you create a custom CExtColorDlg-derived class and adjust the required parameters in its OnInitDialog() virtual method. It’s also possible without coding your own color dialog class. You should save the registry parameters for your color dialog before invoking it.

Robert Webb Jan 12, 2009 - 12:53 AM

[I’m quoting your reply "old-school" as I’m having so much trouble getting this forum to format things how I want]


> It’s possible if you create a custom CExtColorDlg-derived class and adjust the required parameters in its OnInitDialog() virtual method.


I gave it a go, but easier said than done.  What I want is to set the initial default only, ie first use, after which the values should be loaded from the registry.  So I presume I should set these BEFORE calling the base class’s OnInitDialog()?  I tried that with the following results:


Simply doing "m_wndColorCtrl = CExtColorCtrl::MODE_HSL_ROLLER;" in OnInitDialog, before calling the base, leads to an assertion.  Apparently the "=" operator is overridden and expects the window to be up and ready.


To change the default window size I tried the following:



    // Use a wider default window size.
    WINDOWPLACEMENT wp;
    ::memset(&wp, 0, sizeof(WINDOWPLACEMENT));
    wp.length = sizeof(WINDOWPLACEMENT);
    if (CExtControlBar::stat_GetWindowPlacement(m_hWnd, wp))
    {
        RECT &rc = wp.rcNormalPosition;
        rc.right += 400;
        CExtControlBar::stat_SetWindowPlacement(m_hWnd, wp);
    }

It does make the window the right size, but the contents have not been resized to match, and any resizing after that leaves the big extra space on the right empty.


> It’s also possible without coding your own color dialog class. You should save the registry parameters for your color dialog before invoking it.


I don’t like the idea of messing with the registry for this.  Best solution would be for ProfUIS to provide a way to set these defaults to begin with.


Thanks,

Rob.

Technical Support Jan 13, 2009 - 4:31 AM

You should invoke parent’s OnInitDialiog() virtual method first. It contains important initialization code and control anchoring code. But it also contains dialog position loading code. So, you may need to load position of your color dialog manually after invoking parent’s OnInitDialiog() virtual method.

Robert Webb Jan 13, 2009 - 6:20 PM

But if I set the mode/position after calling OnInitDialog(), how do I know whether the values were loaded from the registry?  I only want to set the default, but my default should be overridden by a registry settings.  Conceptually it makes sense to set these before calling the base’s OnInitDialog().


I could get the values before, call OnInitDialog(), then check whether the values changed.  If so, then they were loaded from the registry and I should leave them untouched.  However if not, then I can’t be sure that the values weren’t in the registry.  This is how I’m doing it at the moment, which means if the user chooses the "basic colors" mode, which is the original Prof-UIS default, then my code will see that as no change and it will be switched to my default instead.


The obvious solution is to initially set the mode to an impossible value, so that we can be sure it can’t also appear in the registry.  Then a change definitely indicates that it came from the registry.  However, the m_eMode member of CExtColorCtrl is private, so I can’t access it in order to change it.  In fact, if I could, I could just set it before calling OnInitDialog() and everything would work.


All the same problems with position too.


I suppose you will tell me to look in the registry myself to see whether the key exists, and I guess that’s what I’ll do, but this could all be made much simpler if CExtColorDlg supported a couple of extra methods, like SetDefaultColorMode(), SetDefaultWindowSize() and SetDefaultWindowPos().  Or passing these as args to the constructor might be easier.  Doing this with the colour mode in particular would be very easy, so it’s tempting to hack the ProfUIS code, but not possible at my end of the code.


Thanks,

Rob.

Technical Support Dec 18, 2008 - 11:42 AM

Here is the updated source code for the CExtColorDlg class:

http://www.prof-uis.com/download/forums/UpdatedColorDialog285.zip

It’s not present in 2.84, but will be in 2.85. We added the following properties into the CExtColorDlg class:

   CExtSafeString m_strSection, m_strEntryDialogPosition, m_strEntryColorModelSelection;

The m_strSection property is the registry key name used for storing both dialog position and color model index.
The m_strEntryDialogPosition property is the registry variable name for storing the dialog position.
The m_strEntryColorModelSelection property is the registry variable name for storing the color model index.
We modified the following method in the ProfUIS_Controls sample application:
LRESULT CPagePopupMenus::OnColorSelectCustom(WPARAM wParam, LPARAM lParam)
{
            wParam;
            if(                     lParam == ID_COLOR_CTRL_8X5
                        ||           lParam == ID_COLOR_CTRL_8X2
                        ||           lParam == ID_COLOR_CTRL_GRAYSCALE
                        ||           lParam == ID_COLOR_CTRL_HLS
                        )
            {
                        COLORREF clrNew;
                        CExtColorDlg dlgColor;
                        dlgColor.m_strSection = _T("ColorDialog");
                        dlgColor.m_strEntryDialogPosition = _T("Position");
                        dlgColor.m_strEntryColorModelSelection = _T("ColorModel");
                        if( dlgColor.DoModal() != IDOK )
                                    return 0;
                        clrNew = dlgColor.m_clrNew;
                        OnColorChangedFinally( (WPARAM)clrNew, lParam );
            }
            return 0;
}

The context menu displayed over the Popup Menu page in the ProfUIS_Controls sample application has several color popup sub menus. These color sub menus allow you to display color selection dialogs which have persistent dialog position and color model index.


Robert Webb Dec 18, 2008 - 8:50 PM

Excellent.  I’d still like to set the initial default settings though, for the first time a user opens the colour browser.  I’d like to choose the colour method, and maybe make the window a little larger by default.  Possible?


Thanks,

Rob.