// 请先看源代码:
// 在WndProc过程中:
case WM_CREATE:
cxChar = LOWORD(GetDialogBaseUnits());
cyChar = HIWORD(GetDialogBaseUnits()); rect.left = 20*cxChar;
rect.top = 3*cyChar;
      // 创建一个列表框:
hwndList = CreateWindow(TEXT("listbox"), NULL,
WS_CHILDWINDOW | WS_VISIBLE | LBS_STANDARD,
cxChar, cyChar * 3,
cxChar * 13 + GetSystemMetrics(SM_CXVSCROLL),
cyChar * 10,
hWnd, (HMENU) ID_LIST,
(HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
GetCurrentDirectory(MAX_PATH+1, szBuffer); hwndText = CreateWindow(TEXT("static"), szBuffer,
WS_CHILDWINDOW | WS_VISIBLE | SS_LEFT,
cxChar, cyChar, cxChar*MAX_PATH, cyChar,
hWnd, (HMENU)ID_TEXT, (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE),NULL);
OldList = (WNDPROC) SetWindowLong(hWnd, GWL_WNDPROC, (LPARAM) ListProc); // 《----设置列表框过程
SendMessage(hwndList, LB_DIR, DIRATTR, (LPARAM)TEXT("*.*"));
return 0;// 列表框过程:
LRESULT CALLBACK ListProc(HWND hwnd, UINT message, WPARAM wParam,  LPARAM lParam)
{
if(message == WM_KEYDOWN && wParam == VK_RETURN)
 /*A*/ --------->SendMessage(GetParent(hwnd), WM_COMMAND,
MAKELONG(1, LBN_DBLCLK), (LPARAM) hwnd);
return CallWindowProc(OldList, hwnd, message, wParam, lParam);
}
// 问题:
当我选中列表框中的一项时,按下回车键,为什么/*A*/ 行不执行?

解决方案 »

  1.   

    应该这样吧LRESULT CALLBACK WindowProc(
      HWND hwnd,       // handle to window
      UINT uMsg,       // WM_COMMAND
      WPARAM wParam,   // list box identifier, LBN_DBLCLK
      LPARAM lParam    // handle to list box (HWND)
    );Parameters
    wParam 
    The low-order word is the list box identifier. 
    The high-order word is the notification message. lParam 
    Handle to the list box. 
    Res
    This message is sent only by a list box that has the LBS_NOTIFY style. 
      

  2.   

    if(message == WM_KEYDOWN && wParam == VK_RETURN)是不是这句有问题?
      

  3.   

    WndProc 钩错了:OldList = (WNDPROC) SetWindowLong(hWnd, GWL_WNDPROC, (LPARAM) ListProc); // 应该是:
    OldList = (WNDPROC) SetWindowLong(hwndList, GWL_WNDPROC, (LPARAM) ListProc); //