Delphi uses hooks to implement QQ Chat window modification (4)

Source: Internet
Author: User
Tags message queue

Hook type Idhook options:

Wh_msgfilter =-1; {thread-level; intercept the message that the user interacts with the control}

Wh_journalrecord = 0; {System level; records all Message Queuing input messages sent from Message Queuing, which occurs when messages are purged from the queue; available macro Records}

Wh_journalplayback = 1; {System level; Replay messages logged by Wh_journalrecord, that is, to re-feed these messages to the message queue}

Wh_keyboard = 2; {System-level or thread-level; intercept keyboard Message}

Wh_getmessage = 3; {System-level or thread-level; Intercept messages sent from Message Queuing}

Wh_callwndproc = 4; {System-level or thread-level; intercepts the message sent to the target window, which occurs when SendMessage is called}  WH_CBT = 5; {System-level or thread-level; intercept system basic messages such as window creation, activation, closing, maximum minimization, movement, etc.}  wh_sysmsgfilter = 6; {System level; intercepts the system-wide user-to-control interaction message}

Wh_mouse = 7; {System-level or thread-level; intercept mouse Message}

Wh_hardware = 8; {System-level or thread-level; intercept non-standard hardware (non-mouse, keyboard) messages}

Wh_debug = 9; {System-level or thread-level; called before other hook calls, for debugging hooks}

Wh_shell = ten; {System-level or thread-level; intercept messages sent to the shell application}

Wh_foregroundidle = one; {System-level or thread-level; Called when the program foreground thread is idle}

Wh_callwndprocret =n; {System-level or thread-level; intercept messages processed by the target window, after the SendMessage call occurs}

When the company did a campus card project, the inside of the computer room client needs to use the system of low-level keyboard hook Wh_keyboard_ll,

This is the first time I've touched a hook in Windows, because Wh_keyboard_ll is different from other hooks,

There are no definitions in the Delphi Windows Help and in the Windows.pas file, but there is a wh_keyboard_ll introduction in Microsoft's MSDN, so there is an interest in Windows ' system hooks after a solution.

After having done the mouse hook wh_mouse, low-level mouse hook wh_mouse_ll and the message hook wh_getmessage Small examples, are very interesting.

This time I'm using another system hook: WH_CBT.

Seeing the help in Delphi, I found a lot of features in Cbtproc:

Hcbt_activate
Hcbt_createwnd
Hcbt_destroywnd
Hcbt_minmax
Hcbt_movesize
Hcbt_setfocus
Hcbt_syscommand

(Not in detail, see the Help is written clearly)

Then they started experimenting and finally finished the little program. Let me briefly explain:

After running the program automatically hide, when you extract QQ or MSN messages will be surprised to find the chat window of the annoying "and xx chat" title is not, and the title replaced by "My Documents."

If you then change the Chat window icon to a document-style icon, who can see that it's your chat window?

(There are many ways to change the icon, you can use the program, you can also use the software to directly modify the resources of QQ files, this Part I did not do, here is just to provide a train of thought, interested friends can try their own, hehe).

The following code is posted:

Library HOOKPRJ;

 Uses Sysutils, Classes, Qqtitlehook in ' Qqtitlehook.pas ';

Exports Enablewheelhook, Disablewheelhook;
Begin hkqqchat:= 0;
End.

========================================================== unit Qqtitlehook;

Interface uses Windows, Messages, Sysutils, Dialogs, Commctrl, strutils;
 var Hkqqchat:hhook;
 The handle of the chat window is hwqqchat:hwnd;
 The title of the chat window tlqqchat:string;
 window class name clsname:string;

 Buf:array [0..1024] of char;

 Const//QQ The class name of the chat window csqq = ' #32770 '; function Titlehookproc (code:integer; wparam:wparam; lparam:lparam): LRESULT;
 stdcall; function Enumwindowstitlefunc (handle:thandle; lparam:lparam): Boolean;
 stdcall; function Enablewheelhook:boolean; stdcall;
 Export function Disablewheelhook:boolean; stdcall;

 Export Implementation//Hook handler function Titlehookproc (Code:integer; wparam:wparam; lparam:lparam): LRESULT;
 stdcall;
  Begin result:= 0;
   If code<0 then BEGIN result:= CallNextHookEx (Hkqqchat, Code, WParam, LParam); EXit
    End else If Code = Hcbt_activate THEN BEGIN//Get the handle of the activation window, and the window class name, and then determine if the window class name is #32770.
    hwqqchat:= HWND (WParam);
    GetClassName (Hwqqchat, buf, 1024);
    clsname:= string (BUF); If clsname = CSQQ THEN BEGIN//If the window class name is #32770, then all windows are enumerated and the window handle is passed in//"Here for demonstration purposes only, because many windows have a class name of #32770, so it is Rate will be very bottom, "//" interested friends can be based on the characteristics of QQ Chat window to increase the judging conditions, thereby improving efficiency.
    "EnumWindows (@EnumWindowsTitleFunc, hwqqchat);
   End
  End

 End function Enumwindowstitlefunc (handle:thandle; lparam:lparam): Boolean;
 stdcall; Begin if (Handle = LParam) and Boolean (GetWindowText (Handle, buf, and) THEN BEGIN//Get window caption According to window handle tlqqchat:= str
   ING (BUF); Then determine if the title contains "with ...". Chat "and other related characters, if included then this window is QQ Chat window if (POS (' with ', Tlqqchat) >0) and (POS (' chat ', tlqqchat) >0) THEN BEGIN//OK as Chat window after modification
    The window caption.
    Tlqqchat: = Ansireplacestr (Tlqqchat, ' with ', ' My Documents ');
    Tlqqchat: = Ansireplacestr (tlqqchat, ' chat ', ');
   SetWindowText (Handle, Pchar (tlqqchat));
   End "Ditto, this place can be freely controlled,Not only limited to QQ, MSN and other chat windows. "//" and want to change the title to what can also be freely controlled, if you can according to the modified window icon to determine the title "//" such as by modifying the window icon to replace the icon of Delphi, and then the title is modified to Delphi7, who can see the flaw. Haha "if ((POS (' Group-', Tlqqchat) >0) or (POS (' Advanced Group-', Tlqqchat) >0) THEN begin tlqqchat: = Ansireplacestr (tlqq
    Chat, ' group-', ' My Documents ');
    Tlqqchat: = Ansireplacestr (Tlqqchat, ' advanced ', ');
   SetWindowText (Handle, Pchar (tlqqchat));
   End
    MSN If POS ('-Conversation ', tlqqchat) >0 then begin tlqqchat: = Ansireplacestr (Tlqqchat, '-conversation ', ' My Documents ');
   SetWindowText (Handle, Pchar (tlqqchat));
  End
  End
 Result: =true;

 End Start hook function Enablewheelhook:boolean; stdcall;
 Export
   Begin if hkqqchat=0 THEN BEGIN hkqqchat: = SetWindowsHookEx (WH_CBT, @TitleHookProc, hinstance, 0);
  Result: = True;
  End else Result: = False;

  End Unload hook function Disablewheelhook:boolean; stdcall;
  Export
    Begin if Hkqqchat<>0 then BEGIN UnhookWindowsHookEx (Hkqqchat);
    Hkqqchat: = 0;
   Result: = True;
    End ElseResult: = False;

  End End.

====================================

Call the application is very simple, call enablewheelhook after hiding on it, exit Disablewheelhook OK.

Procedures only provide a train of thought, there are a lot of imperfect places, I hope that interested friends contact me, and improve the common exchange.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.