• win32 sdk绘制ListBox控件


    1》产生:

     
    [html] view plaincopy
     
    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)"你好");  
    14.                 SendMessage(hListBox,LB_ADDSTRING ,0,(LPARAM)"我好");  
    15.                 SendMessage(hListBox,LB_ADDSTRING ,0,(LPARAM)"他好");  
    16. //  
    17.     return hListBox;  
    18. }  

    2》指定size:
     
    [cpp] view plaincopy
     
    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》画:
     
    [cpp] view plaincopy
     
    1. case WM_DRAWITEM:  
    2.       
    3.     if((UINT) wParam==IDC_LISTBOX)  
    4.     {  
    5.         LPDRAWITEMSTRUCT pDI=(LPDRAWITEMSTRUCT) lParam;  
    6.         HBRUSH brsh=CreateSolidBrush(RGB(255-30*pDI->itemID, 128+40*pDI->itemID, 128+40*pDI->itemID));//yellow  
    7.         FillRect(pDI->hDC,&pDI->rcItem,brsh);  
    8.         DeleteObject(brsh);  
    9.         // text   
    10.         SetBkMode(pDI->hDC,TRANSPARENT);  
    11.         char szText[260];  
    12.         SendMessage(m_hListBox,LB_GETTEXT,pDI->itemID,(LPARAM)szText);  
    13.         const DWORD dwStyle = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_END_ELLIPSIS;  
    14.         DrawText(pDI->hDC, szText, strlen(szText), &pDI->rcItem, dwStyle);  
    15.     }  
    16. break;  


    4》要点:| LBS_OWNERDRAWFIXED | LBS_HASSTRINGS,
  • 相关阅读:
    求解未知矩阵的一些方法
    数二2019-19真题最简单的解法
    极坐标转化为参数方程的题目
    隐函数的不定积分
    Go 语言高性能编程
    1457. Pseudo-Palindromic Paths in a Binary Tree (M)
    0754. Reach a Number (M)
    1345. Jump Game IV (H)
    0091. Decode Ways (M)
    0498. Diagonal Traverse (M)
  • 原文地址:https://www.cnblogs.com/lidabo/p/3701607.html
Copyright © 2020-2023  润新知