lpbyte_registerwindowmessage_ON_REGISTERED_MESSAGE

电脑杂谈  发布时间:2017-01-15 12:10:39  来源:网络整理
registerwindowmessageregisterwindowmessage

Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.

To create a page in a module other than user32, prefix the name with the module name and a period.

.Summary

/// <summary>

/// Defines a new window message that is guaranteed to be unique throughout the system. The message value can be used

/// when sending or posting messages.

/// <para>

/// Go to https://msdn.microsoft.com/en-us/library/windows/desktop/ms644947%28v=vs.85%29.aspx for more

/// information.

/// </para>

/// </summary>

/// <param>C++ ( lpString [in]. Type: LPCTSTR )<br /> The message to be registered.</param>

/// <returns>

/// C++ ( Type: UINT )<br /> If the message is successfully registered, the return value is a message identifier in the

/// range 0xC000 through 0xFFFF. If the function fails, the return value is zero.<br /><br /> To get extended error

/// information, call GetLastError.

/// </returns>

/// <remarks>

/// The <see cref="RegisterWindowMessage" /> function is typically used to register messages for communicating between

/// two cooperating applications. If two different applications register the same message string, the applications

/// return the same message value.The message remains registered until the session ends. Only use

/// <see cref="RegisterWindowMessage" /> when more than one application must process the same message.For sending

/// private messages within a window class, an application can use any integer in the range WM_USER through 0x7FFF.

/// <br />(Messages in this range are private to a window class, not to an application.For example, predefined control

/// classes such as BUTTON, EDIT, LISTBOX, and COMBOBOX may use values in this range.)

/// </remarks>

/// <example>

/// <code><![CDATA[

/////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;

///}

/// }

///]]></code>

/// </example>

[DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]

static extern uint RegisterWindowMessage(string lpString);

<DllImport("user32.dll", CharSet:=CharSet.Auto)> _

Private Shared Function RegisterWindowMessage( _

ByVal lpString As String) As UInteger

End Function

[DllImport("user32.dll", SetLastError := true, CharSet := CharSet.Auto)]

class method RegisterWindowMessage(lpString: String): UInt32; external;

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

None.

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.

Please add some!

VB.NET Sample Code

Dim MessageID As Integer

MessageID = RegisterWindowMessage("QueryCancelAutoPlay")

C# Sample Code

//Register the message

lMsg = Win32.RegisterWindowMessage("WM_HTML_GETOECT");

//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

Do you know one? Please contribute it!

Documentation

The RegisterWindowMessage API

ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.

4/25/2007 9:19:55 AM - josep1er@cmich.edu-141.209.229.179

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).


本文来自电脑杂谈,转载请注明本文网址:
http://xinshanjie.com/a/jisuanjixue/article-26452-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      • 潘岐林
        潘岐林

        他要的就是你这句话

      热点图片
      拼命载入中...