Listview 滚动条未完全显示

Listview 滚动条未完全显示,listview,winapi,scroll,Listview,Winapi,Scroll,当listview项目超过listview高度时,我希望使用win32 api显示垂直滚动条 hwndList1 = CreateWindow(WC_LISTVIEW , L"" , WS_VISIBLE | WS_CHILD | LVS_REPORT | WS_BORDER | WS_VSCROLL | LVS_OWNERDRAWFIXED, 10 , 10 , width , height, hwnd, NULL, GetModuleHandle(NULL), 0); // lis

当listview项目超过listview高度时,我希望使用win32 api显示垂直滚动条

hwndList1 = CreateWindow(WC_LISTVIEW , L"" ,  WS_VISIBLE | WS_CHILD | LVS_REPORT | WS_BORDER  | WS_VSCROLL | LVS_OWNERDRAWFIXED, 10 , 10 , width , height, hwnd, NULL, GetModuleHandle(NULL), 0); 


// list procedure
LRESULT CALLBACK ListProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, UINT_PTR, DWORD_PTR ){
    switch(msg)
    {
        case WM_DRAWITEM:

            break;
        case WM_NOTIFY :
         if (((LPNMHDR) lp)->code == NM_CUSTOMDRAW)
         {
            LPNMCUSTOMDRAW lpcd = (LPNMCUSTOMDRAW)lp;
            switch(lpcd->dwDrawStage)
            {
                case CDDS_PREPAINT :

                    return CDRF_NOTIFYITEMDRAW;
                case CDDS_ITEMPREPAINT:
                {

                 SetBkColor(lpcd->hdc, RGB(255, 132, 72));
                 SetTextColor(lpcd->hdc, RGB(255, 255, 245));
                 return CDRF_NEWFONT;
                } 


            }
        }

        break;

        case WM_NCPAINT:
        {
         RECT rc;
         GetWindowRect(hwnd, &rc);
         OffsetRect(&rc, -rc.left, -rc.top);
         auto hdc = GetWindowDC(hwnd);
         auto hpen = CreatePen(PS_SOLID, 1, RGB(201, 201, 201));
         auto oldpen = SelectObject(hdc, hpen);
         SelectObject(hdc, GetStockObject(NULL_BRUSH));
         Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
         SelectObject(hdc, oldpen);
         DeleteObject(oldpen);
         ReleaseDC(hwnd, hdc);
         return 0;
        }

        case WM_NCDESTROY:
         RemoveWindowSubclass(hwnd, ListProc, 0);
         break;
        }

        return DefSubclassProc(hwnd, msg, wp, lp);
}



 // window procedure
 LRESULT CALLBACK WndProc( HWND hwnd , UINT msg , WPARAM wParam , LPARAM lParam)
 {
     switch(msg){

         case WM_DRAWITEM:
         {
                LPDRAWITEMSTRUCT pDIS=(LPDRAWITEMSTRUCT)lParam;
                HDC hDC=pDIS -> hDC;
                RECT rc = pDIS -> rcItem;
                HFONT hF;
                HBRUSH bg = (HBRUSH) (::GetStockObject(DC_BRUSH));
               HPEN pn=(HPEN)(::GetStockObject(NULL_PEN));
               ::SelectObject( hDC , bg );
               ::SelectObject( hDC , pn );
               ::SetTextColor( hDC , RGB(0,0,0));
               int points=0;
               if( resX <= 800 ){

                    hF=CreateFont(17, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Tahoma");
                }
               else{
                     points=10;
                     int fontheight= -MulDiv(points, GetDeviceCaps(hDC , LOGPIXELSY ) , 72 );
                     hF=CreateFont(fontheight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Tahoma");
                }

                HFONT hOldFont = (HFONT) SelectObject(hDC, hF); 
                if( (pDIS->itemID % 2) != 0 )
                   ::SetDCBrushColor(hDC, RGB(255,255,255));
                else{
                   ::SetDCBrushColor(hDC, RGB(223, 241, 255));

                }
                ::Rectangle( hDC , rc.left , rc.top , rc.right , rc.bottom );

                 wchar_t buffer[1000] = {0};
                 ListView_GetItemText(pDIS -> hwndItem,  pDIS -> itemID, 0, (LPWSTR)buffer, 1000);

                 rc.left=12;

                ::DrawText(hDC, (LPWSTR)buffer, -1, &rc, DT_SINGLELINE | DT_VCENTER);
                SelectObject(hDC, hOldFont); 
                DeleteObject(hF);  

            }
            break;
            case WM_MEASUREITEM:{
                 MEASUREITEMSTRUCT * m= (MEASUREITEMSTRUCT*) lParam;
                 m->itemHeight=28;
                }
                break;


            case WM_NOTIFY:
                if(((LPNMHDR)lParam)->code == NM_CUSTOMDRAW) {
                LPNMLVCUSTOMDRAW  lplvcd = (LPNMLVCUSTOMDRAW)lParam;
                switch(lplvcd->nmcd.dwDrawStage) {
                    case CDDS_PREPAINT:
                       return CDRF_NOTIFYITEMDRAW;

                    case CDDS_ITEMPREPAINT:

                       if (((int)lplvcd->nmcd.dwItemSpec%2)==0) {
                           lplvcd->clrText   = RGB(0,0,0);
                           lplvcd->clrTextBk = RGB(255, 255, 255);
                        } else {
                           lplvcd->clrText   = RGB(0,0,0);
                           lplvcd->clrTextBk = RGB(202, 233, 255);
                         }
                        return CDRF_NEWFONT;
                        break;
                }
            }
            return TRUE; 

           case WM_COMMAND: 
            switch(LOWORD(wParam)){
                case ID_FILE_EXIT:
                   PostMessage(hwnd, WM_CLOSE , 0 , 0);
                   break;
                case ID_ABOUT:
                {
                 int ret=DialogBox( GetModuleHandle(NULL) , MAKEINTRESOURCE(ID_ABOUT) , hwnd , AboutDlgProc );

                }
                 break;
           }
           break;
           case WM_CLOSE:
             DestroyWindow( hwnd );
             break;
           case WM_DESTROY:
             PostQuitMessage(0);
             break;
            default:
             return DefWindowProc( hwnd , msg , wParam , lParam );
       }
    return 0;
}
hwndList1=CreateWindow(WC_LISTVIEW,L“”,WS_VISIBLE,WS_CHILD,LVS_REPORT,WS_BORDER,WS_VSCROLL,LVS_OWNERDRAWFIXED,10,10,宽度,高度,hwnd,NULL,GetModuleHandle(NULL),0);
//列表程序
LRESULT回调ListProc(HWND HWND、UINT msg、WPARAM wp、LPARAM lp、UINT_PTR、DWORD_PTR){
开关(msg)
{
案例WM_图纸项目:
打破
案件通知:
如果((LPNMHDR)lp)->code==NM\u CUSTOMDRAW)
{
LPNMCUSTOMDRAW lpcd=(LPNMCUSTOMDRAW)lp;
开关(lpcd->dwDrawStage)
{
案例CDDS_预涂:
返回CDRF\u NOTIFYITEMDRAW;
案例CDDS\U项目预涂:
{
SetBkColor(lpcd->hdc,RGB(255,132,72));
SetTextColor(lpcd->hdc,RGB(255,255,245));
返回CDRF_NEWFONT;
} 
}
}
打破
案例WM_NCPAINT:
{
RECT-rc;
GetWindowRect(hwnd和rc);
偏距(&rc,-rc.左,-rc.上);
自动hdc=GetWindowDC(hwnd);
auto-hpen=CreatePen(PS_-SOLID,1,RGB(201201201));
自动oldpen=选择对象(hdc、hpen);
选择对象(hdc、GetStockObject(NULL_笔刷));
矩形(hdc、rc.左、rc.上、rc.右、rc.下);
选择对象(hdc、oldpen);
删除对象(oldpen);
释放DC(hwnd、hdc);
返回0;
}
案例WM\NCU:
RemoveWindowsSubClass(hwnd,ListProc,0);
打破
}
返回子类PROC(hwnd、msg、wp、lp);
}
//窗口程序
LRESULT回调WndProc(HWND HWND,UINT msg,WPARAM WPARAM,LPARAM LPARAM)
{
开关(msg){
案例WM_图纸项目:
{
LPDRAWITEMSTRUCT pDIS=(LPDRAWITEMSTRUCT)LPRAM;
HDC HDC=pDIS->HDC;
RECT rc=pDIS->rcItem;
HFONT-hF;
HBRUSH bg=(HBRUSH)(::GetStockObject(DC_笔刷));
HPEN pn=(HPEN)(::GetStockObject(NULL_PEN));
::选择对象(hDC、bg);
::选择对象(hDC、pn);
::SetTextColor(hDC、RGB(0,0,0));
积分=0;
如果(resX itemID%2)!=0)
::SetDCBrushColor(hDC、RGB(255255));
否则{
:SetDCBrushColor(hDC、RGB(223241255));
}
::矩形(hDC、rc.left、rc.top、rc.right、rc.bottom);
wchar_t缓冲区[1000]={0};
ListView_GetItemText(pDIS->HwnItem,pDIS->itemID,0,(LPWSTR)缓冲区,1000);
rc.左=12;
::DrawText(hDC,(LPWSTR)缓冲区,-1,&rc,DT|U单线| DT|U VCENTER);
选择对象(hDC、hOldFont);
删除对象(hF);
}
打破
案例WM_测量项目:{
MEASUREITEMSTRUCT*m=(MEASUREITEMSTRUCT*)LPRAM;
m->itemHeight=28;
}
打破
案件通知:
if(((LPNMHDR)lpram)->code==NM\u CUSTOMDRAW){
LPNMLVCUSTOMDRAW lplvcd=(LPNMLVCUSTOMDRAW)lpram;
开关(lplvcd->nmcd.dwDrawStage){
案例CDDS_预涂:
返回CDRF\u NOTIFYITEMDRAW;
案例CDDS\U项目预涂:
如果((int)lplvcd->nmcd.dwItemSpec%2)=0){
lplvcd->clrText=RGB(0,0,0);
lplvcd->clrTextBk=RGB(255、255、255);
}否则{
lplvcd->clrText=RGB(0,0,0);
lplvcd->clrTextBk=RGB(202233255);
}
返回CDRF_NEWFONT;
打破
}
}
返回TRUE;
case WM_命令:
开关(LOWORD(wParam)){
案例ID\u文件\u退出:
PostMessage(hwnd,WM_CLOSE,0,0);
打破
案例ID_关于:
{
int ret=DialogBox(GetModuleHandle(NULL)、MAKEINTRESOURCE(ID_ABOUT)、hwnd、AboutDlgProc);
}
打破
}
打破
案例WM_结束:
窗口(hwnd);
打破
案例WM_销毁:
PostQuitMessage(0);
打破
违约:
返回DefWindowProc(hwnd、msg、wParam、lParam);
}
返回0;
}
但我有两个问题:

1-当我打开程序滚动条时,显示thumb,但不显示顶部和底部箭头;当我单击滚动条时,显示箭头

2-当我向下恢复listview的父窗口并再次最大化时,我看到滚动条的位置是空的,单击后会显示滚动条

为什么滚动条没有完全显示?我如何修复它


谢谢

如果您只想重新绘制边框颜色,可以先删除
ListView
的边框,然后在主窗口的回调函数中处理
WM_PAINT
消息

//Move Border
hwndList1 = CreateWindow(WC_LISTVIEW, L"", WS_VISIBLE | WS_CHILD | LVS_REPORT | WS_BORDER | WS_VSCROLL | LVS_OWNERDRAWFIXED , 500, 200, width, height, hWnd, NULL, GetModuleHandle(NULL), 0);
DWORD Style = GetWindowLong(hwndList1, GWL_STYLE);
SetWindowLong(hwndList1, GWL_STYLE, Style &~WS_BORDER);
重新处理主窗口的重画事件:

 case WM_PAINT:
        {
            PAINTSTRUCT ps;

            HDC hdc = BeginPaint(hWnd, &ps);
            RECT rc,clrc;
            GetWindowRect(hwndList1, &rc);
            ScreenToClient(hWnd, (LPPOINT)&rc.left);
            ScreenToClient(hWnd, (LPPOINT)&rc.right);
            auto hpen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
            auto oldpen = SelectObject(hdc, hpen);
            SelectObject(hdc, GetStockObject(NULL_BRUSH));
            if (S_1) //S_1 = FALSE
            {
                Rectangle(hdc, rc.left - 1, rc.top - 1, rc.right + 1, rc.bottom + 1);
            }
            else
            {
                Rectangle(hdc, 29, 39, 231, 161); //The first time need to force a redrawing of a particular location
            }
            SelectObject(hdc, oldpen);
            DeleteObject(oldpen);
            ReleaseDC(hwndList1, hdc);
            // TODO: Add any drawing code that uses hdc here...
            EndPaint(hWnd, &ps);
        }
调试:

整个代码(修改仅供参考):


代码中的其他地方存在问题,可能与
WM\u PAINT
WM\u DRAWITEM
有关。请张贴最小可复制的示例。我很惊讶这个问题与我在这里给你的早期答案有关(请参见对该答案的编辑)WM\NCPAINT应以
break结尾
返回0(尽管文档说明它应该返回零,但需要进一步研究!)T
#include "stdafx.h"
#include "Test_listview_1.h"
#include <commctrl.h>
#include <uxtheme.h>

#pragma comment (lib,"Comctl32.lib")
#pragma comment (lib,"UxTheme.lib")

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;                                // current instance
WCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
WCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
HWND  hwndList1;
int middle = 600, middleH = 400, width = 400, height = 200;
BOOL S_1 = FALSE;
// Forward declarations of functions included in this code module:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ListProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, UINT_PTR, DWORD_PTR);
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPWSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // TODO: Place code here.

    // Initialize global strings
    LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadStringW(hInstance, IDC_TESTLISTVIEW1, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);

    // Perform application initialization:
    if (!InitInstance (hInstance, nCmdShow))
    {
        return FALSE;
    }

    HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TESTLISTVIEW1));

    MSG msg;

    // Main message loop:
    while (GetMessage(&msg, nullptr, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return (int) msg.wParam;
}


ATOM MyRegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEXW wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TESTLISTVIEW1));
    wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_TESTLISTVIEW1);
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

    return RegisterClassExW(&wcex);
}


BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   hInst = hInstance; // Store instance handle in our global variable  

   HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_CREATE:
    {
        INITCOMMONCONTROLSEX icex;           // Structure for control initialization.
        icex.dwICC = ICC_LISTVIEW_CLASSES;
        InitCommonControlsEx(&icex);

        hwndList1 = CreateWindow(WC_LISTVIEW, L"", WS_VISIBLE | WS_CHILD | LVS_REPORT | WS_BORDER | WS_VSCROLL | LVS_OWNERDRAWFIXED , 500, 200, width, height, hWnd, NULL, GetModuleHandle(NULL), 0);
        DWORD Style = GetWindowLong(hwndList1, GWL_STYLE);
        SetWindowLong(hwndList1, GWL_STYLE, Style &~WS_BORDER);
        SetWindowSubclass(hwndList1, &ListProc, 0, NULL);
        LVCOLUMN column;
        column.mask = LVCF_WIDTH | LVCF_TEXT;
        column.cx = 200;
        column.pszText = (LPWSTR)L"MASTER";
        ListView_InsertColumn(hwndList1, 0, &column); //column for sub item 0

        LVITEM lvi = {};
        lvi.iItem = ListView_GetItemCount(hwndList1);
        lvi.mask = LVIF_TEXT | LVIF_STATE;
        lvi.pszText = (LPWSTR)L"MASTER1";
        lvi.iSubItem = 0;
        ListView_InsertItem(hwndList1, &lvi);
        lvi.pszText = (LPWSTR)L"MASTER2";
        ListView_InsertItem(hwndList1, &lvi);
        lvi.pszText = (LPWSTR)L"MASTER3";
        ListView_InsertItem(hwndList1, &lvi);
        lvi.pszText = (LPWSTR)L"MASTER4";
        ListView_InsertItem(hwndList1, &lvi);
        lvi.pszText = (LPWSTR)L"MASTER5";
        ListView_InsertItem(hwndList1, &lvi);
        lvi.pszText = (LPWSTR)L"MASTER6";
        ListView_InsertItem(hwndList1, &lvi);
        lvi.pszText = (LPWSTR)L"MASTER7";
        ListView_InsertItem(hwndList1, &lvi);
    }
    break;
    case WM_COMMAND:
        {
            int wmId = LOWORD(wParam);
            // Parse the menu selections:
            switch (wmId)
            {
            case IDM_ABOUT:
                DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
                break;
            case IDM_EXIT:
                DestroyWindow(hWnd);
                break;
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
            }
        }
        break;
    case WM_SIZE:
        if (wParam == SIZE_RESTORED) {
            SetWindowPos(hwndList1, 0, 30, 40, 200, 120, 0);
        }
        else if (wParam == SIZE_MAXIMIZED) {
            SetWindowPos(hwndList1, 0, middle - (18 + width), middleH - (18 + height), width, height, 0);
            RECT rc;
            GetClientRect(hwndList1, &rc);
            ListView_SetColumnWidth(hwndList1, 0, rc.right - rc.left);//rc.left is zero
        }
        break;
    case WM_DRAWITEM:
        {
            LPDRAWITEMSTRUCT pDIS = (LPDRAWITEMSTRUCT)lParam;
            HDC hDC = pDIS->hDC;
            RECT rc = pDIS->rcItem;
            HFONT hF;
            HBRUSH bg = (HBRUSH)(::GetStockObject(DC_BRUSH));
            HPEN pn = (HPEN)(::GetStockObject(NULL_PEN));
            ::SelectObject(hDC, bg);
            ::SelectObject(hDC, pn);
            ::SetTextColor(hDC, RGB(0, 0, 0));
            int points = 0;
//          if (resX <= 800) 
//          {
                hF = CreateFont(17, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Tahoma");
//          }
//          else 
//          {
//              points = 10;
//              int fontheight = -MulDiv(points, GetDeviceCaps(hDC, LOGPIXELSY), 72);
//              hF = CreateFont(fontheight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Tahoma");
//          }

            HFONT hOldFont = (HFONT)SelectObject(hDC, hF);
            if ((pDIS->itemID % 2) != 0)
                ::SetDCBrushColor(hDC, RGB(255, 255, 255));
            else {
                ::SetDCBrushColor(hDC, RGB(223, 241, 255));

            }
            ::Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);

            wchar_t buffer[1000] = { 0 };
            ListView_GetItemText(pDIS->hwndItem, pDIS->itemID, 0, (LPWSTR)buffer, 1000);

            rc.left = 12;

            ::DrawText(hDC, (LPWSTR)buffer, -1, &rc, DT_SINGLELINE | DT_VCENTER);
            SelectObject(hDC, hOldFont);
            DeleteObject(hF);

        }
        break;
    case WM_MEASUREITEM: 
        {
            MEASUREITEMSTRUCT * m = (MEASUREITEMSTRUCT*)lParam;
            m->itemHeight = 28;
        }
         break;

    case WM_PAINT:
        {
            PAINTSTRUCT ps;

            HDC hdc = BeginPaint(hWnd, &ps);
            RECT rc,clrc;
            GetWindowRect(hwndList1, &rc);
            ScreenToClient(hWnd, (LPPOINT)&rc.left);
            ScreenToClient(hWnd, (LPPOINT)&rc.right);
            auto hpen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
            auto oldpen = SelectObject(hdc, hpen);
            SelectObject(hdc, GetStockObject(NULL_BRUSH));
            if (S_1)
            {
                Rectangle(hdc, rc.left - 1, rc.top - 1, rc.right + 1, rc.bottom + 1);
            }
            else
            {
                Rectangle(hdc, 29, 39, 231, 161);
            }
            SelectObject(hdc, oldpen);
            DeleteObject(oldpen);
            ReleaseDC(hwndList1, hdc);
            // TODO: Add any drawing code that uses hdc here...
            EndPaint(hWnd, &ps);
        }
        break;

    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    UNREFERENCED_PARAMETER(lParam);
    switch (message)
    {
    case WM_INITDIALOG:
        return (INT_PTR)TRUE;

    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
        {
            EndDialog(hDlg, LOWORD(wParam));
            return (INT_PTR)TRUE;
        }
        break;
    }
    return (INT_PTR)FALSE;
}

LRESULT CALLBACK ListProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, UINT_PTR, DWORD_PTR) {
    switch (msg)
    {
    case WM_NOTIFY:
        if (((LPNMHDR)lp)->code == NM_CUSTOMDRAW)
        {
            LPNMCUSTOMDRAW lpcd = (LPNMCUSTOMDRAW)lp;
            switch (lpcd->dwDrawStage)
            {
            case CDDS_PREPAINT:

                return CDRF_NOTIFYITEMDRAW;
            case CDDS_ITEMPREPAINT:
            {

                SetBkColor(lpcd->hdc, RGB(255, 132, 72));
                SetTextColor(lpcd->hdc, RGB(255, 255, 0));
                return CDRF_NEWFONT;
            }


            }
        }

        break;

    case WM_NCPAINT:
    {
        RECT rc;
        GetWindowRect(hwnd, &rc);
        OffsetRect(&rc, -rc.left, -rc.top);
        auto hdc = GetWindowDC(hwnd);
        auto hpen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
        auto oldpen = SelectObject(hdc, hpen);
        SelectObject(hdc, GetStockObject(NULL_BRUSH));
//      Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
        SelectObject(hdc, oldpen);
        DeleteObject(oldpen);
        ReleaseDC(hwnd, hdc);
        S_1 = TRUE;
        break;
    }

    case WM_NCDESTROY:
        RemoveWindowSubclass(hwnd, ListProc, 0);
        break;
    }

    return DefSubclassProc(hwnd, msg, wp, lp);
}
case WM_SIZE:
        if (wParam == SIZE_RESTORED) {
            SetWindowPos(hwndList1, 0, 30, 40, 200, 120, 0);

Rectangle(hdc, 29, 39, 231, 161);//30-1,40-1, 200+30+1, 120+40+1,