Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
registerwindowmessage (user32)
 
.
Summary

C# Signature:

[DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]
static extern uint RegisterWindowMessage(string lpString);

VB.NET Signature:

<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function RegisterWindowMessage( _
     ByVal lpString As String) As UInteger
End Function

Oxygene.NET Signature:

[DllImport("user32.dll", SetLastError := true, CharSet := CharSet.Auto)]
class method RegisterWindowMessage(lpString: String): UInt32; external;

VB Signature:

Declare Function RegisterWindowMessage Lib "user32.dll" (ByVal lpString As String) As Integer

User-Defined Types:

None.

Notes:

Unicode notification

    DllImport("user32.dll", EntryPoint = "RegisterWindowMessageW", SetLastError = true)]
    private static extern int RegisterWindowMessage(string lpString);

If you use the above notation, it will not be the Unicode call, Always add the CharSet=CharSet.Auto or CharSet.Unicode

In VB6 the definition for the API declaration should be:

Declare Function RegisterWindowMessage Lib "user32.dll" Alias "RegisterWindowMessageW" (ByVal lpString As long) As Integer

    strMessageToRegister = "QueryCancelAutoPlay"
    lngWindowMsg = RegisterWindowMessage(StrPtr(strMessageToRegister))

If you use RegisterWindowMessage("QueryCancelAutoPlay") it will NOT work, put the "QueryCancelAutoPlay" in a variable or constant and use that one.

Tips & Tricks:

Please add some!

Sample Code:

VB.NET Sample Code

    Dim MessageID As Integer
    MessageID = RegisterWindowMessage("QueryCancelAutoPlay")

C# Sample Code

//Register the message
lMsg = Win32.RegisterWindowMessage("WM_HTML_GETOBJECT");
//Get the object
Win32.SendMessageTimeout(windowHandle, lMsg, IntPtr.Zero, IntPtr.Zero, SendMessageTimeoutFlags.SMTO_ABORT_IF_HUNG, 1000, out lRes);
if(lRes != IntPtr.Zero)
{
    //Get the object from lRes
    htmlDoc= (mshtml.IHTMLDocument)Win32.ObjectFromLresult(lRes, IID_IHTMLDocument, IntPtr.Zero);
    return htmlDoc;
}

C# Sample Code

//provide a private internal message id
private UInt32 queryCancelAutoPlay = 0;

[DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]
static extern uint RegisterWindowMessage(string lpString);

/* only needed if your application is using a dialog box and needs to
* respond to a "QueryCancelAutoPlay" message, it cannot simply return TRUE or FALSE.
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
*/

protected override void WndProc(ref Message m)
{
    //calling the base first is important, otherwise the values you set later will be lost
    base.WndProc (ref m);

    //if the QueryCancelAutoPlay message id has not been registered...
    if (queryCancelAutoPlay == 0)
        queryCancelAutoPlay = RegisterWindowMessage("QueryCancelAutoPlay");

    //if the window message id equals the QueryCancelAutoPlay message id
    if ((UInt32)m.Msg == queryCancelAutoPlay)
    {
        /* only needed if your application is using a dialog box and needs to
        * respond to a "QueryCancelAutoPlay" message, it cannot simply return TRUE or FALSE.
        SetWindowLong(this.Handle, 0, 1);
        */
        m.Result = (IntPtr)1;
    }
} //WndProc

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions