Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Peekmessage issue with mousewheel

chunky_lover_23
Beginner
1,105 Views

I am using the following code to determine when the mousewheelis moving. It all works well but unfortuantely the peekmessage function continues to report mousewheel movement when there isn't any. Any movement of the mouse will cause the routine to return jdelta=0 but if you simply move the wheen and then touch nothing else it continually reports the last message.

I've tried various combinations of post message and send message but so far no joy. I'm working with opengl using the GLUT window manager if that helps.

subroutine get_mouse_wheel(hwnd, jdelta)
c
use dfwin
type (t_MSG) msg
c
jdelta=0
jreturn=peekmessage(msg,hwnd,0,0,PM_REMOVE)
if(msg.message .eq. WM_MOUSEWHEEL) then
c recognised mouswhel movement
jdelta=hiword(msg.wparam)
else
jdelta=0
end if
c
return
end

0 Kudos
4 Replies
Jugoslav_Dujic
Valued Contributor II
1,105 Views
You probably want just
jreturn=PeekMessage(msg,hwnd,WM_MOUSEWHEEL,WM_MOUSEWHEEL,PM_REMOVE)
because now, you're removing all messages from the queue in order to examine just one.

However, that isn't supposed to solve your problem -- I don't have an explanation to offer other than your mouse is perhaps broken?

MSDN says that "DefWindowProc propagates it up the parent chain until it finds a window that processes it." whatever that means, but it shouldn't affect your situation.
0 Kudos
chunky_lover_23
Beginner
1,105 Views

No the mouse works fine - its only this application that causes the issue.

Interestingly your code change in the peekmessage made the problem worse. Previously a subsequent mouse movement reset the wheel mesage. Now no amount of mouse movement resets the message. This kind of tells me the problem is fixable - I just don't know how.

0 Kudos
chunky_lover_23
Beginner
1,105 Views

I fixed it via a hint at:

http://www.genesis3d.com/forum/viewtopic.php?topic=1003944&forum=3http://www.genesis3d.com/forum/viewtopic.php?topic=1003944&forum=3

Code that works for me is ...

subroutine get_mouse_wheel(hwnd, jdelta)
c
c
use dfwin
type (t_MSG) msg
c
jdelta=0
jreturn=peekmessage(msg,hwnd,WM_MOUSEWHEEL,WM_MOUSEWHEEL,
& PM_NOREMOVE)
if(msg.message .eq. WM_MOUSEWHEEL) then
c recognised mouswhel movement
jdelta=hiword(msg.wparam)
msg.message=0
jsend=postmessage(hwnd,WM_MOUSEWHEEL,0,0)

end if
c
return
end
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,105 Views
I think my method was much better -- you're seriously hacking it now -- however, it wasn't the only required change. If you changed only that line, you get an undefined (read: most likely unchanged) Msg structure whenever there's no WM_MOUSEWHEEL pending. Instead, you need to check whether you actually retrieved the message:
subroutine get_mouse_wheel(hwnd, jdelta)
use dfwin
type (t_MSG) msg
 jdelta=0
c Check for pending WM_MOUSEWHEEL and remove it from the queue:
if (PeekMessage(msg,hwnd,WM_MOUSEWHEEL,WM_MOUSEWHEEL,PM_REMOVE).ne.0) then
c Retrieve the value ONLY if the message had existed:

jdelta=hiword(msg.wparam)
 end if
 return
end
If this doesn't work, well, I promise I'll do the actual testing in a real application... Smiley with tongue out [:-P]
0 Kudos
Reply