Win32 SDK Drawing ListBox control

Source: Internet
Author: User

1 "Produce:

  1. //
  2. HWND Createlb (HWND Parentwnd)
  3. {
  4. HWND hlistbox=0;
  5. Hlistbox = CreateWindow ("LISTBOX",
  6. Null
  7. ws_child| Ws_vscroll | Ws_tabstop | Lbs_standard | lbs_ownerdrawfixed | Lbs_hasstrings,
  8. 230, 20, 60, 80,
  9. Parentwnd, (HMENU) Idc_listbox,
  10. (HINSTANCE) GetWindowLong (Parentwnd, gwl_hinstance),
  11. NULL);
  12. ShowWindow (hlistbox,sw_show);
  13. SendMessage (hlistbox,lb_addstring, 0, (LPARAM) "Hello");
  14. SendMessage (hlistbox,lb_addstring, 0, (LPARAM) "I am Good");
  15. SendMessage (hlistbox,lb_addstring, 0, (LPARAM) "He is good");
  16. //
  17. return hlistbox;
  18. }

2 "Specify Size:
    1. Case Wm_measureitem://odt_listbox
    2. if (UINT) wparam==idc_listbox)
    3. {
    4. Lpmeasureitemstruct Lpmis = (lpmeasureitemstruct) LParam;
    5. lpmis->itemwidth=400;
    6. lpmis->itemheight=22;
    7. }
    8. Break ;


3 "Painting:
  1. Case Wm_drawitem:
  2. if (UINT) wparam==idc_listbox)
  3. {
  4. lpDrawItemStruct pdi= (lpdrawitemstruct) LParam;
  5. hbrush Brsh=createsolidbrush (RGB (255-30*pdi->itemid, 128+40*pdi->itemid, 128+40*pdi->itemid)); //yellow
  6. FillRect (Pdi->hdc,&pdi->rcitem,brsh);
  7. DeleteObject (Brsh);
  8. //Text
  9. SetBkMode (pdi->hdc,transparent);
  10. Char sztext[260];
  11. SendMessage (M_hlistbox,lb_gettext,pdi->itemid, (LPARAM) sztext);
  12. Const DWORD dwstyle = Dt_left | Dt_singleline | Dt_vcenter | Dt_noprefix |  Dt_end_ellipsis;
  13. DrawText (PDI->HDC, Sztext, strlen (Sztext), &pdi->rcitem, dwstyle);
  14. }
  15. Break


4 "Key points: | lbs_ownerdrawfixed | Lbs_hasstrings,

Http://www.cnblogs.com/lidabo/p/3701607.html

Win32 SDK Drawing ListBox control

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.