以下是在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中怎么写都不对希望高手指点

解决方案 »

  1.   

    修改如下:
    var s: string;
    begin
     s := 'abc';
    SendMessage(ComboBox1.Handle, CB_INSERTSTRING, 0,LPARAM(pchar(s)));
    end;
      

  2.   

    分数可以有都给我了:procedure TForm1.Button1Click(Sender: TObject);
    var
      S :LpctStr;
    begin
      S := PAnsichar('What');
      sendMessage(cb.Handle,cb_addstring,0,LongInt(s));
    end;
      

  3.   

    var
    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');
      

  4.   

    请问chw_csdn_chw(chw),这两种方法有什么不同?procedure SetWndText(hWnd: HWND; Text: string);
    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;