方法1.把combobox的autocomplete属性设为false可以解决乱码问题。
方法2.乱码是因为你使用了TXPMan控件,且在NT系统中使用。
在KeyPress事件中执行ComboBox_XPMan_KeyPress可解决北问题。
方法2.乱码是因为你使用了TXPMan控件,且在NT系统中使用。
在KeyPress事件中执行ComboBox_XPMan_KeyPress可解决北问题。
- function IsNTSystem:Boolean;
- var
- info:OSVERSIONINFO;
- begin
- info.dwOSVersionInfoSize:=sizeof(info);
- GetVersionEx(info);
- Result:=info.dwPlatformId=VER_PLATFORM_WIN32_NT;
- end;
- 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;
- 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;