Combobox的常用消息及使用,可用它来任意改变QQ的性别

CB的消息全在这了
CB_ADDSTRING
CB_DELETESTRING
CB_DIR
CB_FINDSTRING
CB_FINDSTRINGEXACT
CB_GETCOUNT
CB_GETCURSEL
CB_GETDROPPEDCONTROLRECT
CB_GETDROPPEDSTATE
CB_GETDROPPEDWIDTH
CB_GETEDITSEL
CB_GETEXTENDEDUI
CB_GETHORIZONTALEXTENT
CB_GETITEMDATA
CB_GETITEMHEIGHT
CB_GETLBTEXT
CB_GETLBTEXTLEN
CB_GETLOCALE
CB_GETTOPINDEX
CB_INITSTORAGE
CB_INSERTSTRING
CB_LIMITTEXT
CB_RESETCONTENT
CB_SELECTSTRING
CB_SETCURSEL
CB_SETDROPPEDWIDTH
CB_SETEDITSEL
CB_SETEXTENDEDUI
CB_SETHORIZONTALEXTENT
CB_SETITEMDATA
CB_SETITEMHEIGHT
CB_SETLOCALE
CB_SETTOPINDEX
CB_SHOWDROPDOWN
CBN_CLOSEUP
CBN_DBLCLK
CBN_DROPDOWN
CBN_EDITCHANGE
CBN_EDITUPDATE
CBN_ERRSPACE
CBN_KILLFOCUS
CBN_SELCHANGE
CBN_SELENDCANCEL
CBN_SELENDOK
CBN_SETFOCUS
WM_COMPAREITEM
WM_DRAWITEM
WM_MEASUREITEM


使用消息打开comboBox的下拉列表

SendMessage(ComboBox1.Handle, CB_SHOWDROPDOWN, Longint(True), 0);


改变Combobox下拉列表的宽度

向Combobox发送一个消息CB_SETDROPPEDWIDTH
comboBox1.Perform(CB_SETDROPPEDWIDTH, 100, 0);
//100为Combobox下拉的宽度.


如何任意改变QQ的性别


1。首先取得QQ个人设置资料中性别后面Combobox的句柄,可以使用函数
GetQQWnd('ComboBox',0)获得,前提要保证进入“QQ菜单 -> 个人设置”菜单。

function TForm1.GetQQWnd(ControlName:string;index:integer): HWND;
var
  i,j:integer;
  h,m,c: HWnd;
begin
  j:=0;
  for i := 0 to 30 do
  begin
    h := findwindowex(0, h, '#32770', nil);
    m := findwindowEX(h, 0, '#32770', nil);
    c := findwindowex(m, 0, PChar(ControlName), nil);
    if c <> 0 then
    begin
      if index=j then
      begin
        Result := c;
        exit;
      end;
      inc(j);
    end;
  end;
  result:=0;    
end;

2。调用cb的CB_INSERTSTRING消息将当前要添加的字符串插入到Combobox的下拉列表中。

3。重新修改你的QQ性别,点应用即可,原理同样可修改QQ的其他Combobox下
拉选项。

主要部分代码:

  if GetQQWnd('ComboBox',0)=0 then
  begin
    Application.MessageBox(
          '第一步:进入“QQ菜单 -> 个人设置”'+#10#13+
          '第二步:执行“添加”功能既可'+#10#13+
          '第三步:重新修改你的QQ性别','使用帮助',
          MB_ICONINFORMATION+MB_OK);
    exit;
  end;
  s := edit1.Text;
  SendMessage(GetQQWnd('ComboBox',0), CB_DELETESTRING, 0,LPARAM(pchar('男')));
  SendMessage(GetQQWnd('ComboBox',0), CB_INSERTSTRING, 0,LPARAM(pchar(s)));
  SendMessage(GetQQWnd('ComboBox',0), CB_SELECTSTRING, 0,LPARAM(pchar(s)));

取窗口句柄的函数

fHandle, 要查询的父窗口的Handle, Index,表示,要找第几个(比如,上次你说QQ窗口有好几个ComboBox)
调用EnumWindowByCaption方法大概是
EnumWindowByCaption(Handle, 'test', GetClassName(), '', nil, 0, Hnd);
CompareProc1,CompareProc2可以传入GetClassName或GetWindowName。

type
  TCompareProc = function (hWnd: HWND; lpClassName: PChar; nMaxCount: Integer): Integer;stdcall;
procedure EnumWindowByCaption(fHandle: THandle; const ACaption: string;
  CompareProc1: TCompareProc; const AClassName: string;
  CompareProc2: TCompareProc; const Index: Integer; out Hnd: THandle);

procedure EnumWindowByCaption(fHandle: THandle; const ACaption: string;
  CompareProc1: TCompareProc; const AClassName: string;
  CompareProc2: TCompareProc; const Index: Integer; out Hnd: THandle);
var
  hCurrentWindow:HWND;
  szText:array [0..254] of char;
  szText2:array [0..254] of char;
  I: Integer;
begin
  I := 0;
  hCurrentWindow := GetWindow (fHandle ,GW_CHILD);
  hCurrentWindow := GetWindow (hCurrentWindow ,GW_HWNDFIRST);
  repeat
    if (@CompareProc1 <> nil)and(@CompareProc2 <> nil) then
    begin
      if (CompareProc1(hCurrentWindow, @szText, 255) > 0)and(szText = ACaption)
        and(CompareProc2(hCurrentWindow, @szText2, 255) > 0)and(szText2 = AClassName) then
      begin
        if (I = Index) then
        begin
          Hnd := hCurrentWindow;
          Exit;
        end;
       Inc(I);
      end;
    end
    else if @CompareProc1 <> nil then
    if (CompareProc1(hCurrentWindow ,@szText,255) > 0)and(szText = ACaption) then
    begin
        if (I = Index) then
        begin
          Hnd := hCurrentWindow;
          Exit;
        end;
       Inc(I);
    end
    else if @CompareProc2 <> nil then
    if (CompareProc2(hCurrentWindow ,@szText,255) > 0)and(szText = ACaption) then
    begin
        if (I = Index) then
        begin
          Hnd := hCurrentWindow;
          Exit;
        end;
       Inc(I);
    end;

    if WordBool(hCurrentWindow) then
      EnumWindowByCaption(hCurrentWindow, ACaption, CompareProc1, AClassName, CompareProc2, Index, Hnd);

    hCurrentWindow := GetWindow (hCurrentWindow ,GW_HWNDNEXT);
  until hCurrentWindow = 0;
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值