alexsendar 2017-02-15 08:06 采纳率: 100%
浏览 2210
已采纳

Win32 listbox 怎样获取行选中事件?

如下代码段, WndProc 哪个case里做处理?wm_command? 还是 wm_notify?
最好贴下case 处理代码。

 HWND hListBox=0;  
    hListBox = CreateWindow(WC_LISTBOX,  
        NULL,  
        WS_CHILD|WS_VSCROLL | WS_TABSTOP | LBS_STANDARD
        ,
        x, 23,
        100, rcClient.bottom - rcClient.top - 100,
        parentWnd, (HMENU)IDC_ListBox,   
        (HINSTANCE) GetWindowLong(parentWnd, GWL_HINSTANCE),   
        NULL);
    ShowWindow(hListBox,SW_SHOW);

    SendMessage(hListBox,LB_ADDSTRING ,0,(LPARAM)"Clear");
    SendMessage(hListBox,LB_ADDSTRING ,0,(LPARAM)"你好");
    SendMessage(hListBox,LB_ADDSTRING ,0,(LPARAM)"我好");
    SendMessage(hListBox,LB_ADDSTRING ,0,(LPARAM)"他好");

图片说明

  • 写回答

2条回答 默认 最新

  • oyljerry 2017-02-15 09:25
    关注

    http://stackoverflow.com/questions/20984949/c-getting-information-from-a-listbox-with-lb-getcursel-and-lb-gettext

    处理WM_COMMAND

     INT_PTR CALLBACK ListBoxExampleProc(HWND hDlg, UINT message, 
        WPARAM wParam, LPARAM lParam)
    {
        switch (message)
        {
        case WM_INITDIALOG:
            {
                // Add items to list. 
                HWND hwndList = GetDlgItem(hDlg, IDC_LIST1);  
                for (int i = 0; i < ARRAYSIZE(Roster); i++) 
                { 
                    int pos = (int)SendMessage(hwndList, LB_ADDSTRING, 0, 
                        (LPARAM) Roster[i].achName); 
                    // we do not need the rest from Microsoft's example
                } 
                // Set input focus to the list box.
                SetFocus(hwndList); 
                return TRUE;               
            } 
    
        case WM_COMMAND:
            switch (LOWORD(wParam))
            {
            case IDOK:
            case IDCANCEL:
              EndDialog(hDlg, LOWORD(wParam));
              return TRUE;
    
            case IDC_LIST1:
                {
                    switch (HIWORD(wParam)) 
                    { 
                    case LBN_DBLCLK:
                        {
                            HWND hwndList = GetDlgItem(hDlg, IDC_LIST1); 
    
                            // Get selected index.
                            int lbItem = (int)SendMessage(hwndList, LB_GETCURSEL, 0, 0); 
    
                            // display item's text 
                            TCHAR buff[MAX_PATH];
                            SendMessage(hwndList, LB_GETTEXT, lbItem, (LPARAM)buff);
    
                            SetDlgItemText(hDlg, IDC_EDIT1, buff); 
                            return TRUE; 
                        } 
                    }
                }
                return TRUE;
            }
        }
        return FALSE;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 无源定位系统的时差估计误差标准差
  • ¥15 请问这个代码哪里有问题啊
  • ¥20 python--version在命令端输入结果Python is not defined怎么办?还有pip不是exe格式是不是没安装成功?
  • ¥15 通过GaussianView进行结构微调消除虚频
  • ¥15 调用transformers库
  • ¥15 由于导出的数据名字中带有/,导致Matlab打不开,怎么办?
  • ¥15 新硬盘安装的程序总是崩溃,提示遇到错误
  • ¥15 openpcdet自制数据集评估bev精度和3d精度相同
  • ¥15 excel 上下按钮 显示行
  • ¥20 云卓h12pro 数传问题