MFC CListCtrl Adjust Item Height. (LVS_SMALLICON) - mfc

Thanks coming!!
i want to adjust the item's height.look like this one:
but actually it is :
and i find 3 way to adjust the item height:
(1). add the picture but text is not in center.
m_ImageListCList.Create(16,36/*Here*/,ILC_COLOR24|ILC_MASK,$Cnt ,$Cnt);
m_ImageListCList.Add(&Bitmap2, RGB(192, 192, 192));
m_listSchedule.SetImageList(&m_ImageListCList, LVSIL_SMALL);
(2). edit the Font size , it's not pretty
(3). and i want to overwrite the DrawItem() MeasureItem() function of it.
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
afx_msg void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
ON_WM_MEASUREITEM_REFLECT()
ON_WM_DRAWITEM()
but MeasureItem() is work, DrawItem() couldn't called.
and then i find this context
MSDN Knowledge Base Q131788:
The LVS_OWNERDRAWFIXED style is only compatible with the LVS_REPORT style. You cannot have an owner drawn ListView with the LVS_ICON, LVS_SMALLICON or LVS_LIST style.
Now , i don't have better idea ... thanks a lot about your help!!

When MeasureItem works you can size your items, but did you try NM_CUSTOMDRAW. AFAIK it should work to.
If you only need to display an icon and some text and want to pick and select data, wouldn't a list box be sufficient?
Use a classic ListBox and some Ownerdraw mechansim.

Related

How can I create a wxMenu with only bitmaps

I would like to draw a wxMenu where the items are drawn as bitmaps with a size of my choosing. I know I can call SetBitmap etc on a wxMenuItem, but that leaves space on both the left right for the item label etc.
I know how to do this using MFC, where I would subclass CMenu and override DrawItem and MeasureItem so it should at least be possible with the native windows controls.
Is it possible to subclass wxMenu to get the behavior I want?
You can override OnMeasureItem() and OnDrawItem() in your own wxMenuItem subclass, but this will indeed work under MSW only.
You might also want to take a look at the ownerdraw sample.

MFC CEdit won't take keyboard input

I have a legacy project where i need to add a multi-line text box to the view.
I first simply want to create a textbox in onDraw function in my view class to put a text box on screen. The rectangle of the textbox keeps blinking. I can't select it or do anything.
The view class is inherented from CView. The info. i got from research is that CEdit usually added to dialog class, but i can still add it to any view.
CRect rect(100, 100, 300, 200);
CEdit test;
test.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | ES_MULTILINE | WS_VSCROLL, \
rect, this, 1);
I'm totally new to this, and before i get into all the handle and messaging, i just want to simply create a text box and type some text in it.
Thank you for the help in advance.
You probably don't want to create the edit control in your OnDraw. In fact, unless your view contains something else you need to draw, you may not need to handle OnDraw at all.
When you have a view hosting a control, you usually want to create that control in the view's OnCreate, so it's created after the view's own window is created (which will be the control's parent) but before the view's window is displayed (so the control can be displayed at the same time).
In this case, the view probably won't need to deal with drawing at all. It probably will need to deal with:
sizing: resize the control to fit the new size of the view's client area.
focus: when the view receives focus, immediately give focus to the control.
Commands: you pretty routinely want to deal with things like:
cut/copy/paste to/from the control
put data into the control (e.g., from a file)
get data out of the control (e.g., save to a file)
set the control's font

C++ MFC How to draw selection rectangle?

I have a list control. I want to draw selection rectangle on my own.
For example: when i clicked on an item it will draw an selection ractangle on that item and the item is next to it (or can be somewhere else).
Can anybody tell me how to do that ?
Thank you!
To draw a focus rectangle, call the DrawFocusRect function. To enable Visual Styles, call the DrawThemeBackground function (Parts and States: LBCP_ITEM and LBPSI_SELECTED).
Either way, you will have to create an owner-drawn List Box to be able to adjust rendering. For an MFC CListBox control you have to override at least CListBox::DrawItem (and usually also CListBox::MeasureItem).

MFC add scrollbar to CWnd member

I have a member of CWnd class name mywindow
and i want to add to it a scroll-bar.
how i can do it?
i try already to do:
mywindow.EnableScrollBarCtrl(SB_BOTH,TRUE);
it display both Horizontal and Vertical scroll-bars,
but i cannot push the buttons or move the scroll-bars.
i try also after the first command:
mywindow.EnableScrollBar(SB_BOTH,ESB_ENABLE_BOTH);
and it change nothing.
can someone could show me a simple example how to add scroll-bar to this member?
thanks a lot,
Tal
Enabling the scroll bars isn't enough. You have to react to the window messages WM_HSCROLLand WM_VSCROLL. Using the GetScrollInfo method you get the position (value) of the scroll bars and then you draw your window content according to this position.
Look up some scroll bar tutorials such as http://www.codeproject.com/KB/dialog/scrolling_support.aspx . In essence, dwo's comment above is what you need to do - handle those messages and set the virtual client area size.
There must be some 'overflow' before scroll bars became active.
Write some 'sufficiently long' data in your view and the scrollbars will become active (at least, that was my experience time ago).
Usually scroll bars get handled 'automatically' from MFC components like (for instance) text editor or form view. I.e. will became visible when needed also without explicit call EnableScrollBarCtrl ...

How to prevent an icon being highlighted?

I have a listwidget with items which have icons. When the item is selected both the text and the icon are highlighted. My problem is that when the icon is highlighted it just goes entirely black because I'm using only two colours. Is there a way to prevent the icon from being selected?
You can add additional images to the QIcon, depending on it's state:
QIcon icon(...);
icon.addFile("selected.png", size, QIcon::Selected);
See also the documentation of QIcon::addFile().
Best solution was to make your own qstyle which handled the painting of the backgrounds of listitem sub controls and draw the icons qrect as white
Another possibility would be to reimplement QListWidgetItem... You could therefore have a bigger control on how things gets done during the process of selection and painting...
Of course, it's a lot more work...