我做了个对话框,里面添加了一个List Box,对话框响应函数如下:
LRESULT CALLBACK Favorite(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
RECT rt, rt1;
int DlgWidth, DlgHeight; // dialog width and height in pixel units
int NewPosX, NewPosY;
int ItemNum=0;
int CurrItem=0;
HWND hWndListBox;
TCHAR CurrString[64];
memset(CurrString,0,sizeof(TCHAR)*64);
int iCurrItem=-1;
int iIndex=0;
        hWndListBox=GetDlgItem(hDlg,IDC_LIST1); switch (message)
{
   case WM_INITDIALOG:
// trying to center the About dialog
if (GetWindowRect(hDlg, &rt1)) {
GetClientRect(GetParent(hDlg), &rt);
DlgWidth = rt1.right - rt1.left;
DlgHeight = rt1.bottom - rt1.top ;
NewPosX = (rt.right - rt.left - DlgWidth)/2;
NewPosY = (rt.bottom - rt.top - DlgHeight)/2;

// if the About box is larger than the physical screen 
if (NewPosX < 0) NewPosX = 0;
if (NewPosY < 0) NewPosY = 0;
SetWindowPos(hDlg, 0, NewPosX, NewPosY,
0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
         iCurrItem = SendMessage (hWndListBox, LB_ADDSTRING, 0, 
                                 (LPARAM)(LPCTSTR) listItem1);
SendMessage (hWndListBox, LB_SETITEMDATA,      
                     (WPARAM) iCurrItem, (LPARAM) 0);
iCurrItem = SendMessage (hWndListBox, LB_ADDSTRING, 0, 
                                 (LPARAM)(LPCTSTR) listItem2);
SendMessage (hWndListBox, LB_SETITEMDATA,      
                     (WPARAM) iCurrItem, (LPARAM)1);
iCurrItem = SendMessage (hWndListBox, LB_ADDSTRING, 0, 
                                 (LPARAM)(LPCTSTR) listItem3);
SendMessage (hWndListBox, LB_SETITEMDATA,      
                     (WPARAM) iCurrItem, (LPARAM)2); SendMessage (hWndListBox, LB_SETCURSEL, 2, 0);
return TRUE;

case WM_COMMAND:
if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
               switch(LOWORD(wParam))
     {
       case ID_Favorite_Open:
                  iCurrItem=-1;
if (iCurrItem=SendMessage(hWndListBox,LB_GETCURSEL,0,0)!=LB_ERR) 
{
                 
SendMessage(hWndListBox,LB_GETTEXT,iCurrItem,(long)CurrString);
 MessageBox(hDlg,CurrString,0,0);
                   }
break;

        case ID_favorite_CANCEL:
   EndDialog(hDlg, LOWORD(wParam));
   break;
     }
break;
}
    return FALSE;
}
向列表框中添加项没问题,可是我要获得当前选择的项是不管选择哪个,得到的都是同一项的数据,
好像iCurrItem=SendMessage(hWndListBox,LB_GETCURSEL,0,0)所得的iCurrItem都是1,不知道是怎么回事 啊?我是再EVC 4下编程
谢谢高人指点~~