WM_NULL message

来源:互联网 发布:iphone usb共享网络 编辑:程序博客网 时间:2024/06/02 00:31

WM_NULL message

2 out of 2 rated this helpful Rate this topic

Performs no operation. An application sends the WM_NULL message if it wants to post a message that the recipient window will ignore.

A window receives this message through its WindowProc function.

C++
#define WM_NULL                         0x0000

Parameters

wParam

This parameter is not used.

lParam

This parameter is not used.

Return value

Type: LRESULT

An application returns zero if it processes this message.

Remarks

For example, if an application has installed a WH_GETMESSAGE hook and wants to prevent a message from being processed, the GetMsgProc callback function can change the message number to WM_NULL so the recipient will ignore it.

As another example, an application can check if a window is responding to messages by sending the WM_NULL message with the SendMessageTimeoutfunction.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

See also

Windows Overview

Posts tagged WM_NULL

How to find whether a GUI application is freezed or is not responding?

3
5 YEARS AGO
by Jijo Raj in Uncategorized, Windows APIs

It’s common that windows citizens usually hang after long run. ;) Sometimes your application was meant to run for long period but stop responding after days or months. So how to automatically restart it if it gets hang? One method is to schedule a polling application which checks the application periodically. But how to determine whether an application is hung?


You can send WM_NULL message to the application window by using the api – SendMessageTimeout(). The WM_NULL does nothing. It can be used for poll the window. If an appliaction window is hung, it may not be able to process the WM_NULL message. If we use SendMessage(), since its a blocking call out caller thread too will be blocked.

So we should use SendMessageTimeout() in which we can specify a timeout. In SendMessageTimeout() we can specify a flag – SMTO_ABORTIFHUNG which returns immedietly if the targeted application is hung. So SendMessageTimeout() is perfect for our purpouse. See the sample code snippet below.

DWORD Result = 0;LRESULT Return = 0;// Handle of application window.// Get it by using FindWindowEx function.// Here for compilation, i get the handle of my dialog.HWND hWnd = GetSafeHwnd(); // Send the NULL message to the window.// SMTO_ABORTIFHUNG is specified to return immediately,// if the process is hung.Return = ::SendMessageTimeout( hWnd, // Window Handle                               WM_NULL, // Message                               0,       // WParam                               0,       // LParam                               SMTO_ABORTIFHUNG, // Flags                               500,              // Timeout                               &Result );        // Result// Check whether the WM_NULL message is processed.if( !Return ){    // Since the WM_NULL message is not processed,    // the targeted window is hung. Forget about it!}

Customize it according to your wish.


Just like null checking the pointer, you can check, whether a window is perfect by sending WM_NULL message.


Targeted Audience – Intermediate.