SendMessage

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a WinForms application, part of which was done by another programmer.
It contains this code:

[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(int hWnd, int Msg, int wParam, int
lParam);

int ret = SendMessage((int)TCombo.Handle, 0x100,
0x73, 1);

I understand that this is a call to a function is user32.dll, but I can not
find a resource to lookup what function it is, or what it is doing. I
expected to be able to search for user32.dll, and get a list of functions it
contains, but I have failed. If anyone could guide me to such a list, I would
appreciate it.

As a bonus, it anyone could tell me what it is doing, and if there is a
proper WinForms way of doing it instead, that would be ideal.

Thanks.
 
I have a WinForms application, part of which was done by another programmer.
It contains this code:

[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(int hWnd, int Msg, int wParam, int
lParam);

int ret = SendMessage((int)TCombo.Handle, 0x100,
0x73, 1);

I understand that this is a call to a function is user32.dll, but I can not
find a resource to lookup what function it is, or what it is doing. I
expected to be able to search for user32.dll, and get a list of functions it
contains, but I have failed. If anyone could guide me to such a list, I would
appreciate it.

As a bonus, it anyone could tell me what it is doing, and if there is a
proper WinForms way of doing it instead, that would be ideal.

Thanks.

Windows controls are managed almost exclusively with messages.
Keyboard and mouse events generate messages as do many other
operations.

SendMessage is the Windows API call that sends a message. The first
parameter is the handle of the window that will be the recipient of
the message. In this case it is the Windows window for TCombo. The
second parameter is the message code and the next two are parameters
for the message.

I believe the 0x100 is WM_KEYDOWN. If so, then 0x73 is the virtual
keycode and 1 is the repeat count. It appears that 0x73 is F4
(<http://msdn2.microsoft.com/en-us/library/ms645540.aspx>). Therefore
this code sends an F4 keystroke to the TCombo windows control.
 
Richard MSL said:
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(int hWnd, int Msg, int wParam, int
lParam);

In addition to the other reply, note that the 'hWnd' parameter's type must
be 'IntPtr' instead of 'int' to make the code work on 64-bit systems.
 
Hi Richard,

Jack has given a good explanation of the Win32 API function SendMessage and
the meaning of the code " int ret = SendMessage((int)TCombo.Handle, 0x100,
0x73, 1);".

If you'd like to get more information about a Win32 API function, you can
look it up in MSDN. For example, the following is the MSDN document for the
function SendMessage:
http://msdn2.microsoft.com/en-us/library/ms644950.aspx

As for the list of all functions that a dll contains, you can get it using
the Dependency Walker tool. Open the VS05 Command Prompt and type 'depends'
and the Dependency Walker tool will be launched.

In the Dependency Walker, open the dll file, e.g.
C:\windows\system32\user32.dll. The functions that the dll contains are
listed in the Export Function ListView, which is the right and middle list
view in the Dependency Walker window.
and if there is a proper WinForms way of doing it instead

No, there isn't a proper .NET way to do what the SendMessage function does
instead. Classes in WinForms are almost wrappers of the corresponding
Win32 native controls or functions, but not all native functions has a
counterpart .NET function. In this case, we have to use Interop services to
call into unmanaged code.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks to all for the help, I appreciate it.

Linda Liu said:
Hi Richard,

Jack has given a good explanation of the Win32 API function SendMessage and
the meaning of the code " int ret = SendMessage((int)TCombo.Handle, 0x100,
0x73, 1);".

If you'd like to get more information about a Win32 API function, you can
look it up in MSDN. For example, the following is the MSDN document for the
function SendMessage:
http://msdn2.microsoft.com/en-us/library/ms644950.aspx

As for the list of all functions that a dll contains, you can get it using
the Dependency Walker tool. Open the VS05 Command Prompt and type 'depends'
and the Dependency Walker tool will be launched.

In the Dependency Walker, open the dll file, e.g.
C:\windows\system32\user32.dll. The functions that the dll contains are
listed in the Export Function ListView, which is the right and middle list
view in the Dependency Walker window.


No, there isn't a proper .NET way to do what the SendMessage function does
instead. Classes in WinForms are almost wrappers of the corresponding
Win32 native controls or functions, but not all native functions has a
counterpart .NET function. In this case, we have to use Interop services to
call into unmanaged code.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top