c++ - Function call to return string inside ListView_SetItemText macro -
ListView is a question on ListView_SetItemText macro to set the text of the item in Windows control. Why the following code works (text in a list is displayed in the list view)
std :: string strNumber = NumberToString (number); ListView_SetItemText (hListView, iItemIndex, iSubitemIndex, (LPSTR) strNumber.c_str ()); does not make a direct call
ListView_SetItemText (hListView, iItemIndex, iSubitemIndex, (LPSTR) NumberToString (number) .c_str ()); Where
std :: string numerostring (double number) {std :: ostringstream ss; SS & lt; & Lt; Number; Return ss.str (); } Many thanks
Here is the macro definition ( Commctrl.h ): #define ListView_SetItemText (w, i, iS, s) \ {\ LV_ITEM _lvi; \ _lvi.iSubItem = iS; \ _lvi.pszText = S; \ SNDMSG ((w), LVM_SETITEMTEXT, i, (LPARAM) (LV_ITEM *) and amp; _lvi); \} This spreads:
... _lvi.pszText = (LPSTR) numberstrosting (number). C_str (); SNDMSG ((hListView), LVM_SETITEMTEXT, iItemIndex, (lParam) (LV_ITEM *) & amp; _lvi); } The NumberToString function returns a temporary std :: string , which is SDMMSG < / Code> Call therefore indicates thin air to _lvi.pszText . (Your code will be fully protected if ListView_SetItemText was a real function call.)
Comments
Post a Comment