首页 > 代码库 > win32 sdk绘制ListBox控件
win32 sdk绘制ListBox控件
1》产生:
[html] view plaincopy
- //
- HWND CreateLB(HWND parentWnd)
- {
- HWND hListBox=0;
- hListBox = CreateWindow("LISTBOX",
- NULL,
- WS_CHILD|WS_VSCROLL | WS_TABSTOP | LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS,
- 230, 20, 60, 80,
- parentWnd, (HMENU)IDC_LISTBOX,
- (HINSTANCE) GetWindowLong(parentWnd, GWL_HINSTANCE),
- NULL);
- ShowWindow(hListBox,SW_SHOW);
- SendMessage(hListBox,LB_ADDSTRING ,0,(LPARAM)"你好");
- SendMessage(hListBox,LB_ADDSTRING ,0,(LPARAM)"我好");
- SendMessage(hListBox,LB_ADDSTRING ,0,(LPARAM)"他好");
- //
- return hListBox;
- }
2》指定size:
[cpp] view plaincopy
- case WM_MEASUREITEM://ODT_LISTBOX
- if((UINT) wParam==IDC_LISTBOX)
- {
- LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lParam;
- lpmis->itemWidth=400;
- lpmis->itemHeight=22;
- }
- break;
3》画:
[cpp] view plaincopy
- case WM_DRAWITEM:
- if((UINT) wParam==IDC_LISTBOX)
- {
- LPDRAWITEMSTRUCT pDI=(LPDRAWITEMSTRUCT) lParam;
- HBRUSH brsh=CreateSolidBrush(RGB(255-30*pDI->itemID, 128+40*pDI->itemID, 128+40*pDI->itemID));//yellow
- FillRect(pDI->hDC,&pDI->rcItem,brsh);
- DeleteObject(brsh);
- // text
- SetBkMode(pDI->hDC,TRANSPARENT);
- char szText[260];
- SendMessage(m_hListBox,LB_GETTEXT,pDI->itemID,(LPARAM)szText);
- const DWORD dwStyle = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_END_ELLIPSIS;
- DrawText(pDI->hDC, szText, strlen(szText), &pDI->rcItem, dwStyle);
- }
- break;
4》要点:| LBS_OWNERDRAWFIXED | LBS_HASSTRINGS,
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。