1 "Produce:
- //
- 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) "Hello");
- SendMessage (hlistbox,lb_addstring, 0, (LPARAM) "I am Good");
- SendMessage (hlistbox,lb_addstring, 0, (LPARAM) "He is good");
- //
- return hlistbox;
- }
2 "Specify Size:
- Case Wm_measureitem://odt_listbox
- if (UINT) wparam==idc_listbox)
- {
- Lpmeasureitemstruct Lpmis = (lpmeasureitemstruct) LParam;
- lpmis->itemwidth=400;
- lpmis->itemheight=22;
- }
- Break ;
3 "Painting:
- 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 "Key points: | lbs_ownerdrawfixed | Lbs_hasstrings,
Http://www.cnblogs.com/lidabo/p/3701607.html
Win32 SDK Drawing ListBox control