선언:
RegisterWindowMessage (C#)
[DllImport("user32")]
static extern uint RegisterWindowMessage(string lpString);
static extern uint RegisterWindowMessage(string lpString);
RegisterWindowMessage (VB.NET)
<DllImport("user32")> _
Shared Function RegisterWindowMessage(ByVal lpString As String) As UInteger
End Function
Shared Function RegisterWindowMessage(ByVal lpString As String) As UInteger
End Function
사용 예제:
RegisterWindowMessage Example (C#)
using System;
using System.Runtime.InteropServices;
namespace ApiReference {
class ApiExample {
[DllImport("user32")]
static extern uint RegisterWindowMessage(string lpString);
public static void Main(string[] args) {
Console.Write("등록할 메세지를 입력하세요: ");
// 메세지를 입력받고
string input = Console.ReadLine();
Console.WriteLine("{0} 메세지를 등록합니다.", input);
// 등록한다.
uint uMsg = RegisterWindowMessage(input);
// 메세지를 성공적으로 등록한 경우..
if ( uMsg != 0 ) {
Console.WriteLine("{0} 메세지가 등록되었습니다.", input);
Console.WriteLine("{0} 메세지에 대한 값은 0x{1:X4} ({1}) 입니다.", input, uMsg);
} else
Console.WriteLine("{0} 메세지를 등록하지 못했습니다.");
Console.ReadKey(true);
}
}
}
using System.Runtime.InteropServices;
namespace ApiReference {
class ApiExample {
[DllImport("user32")]
static extern uint RegisterWindowMessage(string lpString);
public static void Main(string[] args) {
Console.Write("등록할 메세지를 입력하세요: ");
// 메세지를 입력받고
string input = Console.ReadLine();
Console.WriteLine("{0} 메세지를 등록합니다.", input);
// 등록한다.
uint uMsg = RegisterWindowMessage(input);
// 메세지를 성공적으로 등록한 경우..
if ( uMsg != 0 ) {
Console.WriteLine("{0} 메세지가 등록되었습니다.", input);
Console.WriteLine("{0} 메세지에 대한 값은 0x{1:X4} ({1}) 입니다.", input, uMsg);
} else
Console.WriteLine("{0} 메세지를 등록하지 못했습니다.");
Console.ReadKey(true);
}
}
}
예제 코드 (.NET Fiddle)
RegisterWindowMessage Example (VB.NET)
Imports System
Imports System.Runtime.InteropServices
Class ApiExample
<DllImport("user32")>
Shared Function RegisterWindowMessage(ByVal lpString As String) As UInteger
End Function
Public Shared Sub Main(args As String())
Console.Write("등록할 메세지를 입력하세요: ")
' 메세지를 입력받고
Dim input As String = Console.ReadLine()
Console.WriteLine("{0} 메세지를 등록합니다.", input)
' 등록한다.
Dim uMsg As UInteger = RegisterWindowMessage(input)
' 메세지를 성공적으로 등록한 경우..
If uMsg <> 0 Then
Console.WriteLine("{0} 메세지가 등록되었습니다.", input)
Console.WriteLine("{0} 메세지에 대한 값은 0x{1:X4} ({1}) 입니다.", input, uMsg)
Else
Console.WriteLine("{0} 메세지를 등록하지 못했습니다.")
End If
Console.ReadKey(True)
End Sub
End Class
Imports System.Runtime.InteropServices
Class ApiExample
<DllImport("user32")>
Shared Function RegisterWindowMessage(ByVal lpString As String) As UInteger
End Function
Public Shared Sub Main(args As String())
Console.Write("등록할 메세지를 입력하세요: ")
' 메세지를 입력받고
Dim input As String = Console.ReadLine()
Console.WriteLine("{0} 메세지를 등록합니다.", input)
' 등록한다.
Dim uMsg As UInteger = RegisterWindowMessage(input)
' 메세지를 성공적으로 등록한 경우..
If uMsg <> 0 Then
Console.WriteLine("{0} 메세지가 등록되었습니다.", input)
Console.WriteLine("{0} 메세지에 대한 값은 0x{1:X4} ({1}) 입니다.", input, uMsg)
Else
Console.WriteLine("{0} 메세지를 등록하지 못했습니다.")
End If
Console.ReadKey(True)
End Sub
End Class
예제 코드 (.NET Fiddle)
예제 실행 결과:
매개변수 설명(기울임꼴로 표시된 매개변수는 생략 가능합니다):
lpString - 등록할 윈도우 메세지의 이름을 입력합니다.
API 설명:
사용자 정의 윈도우 메세지를 등록합니다.
참고:
RegisterWindowMessage (MSDN)
문자셋:
RegisterWindowMessageA (Ansi)
RegisterWindowMessageW (Unicode)
요구 사항:
Windows 2000 Professional 이상
Windows 2000 Server
비고:
이 API를 이용해 새롭게 정의된 메세지의 값은 반드시 0xC000 ~ 0xFFFF 범위 내의 값입니다.
.NET Fiddle 의 .NET 보안 수준으로 인해 P/Invoke 를 직접 테스트하실 수 없습니다. .NET Fiddle 사이트는 코드 참고용으로만 이용해 주시기 바랍니다.
Powered by SlaneR & TeamDEV Korea
Powered by SlaneR & TeamDEV Korea
'API Reference' 카테고리의 다른 글
62. PROCESS_EXTENDED_BASIC_INFORMATION (0) | 2015.10.09 |
---|---|
61. LoadLibraryEx (0) | 2015.10.03 |
59. IsWindow (0) | 2015.09.29 |
58. SystemFunction041 (RtlDecryptMemory) (0) | 2015.09.27 |
57. SystemFunction040 (RtlEncryptMemory) (0) | 2015.09.26 |