Windows Messages!

  • Thread starter Thread starter Afshin Eftekhar
  • Start date Start date
A

Afshin Eftekhar

when I was working with VB 6.0 I used to use API function "SendMessage" to
sending windows messages to forms and controls. Now In VB.net it seems that
VB doean't support API functions as usual and the function was replaced with
"Message" object. in message object there is "lparam" and "wparam" arguments
which are declared as "intptr" datatype. intptr is some kind of pointer. So,
I can not use API viewer constants like "HTCAPTION" in that case.

I don't understand how can I get the correct arguments and how can I use
"message" object instead of "SendMessage" function?

is there somebody who can help?
thanks
Afshin
 
Hi,

You can still use sendmessage. Instead of using as any like in vb6
declare it with the specific type for the argument you are using. You
can declare have more than one version of sendmessage. Here is a quick
example.

Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As
Integer, _
ByVal lParam As Integer) As Integer

Const WM_FONTCHANGE As Integer = &H1D
Const HWND_BROADCAST As Integer = &HFFFF

SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0)

Ken
---------------
 
* "Afshin Eftekhar said:
when I was working with VB 6.0 I used to use API function "SendMessage" to
sending windows messages to forms and controls. Now In VB.net it seems that
VB doean't support API functions as usual and the function was replaced with
"Message" object. in message object there is "lparam" and "wparam" arguments
which are declared as "intptr" datatype. intptr is some kind of pointer. So,
I can not use API viewer constants like "HTCAPTION" in that case.

You can still use API calls in a similar way.
I don't understand how can I get the correct arguments and how can I use
"message" object instead of "SendMessage" function?

Continue using 'SendMessage'.
 
in using API calls I have another problem, I can not find "hwnd" and
"Handle" property is an object deferent. I am using ".Handle.ToInt32" but it
seems it is not working yet.

SendMessage(Me.lblCaption.Handle.ToInt32, WM_NCLBUTTONDOWN, HTCAPTION, 0)

Af,
 
Hi,

Here I placed a button and label on a form. When you click on the
button it sends a wm_lbuttondown message to the label. You receive the
mousedown event for the label.


Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As IntPtr, ByVal wMsg As Integer, _
ByVal wParam As Integer, ByVal lParam As Integer) As Integer

Private Const HTCAPTION As Integer = 2
Private Const WM_LBUTTONDOWN As Integer = &H201

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

SendMessage(Label1.Handle, WM_LBUTTONDOWN, HTCAPTION, 0)

End Sub

Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown

MessageBox.Show("Mouse Down")

End Sub

Ken
----------------------
 
It looks like you're trying to move a borderless form with the aid of a
label.
If you use API then you'll also need to use the ReleaseCapture API before
SendMessage.
You do not need to use InterOp although there's no reason that you can't.
You'll find the non InterOp way here:
http://homepage.ntlworld.com/mdaudi100/alternate/misc.html

Just for information.

If you need an IntPtr but only have an Integer then use:
\\\
IntPtr.Op_Explicit(Integer)
///

Handle is an IntPtr

VB6 did not understand pointers and so Handles were declared as Longs.
VB.net does understand pointers and so Handles are declared as IntPtr.

VB6 Long is VB.net Int32
VB6 Integer is VB.net Int16
 
thanks

Ken Tucker said:
Hi,

Here I placed a button and label on a form. When you click on the
button it sends a wm_lbuttondown message to the label. You receive the
mousedown event for the label.


Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As IntPtr, ByVal wMsg As Integer, _
ByVal wParam As Integer, ByVal lParam As Integer) As Integer

Private Const HTCAPTION As Integer = 2
Private Const WM_LBUTTONDOWN As Integer = &H201

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

SendMessage(Label1.Handle, WM_LBUTTONDOWN, HTCAPTION, 0)

End Sub

Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown

MessageBox.Show("Mouse Down")

End Sub

Ken
 
Back
Top