我做了个对话框,里面添加了一个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下编程
谢谢高人指点~~
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下编程
谢谢高人指点~~
解决方案 »
- Ring0 下由 ZwQueryInformationProcess 取得 ProcessImageFileName 如何轉換為類似 C:\ 開頭的路徑名?
- 递归调用 实现后缀.XXX文件的遍历 问题
- TOM模型的ITextRange::FindText()方法如何进行正则表达式查找
- 关于Select模型的服务器
- 关于多个表的关联操作问题!着急啊....
- 这样往ListContorl里添加控件(如:ComboBox或CheckBox)以及这些控件的消息响应如何?
- VC培训费用大约收多少
- 如何实时更新由RemoteCtrl和DBGrid控件组成数据库数据显示(DBGrid控件中的数据)?
- 急:如何刷新自画按钮的背景?
- 能否让程序代替人操作其他应用程序?
- 遍历文件,排序问题
- 如何在VC中导入excel中的数据
!=的优先级比=高吧????
先算后面的,SendMessage的返回值不等于LB_ERR不就是真(1)吗???