Big problems with MFC / WinAPI

I need to create an SDI form with a form that has two tabs that encapsulate multiple dialogs as the contents of the tab. But the shape should have a colored background.

And such things make me hate programming.

Firstly, I tried CTabControl through the resource editor, tried different things, but undocumented behavior and quirks without answers led me to the checkpoint.

After many hours of searching, I found that there is a control called a property sheet that I actually need.

A few more searches later, I found that the property bar can even be embedded in CFormView like this: http://www.codeguru.com/Cpp/controls/propertysheet/article.php/c591

And that the dialog classes derived from CPropertyPage can be directly added as pages using the AddPage method for CPropertySheet.

Fine! Not quite so ... Some of the controls did not work and were not created, stumbled upon strange statements. It turns out that the DS_CONTROL style is missing in the dialog box. I found this completely by accident at http://blogs.msdn.com/b/oldnewthing/archive/2007/01/08/1434501.aspx , not a word about it on MSDN !!!! The property page should have: DS_3DLOOK | DS_CONTROL | WS_CHILD | WS_TABSTOP, and may have: DS_SHELLFONT | DS_LOCALEDIT | WS_CLIPCHILDREN styles! Not any others created by default using the resource editor. Sweet, super-hidden information for software developers!

: "OMG. , ...

, API PlaySound 64- ". , , , Microsoft 20 , .

, , (CPropertyPages) , - , !

WM_CTLCOLOR, hwnd , . CPropertySheet, ! CTabCtrl - , CPropertySheet .

? , CPropertySheet CTabControl - , , WM_ERASEBKGND, .

, GetTabControl() CPropertySheet, CTabCtrl * CPropertySheet. , , WM_CTLCOLOR.

, windowproc, , . SubclassWindow doc MSDN : " MFC ".?! ?

CCustomTabCtrl CTabCtrl MFC, SubclassWindow CCustomPropertySheet, CTabCtrl, , MFC.

WindowLong GCL_HBRBACKGROUND CTabCtrl, .

, - .

, , , , Windows, IAccesible , ownerdraw, , 10% . , - , .

, : http://arstechnica.com/civis/viewtopic.php?f=20&t=169886&sid=aad002424e80121e514548d428cf09c6 - PITA, , MSDN NULL-.

? CPropertySheet? -?

+3
2

- ownerdraw . . , , MFC , Win32.

CPropertySheet OnInitDialog() :

GetTabControl()->ModifyStyle(0,TCS_OWNERDRAWFIXED);

, CPropertySheet, . WM_DRAWITEM (OnDrawItem) backgroundColor textColor, . OnDrawItem :

void CPropSht::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
    if (ODT_TAB != lpDrawItemStruct->CtlType)
    {
        CPropertySheet::OnDrawItem(nIDCtl, lpDrawItemStruct);
        return;
    }

    // prepare to draw the tab control
    COLORREF backgroundColor = RGB(0,255,0);
    COLORREF textColor = RGB(0,0,255);
    CTabCtrl *c_Tab = GetTabControl();

    //  Get the current tab item text.
    TCHAR buffer[256] = {0};
    TC_ITEM tcItem;
    tcItem.pszText = buffer;
    tcItem.cchTextMax = 256;
    tcItem.mask = TCIF_TEXT;

    if (!c_Tab->GetItem(c_Tab->GetCurSel(), &tcItem )) return;

    // draw it
    CDC aDC;
    aDC.Attach(lpDrawItemStruct->hDC);
    int nSavedDC = aDC.SaveDC();

    CBrush newBrush;
    newBrush.CreateSolidBrush(backgroundColor);
    aDC.SelectObject(&newBrush);
    aDC.FillRect(&lpDrawItemStruct->rcItem, &newBrush);
    aDC.SetBkMode(TRANSPARENT); 
    aDC.SetTextColor(textColor);
    aDC.DrawText(tcItem.pszText, &lpDrawItemStruct->rcItem, DT_CENTER|DT_VCENTER|DT_SINGLELINE);

    aDC.RestoreDC(nSavedDC);

    aDC.Detach();
}
+5

, ...

, , , . if GetItem:

if (!c_Tab->GetItem(lpDrawItemStruct->itemID, &tcItem )) return;

lpDrawItemStruct- > itemID,

0

Source: https://habr.com/ru/post/1770521/


All Articles