2

如何在 ListBox 中选择的 MessageBox 文本中显示?我尝试使用下一个代码,但它只显示空白 MessageBox

wchar_t listBoxStr[15];
HWND hWndList;

switch (message)
{
case WM_CREATE:
    hWndList = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("listbox"), "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_AUTOVSCROLL, 240, 40, 150, 20, hwnd, (HMENU)105, NULL, NULL);
    SendMessage(hWndList, LB_ADDSTRING, 0, (LPARAM)"name");
    SendMessage(hWndList, LB_ADDSTRING, 0, (LPARAM)"extension");
    SendMessage(hWndList, LB_ADDSTRING, 0, (LPARAM)"date");
    SendMessage(hWndList, LB_ADDSTRING, 0, (LPARAM)"size");
    CreateWindowEx(NULL, TEXT("button"), TEXT("FIND"), WS_VISIBLE | WS_CHILD, 410, 40, 50, 20, hwnd, (HMENU)106, NULL, NULL);
    return 0 ;
    return 0 ;
case WM_COMMAND:
    switch(LOWORD(wParam))
    {
    case 106:
        SendMessageW(hWndList, LB_GETTEXT,0,(LPARAM)listBoxStr);
        MessageBoxW(NULL, listBoxStr, L"", NULL);
        return 0;
    }
    return 0;
case WM_PAINT:
    hdc = BeginPaint (hwnd, &ps);
    GetClientRect (hwnd, &rect) ;
    EndPaint (hwnd, &ps) ;
    return 0 ;
case WM_DESTROY:
    PostQuitMessage (0) ;
    return 0 ;
}
4

2 回答 2

3

的第一个参数SendMessage应该是列表框句柄,而不是父窗口句柄。

于 2012-10-26T11:45:52.833 回答
1

通过定义使hWndList静态

static HWND hWndList;

然后像这样尝试

 -  SendMessage(hWndList, LB_ADDSTRING, 0, (LPARAM) L"name");
 -  SendMessage(hWndList, LB_ADDSTRING, 0, (LPARAM) L"extension");
 -  SendMessage(hWndList, LB_ADDSTRING, 0, (LPARAM) L"date");
 -  SendMessage(hWndList, LB_ADDSTRING, 0, (LPARAM) L"size");
于 2012-11-12T14:35:45.620 回答