Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Рисование своих итемов. Вопрос по CListCtrl 
:(
    Опции темы
Гость_Дмитрий
Дата 10.11.2004, 22:10 (ссылка)    |    (голосов: 0) Загрузка ... Загрузка ... Быстрая цитата Цитата


Unregistered











Ребята, как в ListCtrl перехватить отрисовку итема? Я ловлю DrawItem. Там есть DRAWITEMSTRUCT. И какой из полей отвечает за текстовую строку в ListCtrl? А если будет несколько колонок (у меня так и есть)? С ListBox-ом у меня все получилось. А вот с ListCtrl...

И еще, как изменить высоту итемов? (В ListCtrl)

Разумеется, ListCtrl имеет св-во OWNER_DRAW.

Большое спасибо!
  Вверх
Tatarin
Дата 11.11.2004, 08:57 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 13
Регистрация: 5.1.2004
Где: Россия

Репутация: нет
Всего: нет



статья из MSDN о том, как собственноручно перерисовывать всякие контроллы. Порезано для ListView

+++++++++++++++++++

Custom Draw With List-View Controls
Because list-view controls have subitems and multiple display modes, you will need to handle the NM_CUSTOMDRAW notification somewhat differently than for the other common controls.

For report mode:

The first NM_CUSTOMDRAW notification will have the dwDrawStage member of the associated NMCUSTOMDRAW structure set to CDDS_PREPAINT. Return CDRF_NOTIFYITEMDRAW.
You will then receive an NM_CUSTOMDRAW notification with dwDrawStage set to CDDS_ITEMPREPAINT. If you specify new fonts or colors and return CDRF_NEWFONT, all subitems of the item will be changed. If you want instead to handle each subitem separately, return CDRF_NOTIFYSUBITEMDRAW.
If you returned CDRF_NOTIFYITEMDRAW in the previous step, you will then receive an NM_CUSTOMDRAW notification for each subitem with dwDrawStage set to CDDS_SUBITEM | CDDS_PREPAINT. To change the font or color for that subitem, specify a new font or color and return CDRF_NEWFONT.
For the large icon, small icon, and list modes:

The first NM_CUSTOMDRAW notification will have the dwDrawStage member of the associated NMCUSTOMDRAW structure set to CDDS_PREPAINT. Return CDRF_NOTIFYITEMDRAW.
You will then receive an NM_CUSTOMDRAW notification with dwDrawStage set to CDDS_ITEMPREPAINT. You can change the fonts or colors of an item by specifying new fonts and colors and returning CDRF_NEWFONT. Because these modes do not have subitems, you will not receive any additional NM_CUSTOMDRAW notifications.
An example of a list-view NM_CUSTOMDRAW notification handler is given in the next section.

Using Custom Draw
The following code fragment is a portion of a WM_NOTIFY handler that illustrates how to handle custom draw notifications sent to a list-view control:

Example:
Код


LPNMLISTVIEW  pnm    = (LPNMLISTVIEW)lParam;

switch (pnm->hdr.code){
...
case NM_CUSTOMDRAW:

   LPNMLVCUSTOMDRAW  lplvcd = (LPNMLVCUSTOMDRAW)lParam;

   switch(lplvcd->nmcd.dwDrawStage) {

   case CDDS_PREPAINT :
       return CDRF_NOTIFYITEMDRAW;

   case CDDS_ITEMPREPAINT:
       SelectObject(lplvcd->nmcd.hdc,
                    GetFontForItem(lplvcd->nmcd.dwItemSpec,
                                   lplvcd->nmcd.lItemlParam) );
       lplvcd->clrText = GetColorForItem(lplvcd->nmcd.dwItemSpec,
                                         lplvcd->nmcd.lItemlParam);
       lplvcd->clrTextBk = GetBkColorForItem(lplvcd->nmcd.dwItemSpec,
                                             lplvcd->nmcd.lItemlParam);

/* At this point, you can change the background colors for the item
and any subitems and return CDRF_NEWFONT. If the list-view control
is in report mode, you can simply return CDRF_NOTIFYSUBITEMREDRAW
to customize the item's subitems individually */
       ...

       return CDRF_NEWFONT;
//  or return CDRF_NOTIFYSUBITEMREDRAW;

   case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
       SelectObject(lplvcd->nmcd.hdc,
                    GetFontForSubItem(lplvcd->nmcd.dwItemSpec,
                                      lplvcd->nmcd.lItemlParam,
                                      lplvcd->iSubItem));
       lplvcd->clrText = GetColorForSubItem(lplvcd->nmcd.dwItemSpec,
                                            lplvcd->nmcd.lItemlParam,
                                            lplvcd->iSubItem));
       lplvcd->clrTextBk = GetBkColorForSubItem(lplvcd->nmcd.dwItemSpec,
                                                lplvcd->nmcd.lItemlParam,
                                                lplvcd->iSubItem));

/* This notification is received only if you are in report mode and
returned CDRF_NOTIFYSUBITEMREDRAW in the previous step. At
this point, you can change the background colors for the
subitem and return CDRF_NEWFONT.*/
       ...
       return CDRF_NEWFONT;    
   }
...
}



The first NM_CUSTOMDRAW notification has the dwDrawStage member of the NMCUSTOMDRAW structure set to CDDS_PREPAINT. The handler returns CDRF_NOTIFYITEMDRAW to indicate that it wishes to modify one or more items individually. The control then sends an NM_CUSTOMDRAW notification with dwDrawStage set to CDDS_PREPAINT for each item. The handler returns CDRF_NOTIFYITEMDRAW to indicate that it wishes to modify the item.

If CDRF_NOTIFYITEMDRAW was returned in the previous step, the next NM_CUSTOMDRAW notification has dwDrawStage set to CDDS_ITEMPREPAINT. The handler retrieves the current color and font values. At this point, you can specify new values for small icon, large icon, and list modes. If the control is in report mode, you can also specify new values that will apply to all subitems of the item. If you have changed anything, return CDRF_NEWFONT. If the control is in report mode and you want to handle the subitems individually, return CDRF_NOTIFYSUBITEMREDRAW.

The final notification is only sent if the control is in report mode and you returned CDRF_NOTIFYSUBITEMREDRAW in the previous step. The procedure for changing fonts and colors is the same as that step, but it only applies to a single subitem. Return CDRF_NEWFONT to notify the control if the color or font was changed.

++++++++++++++++++++++++++++

PM MAIL   Вверх
Coocky
Дата 12.11.2004, 23:03 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


GUI гуру
****


Профиль
Группа: Участник Клуба
Сообщений: 2879
Регистрация: 16.2.2004
Где: Украина. Запорожь е

Репутация: 25
Всего: 62



Цитата
И какой из полей отвечает за текстовую строку в ListCtrl?

Конечно itemData smile
Есть по этому поводу топик smile Все тоже самое.Просто заполняй структуру LV_ITEM в DRAWITEM обработчике smile
Цитата
И еще, как изменить высоту итемов?

Назови стиль списка smile


--------------------
Верю в смерть после жизни, в любовь после секса ,в крем после бритья smile        
PM ICQ   Вверх
Гость_Дмитрий
Дата 13.11.2004, 15:57 (ссылка)    |    (голосов: 0) Загрузка ... Загрузка ... Быстрая цитата Цитата


Unregistered











itemData имеет значение == 0!!!!!!!!!! Это в ListBox все так просто и itemData - char *. В ListCtrl все по другому. В ListCtrl при стиле отображения LVS_REPORT структура LPDRAWITEMSTRUCT соответствует всей строке, без разделения на юзерские колонки.

Попробую помучаться. Спасибо.
  Вверх
Coocky
Дата 13.11.2004, 16:51 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


GUI гуру
****


Профиль
Группа: Участник Клуба
Сообщений: 2879
Регистрация: 16.2.2004
Где: Украина. Запорожь е

Репутация: 25
Всего: 62



Цитата
itemData имеет значение == 0!!!!!!!!!

Я ж сказал заполнить нужно изначально !Не мучайся ,завтра код вышлю smile


--------------------
Верю в смерть после жизни, в любовь после секса ,в крем после бритья smile        
PM ICQ   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Visual C++/MFC/WTL | Следующая тема »


 




[ Время генерации скрипта: 0.0508 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.