1、TComboBox乱码的问题:
procedure ComboBox_XPMan_KeyPress(Sender: TObject;
var Key: Char);
function HasSelectedText(CB_HWND:HWND; var StartPos, EndPos: DWORD): Boolean;
begin
SendMessage(CB_HWND, CB_GETEDITSEL, Integer(@StartPos),
Integer(@EndPos));
Result := EndPos > StartPos;
end;
function IsNTSystem: Boolean;
{功能:检测是否为NT系统}
var
info: OSVERSIONINFO;
begin
info.dwOSVersionInfoSize := sizeof(info);
GetVersionEx(info);
Result := info.dwPlatformId = VER_PLATFORM_WIN32_NT;
end;
var
StartPos, EndPos: DWORD;
OldText, SaveText: WideString; //关键在此,中间字符串要设为宽字符串型
LastByte: Integer;
TheCB:TComboBox;
CBHandle:HWND;
begin
if not IsNTSystem then Exit; //非NT系统则退出
TheCB:=TComboBox(Sender);
CBHandle:=TheCB.Handle;
if not TheCB.AutoComplete then exit;
if ord(Key) = VK_BACK then
begin
SaveText := TheCB.Text;
if HasSelectedText(CBHandle, StartPos, EndPos) then
begin
SendMessage(CBHandle,CB_GETEDITSEL,Integer(@StartPos),Integer(@EndPos));
Delete(SaveText, StartPos + 1, EndPos - StartPos);
SendMessage(CBHandle, CB_SETCURSEL, -1, 0);
TheCB.Text := SaveText;
SendMessage(CBHandle,CB_SETEDITSEL,0,MakeLParam(StartPos,StartPos));
Key := #0;
end
else
if(TheCB.Style in [csDropDown,csSimple]) and (Length(SaveText)>0) then
begin
LastByte := StartPos;
OldText := Copy(SaveText, 1, LastByte - 1);
SendMessage(CBHandle, CB_SETCURSEL, -1, 0);
TheCB.Text := OldText + Copy(SaveText, EndPos + 1, MaxInt);
SendMessage(CBHandle, CB_SETEDITSEL, 0, MakeLParam(LastByte - 1,
LastByte - 1));
Key := #0;
end;
end;
end;
在TComboBox的KeyPress事件中调用ComboBox_XPMan_KeyPress(Sender,Key);
2、排序问题