Windows core Programming (5)

Source: Internet
Author: User

First, tool tip window

1. Sometimes when you move the mouse to a window control

There will be a hint to bounce out, and this principle is to give the ToolTip window

Send a message, Tm_addtool


2 where the parameter lparam is the toolinfo struct-body pointer

typedef struct tagtoolinfo{
UINT cbsize structure Body size

UINT Uflag Properties of the Focus field

HWND HWND contains the window caption of the tool, if the specified Ttf_idishwnd standard

The value is ignored, but the value of the UID member is used as the window handle

Uint_ptr UId Spit over Uflag contains Ttf_idishwnd

This value is the tool window handle, if there is a tool ID that contains this value,

Rect rect ignores this value if it contains TTF_IDISHWNDJ, otherwise specifies the tool size of the RECT structure

HINSTANCE hinst Application Instance handle

LPTSTR lpszText This field can have the following values: if the Lpstr_textcalback

The tool sends a TTN_NEEDTEXT message to its window to get the gist of the string

Displays the string corresponding to the resource ID if it is a resource identity

If it is a string pointer, displays the string that the character pointer points to

LPARAM LPARAM void* lpreserved

) Toolinfo;

}




Second, the window translucent

1. Create a window with extended properties, the CreateWindow function parameter has no extended attribute information

To use CREATEWINDOWEX with extended information

Parameter 1 Extended Style of window window

Parameter 2 window class name

Parameter 3 Window Caption

Parameter 4 window style

Parameter 5 6 coordinates

Parameter 7 8 size

Parameter 9 Parent window

Parameter 10 Window menu handle

Parameter 11 program Instance handle

Parameter 12 Creating a window additional data pointer

Passed through the CREATESTRUCT structure to the lparam parameter of the WM_CREATE message




2 Changing the window various properties: style, extension style, ID, window message process, user data, etc.

LONG SetWindowLong (

Parameter 1 window for changing properties

Parameter 2 nIndex type of change

Change style or extend style gwl_style Gwl_exstyle

ID type gwl_id

Application Handle Type Gwl_hinstance

User Data type Gwl_userdata

Window message processing type GWL) WNDPROC


The new property value of the LONG dwnewlong window, the specific property type depends on the nindex parameter

)

Returns the creation of the old property, which returns what depends on the nindex parameter




3 Getting the properties of a window

GetWindowLong

Parameter 1 window handle to get

Parameter 2 meaning and above nindex meaning

Returns the nindex parameter type for the corresponding return value


4. To modify the extended style, first get the original extended style

And then modify it, such as changing the normal window to a layer window

Get style

LONG Lexstyle = GetWindowLong (Hwnd,gwl_exstyle);

Modify Style

Lexstyle |= ws_ex_layered

Set style

SetWindowLong (Hwnd,gwl_exstyle,lexstyle );




5. Normal window becomes a layer window can have translucent effect

SetLayeredWindowAttributes

Set Layer Window Properties

Parameter 1 setting the Properties window

Parameter 2 mask color can be specified with RGB

Parameter 3 transparency value range (0-255) 0 fully transparent 255 opaque

Parameter 4 Transparent Way

Lwa_alpha parameter 2 Invalid parameter 3 valid

Lwa_colorkey in the window where the color is parameter 2 is transparent

Parameter 3 failure


Successful execution Returns True





Third, irregular window

1. Most of the windows are rectangular like this, when you want to make a

The irregular window should do this

2.SETWINDOWRGN function

Do not display outside of window area, equivalent to transparent message

Normal display within window area, editing of window area equivalent to window shape

Parameter 1 HWND to change the handle of the window area

Parameter 2 HRGN new window area handle

Parameter 3 BOOL sets the window area after the window interface is redrawn

Successfully returned a non-0 value


3. Window Rgn

CreateRectRgn creating a normal rectangular area

CreateRoundRectRgn creating rounded rectangles

CreateEllipticRgn creating a garden-shaped area

Extcreateregion Creating a custom zone


4 CreateRoundRectRgn

Parameter 1 upper left corner x coordinate

Parameter 2 y-coordinate, upper-left corner

Parameter 3 right descent x coordinate

Parameter 4 y-coordinate in the lower-right corner

int W rounded Corner garden width

int H Park Height


5.CreateEllipticRgn

Parameter 1 The upper left corner of the bounding rectangle of the garden x coordinate

Parameter 2 the upper left corner of the bounding rectangle of the garden y- coordinate

Parameter 3 The bounding rectangle of the garden right descent x coordinate

Parameter 4 the lower right corner of the bounding rectangle of the garden y- coordinate


6.Extcreateregion

Parameter 1 lpx to execute xform struct pointer, change with the created area

If the pointer is null, the Create-after area does not transform

DWORD ncount lpdata Pointer to the size of the control

CONST rgndata* lpdata Pointer to rgndata struct, containing area data information


7.RGNDATA Structural Body

Rgndataheader RDG pointer to rgndataheader struct variable for area header information

Char Buffer[1] Executes an arbitrary size buffer. RECT structure for storing area information


8.Rgndataheader Structural Body

Dwird dwsize structure Body size

The DWORD iType zone type must be rdh_rectangles

DWORD ncount The number of rectangles that make up the region

DWORD nrgnsize The buffer size of all rectangles that make up the region

Rect rectangle boundary of Rcbound area




Iv. intercepting window messages or events

1. Sometimes change the MessageBox of Windows to your own,

But he is in windows, we have no source code, so we need to use

Intercept his paint message and change his drawing effect.

2. It is possible to setwindowlong the process of his message by means of a sub-class method.

But where are you going to change that, if it's after he's bounced?

This gives a bad result, so you need to know where the window is to initialize the best

It is then modified, and the dialog box is typically initialized with the WM_INITDIALOG message.

So the best thing to do here is to change the child.

3. How do I know wm_initdialog the news?

Through the hooks in Windows



Five, hooks

The message is processed before the target message function is processed

1. Installing the hook function SetWindowsHookEx

Hhook SetWindowsHookEx (

int Idhook,//hook type


HOOKPROC LPFN,//HOOK program function pointer

(

if the dwThreadID parameter is 0 or a thread that is created by another process,

Then IPFN must point to the Hook program in the DLL,

If dwThreadID is the thread ID created for the current process, then IPFN can

A hook program to the current process, LPFN to HookProc

typedef LRESULT (callback* HOOKPROC) (int code,wparam,lparam)

Code prompts you whether to process the message, and if the parameter value is hc_action, you can handle

The message, if the code value is less than 0, does not need to process the message, which is to call the Callnext

The Hookex function and returns the value of the function,callnextHookex as the calling hook list

The next hook in the hook program.

)


HINSTANCE HMOD,//LPFN The instance handle of the program module where dwThreadID

The thread that is created for the current process is represented and the hook code is also in the current process.

Then Hmode must be null


The DWORD dwThreadID,//Hook program associates The identifier of the thread, if it is 0,

The hook program is associated with all programs, and the hook is the global Hook .

)




2. Hook type

Each type of hook allows the application to monitor different types of message processing mechanisms

Specifically: Wh_callwndproc and Wh_callwndprocret: These two types make you

Monitors messages sent to a window procedure, which is called before the system sends a message to the receive window procedure.

A wh_callwndproc type of hook that is called after a window procedure finishes processing a message

Wh_callwndprocret Types of Hooks

WH_CBT: The system calls the WH_CBT type hook before the following event

1) Activate, build, minimize, maximize, move, change window size, etc. window events

2) Complete System instructions

3) Mobile mouse from System message queue, keyboard event

4) Set the input focus event

5) synchronizing system Message Queuing events

Wh_getmessage: Monitors messages returned from Message Queuing and can be used

The hook type goes to monitor mouse and keyboard input, and other messages that have been sent to the message queue

Wh_keyboard: Applications can use hooks of type Wh_keybody to monitor the message queue

Keyboard messages,

Wh_mouse applications can use wh_mouse types of hooks to monitor mouse messages in Message Queuing



3. Attach the hook information bed to the next thread in the current hook chain, a hook program can call this

Information for handling hooks before or after a function

CallNextHookEx (

Hhook HHK, current hook handle

int NCode, equivalent to HookProc's NCode

WPARAM WPARAM, equivalent to HookProc's WPARAM

LPARAM LPARAM, equivalent to HookProc's LPARAM

)




4.HOOKPROC callback function

LRESULT Cakkback HookProc (
int ICode hc_action hc_getnext hc_skip hc_noremove .....

WPARAM depends on hook type

LPARAM depends on hook type

For example, the hook type is Wh_keyboard, so lparam and wparam are equivalent to Wm_keydown.

LPARAM and wparam, if the hook type is wh_callwndproc,wparam to indicate the message

Whether it originates from the current thread (nonzero, indicates the current thread, otherwise originates from another thread)

The lparam is a pointer to the cwpstruct struct body.


5. Uninstalling Hooks

UnhookWindowsHookEx

Install a successful hook before uninstalling

BOOL UnhookWindowsHookEx (

Hhook HHK//previous hook handle returned by Mount Hook

) successfully returns True




Windows core Programming (5)

Related Article

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.