win32 sdk绘制ListBox控件
标签:style blog class tar ext width strong string get art int
1》产生:
- //
- 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:
- case WM_MEASUREITEM://ODT_LISTBOX
- if((UINT) wParam==IDC_LISTBOX)
- {
- LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lParam;
- lpmis->itemWidth=400;
- lpmis->itemHeight=22;
- }
- break;
3》画:
- 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,
win32 sdk绘制ListBox控件,搜素材,soscw.com
win32 sdk绘制ListBox控件
标签:style blog class tar ext width strong string get art int
原文地址:http://www.cnblogs.com/lidabo/p/3701607.html
评论