473,320 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problems extracting Mouse position from LParam in WndProc

Hello,

I've overridden the WndProc function in my form to hand some special
behavior. Specifically, I look for the WM_NCMOUSEMOVE event to tell me
when the user is trying to move the window by draggin the title bar.
However, I am having trouble extracting the POINT structure that is
supposed to come with the message. For example:

Structure POINTS
Public x As Short
Public y As Short
End Structure

....

IF m.Msg = WM_NCMOUSEMOVE Then

Dim mousePos as New POINTS =
System.Runtime.Interopservices.Marshal.PtrToStruct ure(m.LParam,
GetType(POINTS))

....
End If

I continually receive a Null assignment exception. Is there a
diff/proper way to extact the POINTS struct that is supposed to come
with the System.Windows.Forms.Message structure?

Nov 21 '05 #1
4 7879
You might try something like this:

Structure POINTS
Public x As Integer
Public y As Integer
End Structure

Const WM_NCMOUSEMOVE As Integer = &HA0

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = NCMOUSEMOVE Then
Dim xPos As Short = GetLoWord(m.LParam.ToInt32)
Dim yPos As Short = GetHiWord(m.LParam.ToInt32)
End If
MyBase.WndProc(m)
End Sub

Private Function GetLoWord(ByVal lngWord As Integer) As Short
If CBool(lngWord And &H8000) Then
Return CShort(&H8000 Or (lngWord And &H7FFF))
Else
Return CShort(lngWord And &HFFFF)
End If
End Function

Private Function GetHiWord(ByVal lngWord As Integer) As Short
If CBool(lngWord And &H80000000) Then
Return CShort((lngWord \ 65535) - 1)
Else
Return CShort(lngWord \ 65535)
End If
End Function
Stefan
"crafuse" <vo*********@hotmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hello,

I've overridden the WndProc function in my form to hand some special
behavior. Specifically, I look for the WM_NCMOUSEMOVE event to tell me
when the user is trying to move the window by draggin the title bar.
However, I am having trouble extracting the POINT structure that is
supposed to come with the message. For example:

Structure POINTS
Public x As Short
Public y As Short
End Structure

...

IF m.Msg = WM_NCMOUSEMOVE Then

Dim mousePos as New POINTS =
System.Runtime.Interopservices.Marshal.PtrToStruct ure(m.LParam,
GetType(POINTS))

...
End If

I continually receive a Null assignment exception. Is there a
diff/proper way to extact the POINTS struct that is supposed to come
with the System.Windows.Forms.Message structure?

Nov 21 '05 #2
crafuse schrieb:
Hello,

I've overridden the WndProc function in my form to hand some special
behavior. Specifically, I look for the WM_NCMOUSEMOVE event to tell me
when the user is trying to move the window by draggin the title bar.
However, I am having trouble extracting the POINT structure that is
supposed to come with the message. For example:

Structure POINTS
Public x As Short
Public y As Short
End Structure

....

IF m.Msg = WM_NCMOUSEMOVE Then

Dim mousePos as New POINTS =
System.Runtime.Interopservices.Marshal.PtrToStruct ure(m.LParam,
GetType(POINTS))

....
End If

I continually receive a Null assignment exception. Is there a
diff/proper way to extact the POINTS struct that is supposed to come
with the System.Windows.Forms.Message structure?

m.lParam is not a pointer to a POINTS structure, thus the error. m.lParam
itself contains the values:

Dim x, y As Integer

x = (m.LParam.ToInt32 And &HFFFF)
y = (m.LParam.ToInt32 And &HFFFF0000) >> 16
Armin
Nov 21 '05 #3
Define a structure for POINT (as you already have) and use Message.GetLParam
supplying the structure type.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"crafuse" <vo*********@hotmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hello,

I've overridden the WndProc function in my form to hand some special
behavior. Specifically, I look for the WM_NCMOUSEMOVE event to tell me
when the user is trying to move the window by draggin the title bar.
However, I am having trouble extracting the POINT structure that is
supposed to come with the message. For example:

Structure POINTS
Public x As Short
Public y As Short
End Structure

...

IF m.Msg = WM_NCMOUSEMOVE Then

Dim mousePos as New POINTS =
System.Runtime.Interopservices.Marshal.PtrToStruct ure(m.LParam,
GetType(POINTS))

...
End If

I continually receive a Null assignment exception. Is there a
diff/proper way to extact the POINTS struct that is supposed to come
with the System.Windows.Forms.Message structure?

Nov 21 '05 #4
Oops, typo...

Should be:
If m.Msg = WM_NCMOUSEMOVE Then

Stefan
"Stefan De Schepper" <st****************@skynet.be> wrote in message
news:42*********************@news.skynet.be...
You might try something like this:

Structure POINTS
Public x As Integer
Public y As Integer
End Structure

Const WM_NCMOUSEMOVE As Integer = &HA0

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = NCMOUSEMOVE Then
Dim xPos As Short = GetLoWord(m.LParam.ToInt32)
Dim yPos As Short = GetHiWord(m.LParam.ToInt32)
End If
MyBase.WndProc(m)
End Sub

Private Function GetLoWord(ByVal lngWord As Integer) As Short
If CBool(lngWord And &H8000) Then
Return CShort(&H8000 Or (lngWord And &H7FFF))
Else
Return CShort(lngWord And &HFFFF)
End If
End Function

Private Function GetHiWord(ByVal lngWord As Integer) As Short
If CBool(lngWord And &H80000000) Then
Return CShort((lngWord \ 65535) - 1)
Else
Return CShort(lngWord \ 65535)
End If
End Function
Stefan
"crafuse" <vo*********@hotmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hello,

I've overridden the WndProc function in my form to hand some special
behavior. Specifically, I look for the WM_NCMOUSEMOVE event to tell me
when the user is trying to move the window by draggin the title bar.
However, I am having trouble extracting the POINT structure that is
supposed to come with the message. For example:

Structure POINTS
Public x As Short
Public y As Short
End Structure

...

IF m.Msg = WM_NCMOUSEMOVE Then

Dim mousePos as New POINTS =
System.Runtime.Interopservices.Marshal.PtrToStruct ure(m.LParam,
GetType(POINTS))

...
End If

I continually receive a Null assignment exception. Is there a
diff/proper way to extact the POINTS struct that is supposed to come
with the System.Windows.Forms.Message structure?


Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: paul francis | last post by:
Hi Please help because I'm really stuck: I'm trying to write an application in C# which can be used to track the mouse pointer position on any window. I'm trying to use a Global mouse hook to...
8
by: NeoAsimov | last post by:
Hello, There is what I want to do. I worked on the problem since 6 hours but I had a problem (probably stupid) and I dont know how to resolve it. I need to have an Mouse Event Click when...
1
by: redneon | last post by:
I'm trying to add another button to a window's title bar to use as a "keep this window on top" button. I've managed to draw the button using the code below (C#) but I'm having a couple of other...
1
by: mikelostcause | last post by:
I'm working on shutting down an app that runs in the system tray, I have no problems shutting down, but I have problems saving data first. if the base.WndProc(ref m) is placed at the top, it...
1
by: Benny Raymond | last post by:
I'm currently trying to implement a Form that uses the BorderStyle "None" property but still allows the user to resize, move the window around, etc. This is all working correctly - now I run...
3
by: akowald | last post by:
There's another topic like this but the code posted is in VB.NET. Well I need some help detecting mouse clicks outside the form. An event handler would be great but I can work with anything. ...
4
by: konafreeride | last post by:
Hello, Does anyone know of how I can go about suppressing a mouse click after I've handled it? I know this can be done for keystrokes via the Handled property, but I am unable to find a way to...
10
by: bern11 | last post by:
If Form1 opens Form2 modally, how do I capture clicks on Form1 when Form2 is open? I want to click on Form1 and read the mouse co-ordinates into Form2. Since Form2 is open modally, Form1...
5
by: RomeoPapacy | last post by:
I'm currently writing a replacement shell and am suffering from quite dire memory leaks, when running, every time I roll my mouse over the taskbar icon a new window scrolls out revealing the window's...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.