Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Visual C++/MFC/WTL > MFC listctrl


Автор: Sheff2 6.9.2005, 00:11
Мне нужно изменить размер первой строки в лист контроле, чотбы она была больше чем обычно!!!! а все остальные оставить без изминения!!!
Как это сделать???

Зарание спасибо!!!!!

Автор: Coocky 6.9.2005, 10:30
Sheff2
Ищем по поиску-CListCtrl, а заодно и перерисовку.
Честно сказать будет немного сложновато smile

Автор: Mad 6.9.2005, 12:21
Sheff2
перехватываеш WM_MEASUREITEM, и в обработчике выставляеш нужный тебе размер

Автор: Coocky 6.9.2005, 12:55
А разве при WM_MEASUREITEM не требуется перерисовка? smile

Автор: Mad 6.9.2005, 13:00
Coocky
Опять спорить начнем ? smile


Цитата(Coocky @ 6.9.2005, 11:55)
А разве при WM_MEASUREITEM не требуется перерисовка?

нет перирисовка выполняеться в обработке WM_DRAWITEM smile

Автор: Coocky 6.9.2005, 13:23
Цитата
The framework calls this member function by the framework for the owner of an owner-draw button, combo box, list box, or menu item when the control is created.
Windows initiates the call to OnMeasureItem for the owner of combo boxes and list boxes created with the OWNERDRAWFIXED style before sending the WM_INITDIALOG message

Да что там спорить smile
А по поводу CListCtrl вообще сомневаюсь smile
Цитата
The framework calls this member function by the framework for the owner of an owner-draw button, combo box, list box, or menu item when the control is created.

Слишком все просто...Но тема уже поднималась, можно поискать, а я подожду ответа паренька.
Вернее не ответа , а вопроса-"не работает, что делать?" smile

Автор: Sheff2 7.9.2005, 17:50
Что то у меня вообще не получаеться задействовать это сообщение!!! Создаю ф-цию ставлю стили а оно туда и не заходит! и что тогда делать???

Автор: The Thing 7.9.2005, 19:00
А какие методы ты уже задействовал?...

Возможно в стилях..контрола надо указать Owner Draw = Fixed + Has string

Автор: Coocky 7.9.2005, 21:31
Sheff2
И не получится!
Я уже сказал, что это не сообщение для ListCtrl.
Я завтра гляну примеры, может найду чего интересного..Подожди..

Автор: Mad 8.9.2005, 12:17
Цитата(The @ 7.9.2005, 18:00)
Возможно в стилях..контрола надо указать Owner Draw = Fixed + Has string

Fixed - подразумевает все элементы одного размера smile

Цитата(Coocky @ 7.9.2005, 20:31)
И не получится!
Я уже сказал, что это не сообщение для ListCtrl.

сообщение WM_MEASUREITEM посылаеться не самому контролу, а родительскому окну
Цитата(MSDN)
The WM_MEASUREITEM message is sent to the owner window of a combo box, list box, list view control, or menu item when the control or menu is created

Автор: Sheff2 8.9.2005, 22:03
Coocky
Поисщи пожайлуста буду очень признателен!!!

Автор: Coocky 9.9.2005, 12:42
When you change the font of a list view control, the control or its parent window does not get a chance to respecify the height of the rows. No WM_MEASUREITEM message is sent to the controls parent window. The net effect is that when the font is changed for the control, the row height is no longer valid.
Here's a work around that forces the WM_MEASUREITEM message to be generated.

Step 1: Add handler for WM_SETFONT
The WM_MEASUREITEM message is sent when the control is created. Fortunately this message is also sent whenever the control is resized. Since we want the row height to be adjusted when the font changes, what better place to do thin than in the WM_SETFONT handler. In OnSetFont() we fool Windows into thinking that the window size of the control has changed. We do this by sending the WM_WINDOWPOSCHANGED message to the control which then gets handled by the default window procedure for the control. Note that we haven't specified the SWP_NOSIZE flag and we set the width and height field in the WINDOWPOS structure equal to the existing dimension.
For some reason, the Class Wizard did not have the WM_SETFONT message in its list of window messages. You will have to add the message map entry yourself. It is important to place the entries outside of the block used by the Class Wizard, otherwise the next you make any change with the wizard, our manual changes will be lost.
Код



// In the header file
    //{{AFX_MSG(CMyListCtrl)
    :
    :
    //}}AFX_MSG
    afx_msg LRESULT OnSetFont(WPARAM wParam, LPARAM);
    afx_msg void MeasureItem ( LPMEASUREITEMSTRUCT lpMeasureItemStruct );
    DECLARE_MESSAGE_MAP()



//////////////////////////////////////////////////////////////////////
Код



// In the cpp file
BEGIN_MESSAGE_MAP(CMyListCtrl, CListCtrl)
    //{{AFX_MSG_MAP(CMyListCtrl)
    :
    :
    //}}AFX_MSG_MAP
    ON_MESSAGE(WM_SETFONT, OnSetFont)
    ON_WM_MEASUREITEM_REFLECT( )
END_MESSAGE_MAP()


LRESULT CMyListCtrl::OnSetFont(WPARAM wParam, LPARAM)
{
    LRESULT res =  Default();

    CRect rc;
    GetWindowRect( &rc );

    WINDOWPOS wp;
    wp.hwnd = m_hWnd;
    wp.cx = rc.Width();
    wp.cy = rc.Height();
    wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
    SendMessage( WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp );

    return res;
}

Step 2: Add handler for WM_MEASUREITEM
Since we want our CListCtrl derived class to be modular, we will handle the WM_MEASUREITEM message within this class. The message however, is sent to the parent window, so we use message reflection. Again, the Class Wizard is not much help. We have to manually add the entry in the message map and update the header file. See the code snippet in step one for this.
Код



void CMyListCtrl::MeasureItem ( LPMEASUREITEMSTRUCT lpMeasureItemStruct )
{
    LOGFONT lf;
    GetFont()->GetLogFont( &lf );

    if( lf.lfHeight < 0 )
        lpMeasureItemStruct->itemHeight = -lf.lfHeight;
    else
        lpMeasureItemStruct->itemHeight = lf.lfHeight;
}


Добавлено @ 12:42
Вроде так... smile

Автор: Sheff2 10.9.2005, 11:31
Я конечно извеняюсь за свой тупизм но я не могу достучатся до этих сообщений!!!
Создаю сообщение обработчик на него но туда оно никак не хочет заходить!!!! Что делать??? Может у вас есть уже рабочий исходник!!!!

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)