PeekMessage does not work in VB .Net

G

Guest

I get the following VB6 sample and it doesn't work in VB .Net. Can anyone
help to make it work in VB .Net?

Structure POINTAPI
Dim x As Long
Dim y As Long
End Structure

Structure MSG
Dim hwnd As Long
Dim message As Long
Dim wParam As Long
Dim lParam As Long
Dim time As Long
Dim pt As POINTAPI
End Structure

Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA"
(ByVal lpMsg As MSG, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal
wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
 
C

Cor Ligthert [MVP]

John,

One and a half year ago and before that this newsgroup was sometimes full of
replies that a 'long' in VB6 is an Integer in VBNet.

Now we see those messages less, probably because most people try to avoid
API's now, however can it not be that?

I hope this helps,

Cor
 
D

Dragon

Hello,

That should work:

' When translating from VB6 you should always consider that Long's are
Integer's now

'Note the Auto modifier. Now it's PeekMessageW on WinNT and PeekMessageA
on Win9x
'lpMsg is ByRef, not ByVal
'Is more convenient to declare hwnd as IntPtr, not Integer
Friend Declare Auto Function PeekMessage Lib "user32.dll" ( _
ByRef lpMsg As MSG, _
ByVal hWnd As IntPtr, _
ByVal wMsgFilterMin As Integer, _
ByVal wMsgFilterMax As Integer, _
ByVal wRemoveMsg As Integer _
) As Boolean 'you can use Integer as return value type, but since it is
BOOL in winuser.h, Boolean type is more appropriate

'StructLayoutAttribute with Sequential layout kind should be appended to
PInvoke structs
<StructLayout(LayoutKind.Sequential)> Friend Structure MSG
Public hWnd As IntPtr
Public message As Integer
Public wParam As Integer
Public lParam As Integer 'Maybe you will want to put IntPtr
here
Public time As Integer
Public pt As POINT
End Structure

<StructLayout(LayoutKind.Sequential)> Friend Structure POINT
Public x As Integer
Public y As Integer
End Structure

Roman
 
M

m.posseth

Hello

if your task is to catch the messages that windows sends to your app in the
message queueyou might be interested the IMessageFilter interface that
..net provides

i can provide you with an example that uses this technique , you can see it
here

http://www.freevbcode.com/ShowCode.Asp?ID=5635

this will prefilter all messages send to the form and optionally cancel them



Michel Posseth [MCP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top