以下是在msdn中的解释
-----------------------------------------------------------------------
CB_ADDSTRING Message --------------------------------------------------------------------------------An application sends a CB_ADDSTRING message to add a string to the list box of a combo box. If the combo box does not have the CBS_SORT style, the string is added to the end of the list. Otherwise, the string is inserted into the list, and the list is sorted. Syntax
To send this message, call the SendMessage function as follows.
lResult = SendMessage( // returns LRESULT in lResult (HWND) hWndControl, // handle to destination control (UINT) CB_ADDSTRING, // message ID (WPARAM) wParam, // = 0; not used, must be zero (LPARAM) lParam // = (LPARAM) (LPCTSTR) lParam; );
ParameterswParam
This parameter is not used.
lParam
Pointer to the null-terminated string to be added. If you create the combo box with an owner-drawn style but without the CBS_HASSTRINGS style, the value of the lParam parameter is stored as item data rather than the string it would otherwise point to. The item data can be retrieved or modified by sending the CB_GETITEMDATA or CB_SETITEMDATA message.
Return ValueThe return value is the zero-based index to the string in the list box of the combo box. If an error occurs, the return value is CB_ERR. If insufficient space is available to store the new string, it is CB_ERRSPACE. ResIf you create an owner-drawn combo box with the CBS_SORT style but without the CBS_HASSTRINGS style, the WM_COMPAREITEM message is sent one or more times to the owner of the combo box so the new item can be properly placed in the list. To insert a string at a specific location within the list, use the CB_INSERTSTRING message. If the combo box has WS_HSCROLL style and you add a string wider than the combo box, send a LB_SETHORIZONTALEXTENT message to ensure the horizontal scrollbar appears.Comclt32.dll version 5.0 or later: If CBS_LOWERCASE or CBS_UPPERCASE is set, the Unicode version of CB_ADDSTRING alters the string. If using read-only global memory, this causes the application to fail.-------------------------------------------------------------------------
在C中我看人家是这样写的,SendMessage(hwnd, CB_INSERTSTRING, 0,(LPARAM) "abc") ,但在delphi中怎么写都不对希望高手指点
-----------------------------------------------------------------------
CB_ADDSTRING Message --------------------------------------------------------------------------------An application sends a CB_ADDSTRING message to add a string to the list box of a combo box. If the combo box does not have the CBS_SORT style, the string is added to the end of the list. Otherwise, the string is inserted into the list, and the list is sorted. Syntax
To send this message, call the SendMessage function as follows.
lResult = SendMessage( // returns LRESULT in lResult (HWND) hWndControl, // handle to destination control (UINT) CB_ADDSTRING, // message ID (WPARAM) wParam, // = 0; not used, must be zero (LPARAM) lParam // = (LPARAM) (LPCTSTR) lParam; );
ParameterswParam
This parameter is not used.
lParam
Pointer to the null-terminated string to be added. If you create the combo box with an owner-drawn style but without the CBS_HASSTRINGS style, the value of the lParam parameter is stored as item data rather than the string it would otherwise point to. The item data can be retrieved or modified by sending the CB_GETITEMDATA or CB_SETITEMDATA message.
Return ValueThe return value is the zero-based index to the string in the list box of the combo box. If an error occurs, the return value is CB_ERR. If insufficient space is available to store the new string, it is CB_ERRSPACE. ResIf you create an owner-drawn combo box with the CBS_SORT style but without the CBS_HASSTRINGS style, the WM_COMPAREITEM message is sent one or more times to the owner of the combo box so the new item can be properly placed in the list. To insert a string at a specific location within the list, use the CB_INSERTSTRING message. If the combo box has WS_HSCROLL style and you add a string wider than the combo box, send a LB_SETHORIZONTALEXTENT message to ensure the horizontal scrollbar appears.Comclt32.dll version 5.0 or later: If CBS_LOWERCASE or CBS_UPPERCASE is set, the Unicode version of CB_ADDSTRING alters the string. If using read-only global memory, this causes the application to fail.-------------------------------------------------------------------------
在C中我看人家是这样写的,SendMessage(hwnd, CB_INSERTSTRING, 0,(LPARAM) "abc") ,但在delphi中怎么写都不对希望高手指点
解决方案 »
- 老妖妖结婚,没什么好送的,送点分吧...hehe^^
- 如果没有安装winrar如何压缩文件。
- 如何让已处于运行阶段的执行程序不再让它重复运行且恢复原窗口大小并置最前端?
- Delphi在现在主要开发一些什么东东!!??
- 急急急!!!怎样模拟shift+end 或者 shift+home 组合键!!!急急急,追加100分
- 第二次打开AdoDataSet ,查找不到数据,为什么?
- delphi小问题
- Delphi 获取远程SQL服务器的中可用的数据库备份(还原)路径
- 我的网卡没有驱动程序,也不知道牌子型号,该怎么办?
- ADOTable的Filter属性的用法?? 在线等待………………
- 请问谁有RAVE的技术资料!总共100分,我肯定结贴的!
- 请试试这个函数!!!!
var s: string;
begin
s := 'abc';
SendMessage(ComboBox1.Handle, CB_INSERTSTRING, 0,LPARAM(pchar(s)));
end;
var
S :LpctStr;
begin
S := PAnsichar('What');
sendMessage(cb.Handle,cb_addstring,0,LongInt(s));
end;
i:integer;
ss:string;
begin
ss:='hello';
i:=self.ComboBox1.Items.Count;
sendmessage(self.ComboBox1.Handle,CB_INSERTSTRING,i,Integer(ss));
self.ComboBox1.ItemIndex:=self.ComboBox1.Items.Count-1;
end;
调试通过,可行!
另外
jxc163(一水寒) :
delphi 中缺省把string转换为Ansistring,因此可不必 PAnsichar('What');
var
Ret: LongInt;
mText: PChar;
Buf: Integer;
begin
GetMem(mText, Length(Text));
StrCopy(mText, PChar(Text));
try
Buf := LongInt(mText);
SendMessage(hWnd, CB_INSERTSTRING, 0, Buf);
finally
FreeMem(mText, Length(Text));
end;
end;