Visual Basic Development Bookmark and Share   
 Home > Visual Basic General > Call GET_APPCOMMAND_LPARAM Macro?
 

Call GET_APPCOMMAND_LPARAM Macro?

Hello,

i've found this article in the MSDN:

http://msdn2.microsoft.com/en-us/library/ms646275.aspx

But i dont find any way to call the GET_APPCOMMAND_LPARAM macro.

Can anybody tell me how does this works?

Best Regards

Thorsten

eclere  Friday, August 31, 2007 6:04 PM
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = &H319 Then ' WM_APPCOMMAND
Dim cmd As Integer = (m.LParam.ToInt32() >> 16) And &HFFF
'--- Do your stuff
'...
End If
MyBase.WndProc(m)
End Sub
nobugz  Sunday, September 02, 2007 7:49 PM
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = &H319 Then ' WM_APPCOMMAND
Dim cmd As Integer = (m.LParam.ToInt32() >> 16) And &HFFF
'--- Do your stuff
'...
End If
MyBase.WndProc(m)
End Sub
nobugz  Sunday, September 02, 2007 7:49 PM

Hello,

thank you.

eclere  Sunday, September 02, 2007 7:58 PM
Seems to me that this code crashes on 64-bit machines. The call to ToInt32 throws OverflowException in some cases (say, mouse back button).
FiveCar  11 hours 15 minutes ago
Perhaps, but...it was not written to be run on a 64-bit machine, either.

The mouse back button is no coincidence...the MSB is set in that message.

Here is that MACRO, and a few others. Should be simple enough to convert, right?

btw, for your reference...that is from winuser.h You can find things like this using the help that comes with VS, and MS SDKs, by finding the function, or MACRO, structure, etc. and examining the Requirements section. Relevant header files are listed, and those are installed by VS, the Platform SDK, Device Driver SDK, XNA Studio, etc.



#define FAPPCOMMAND_MOUSE 0x8000
#define FAPPCOMMAND_KEY   0
#define FAPPCOMMAND_OEM   0x1000
#define FAPPCOMMAND_MASK  0xF000

#define GET_APPCOMMAND_LPARAM(lParam) ((short)(HIWORD(lParam) & ~FAPPCOMMAND_MASK))
#define GET_DEVICE_LPARAM(lParam)     ((WORD)(HIWORD(lParam) & FAPPCOMMAND_MASK))
#define GET_MOUSEORKEY_LPARAM         GET_DEVICE_LPARAM
#define GET_FLAGS_LPARAM(lParam)      (LOWORD(lParam))
#define GET_KEYSTATE_LPARAM(lParam)   GET_FLAGS_LPARAM(lParam)





  • Edited byjinzai 10 hours 52 minutes agoformatting
  •  
jinzai  10 hours 58 minutes ago
Seems to me that this code crashes on 64-bit machines. The call to ToInt32 throws OverflowException in some cases (say, mouse back button).

The short version:

If your CPU is 32 bit and your OS is 32 bit, use an Int32 for any API value not explicitly specified as something else.
If your CPU is 64 bit and your OS is 32 bit, use an Int32 for any API value not explicitly specified as something else.
If your CPU is 64 bit and your OS is also 64 bit, use an Int64 for any API value not explicitly specified as something else.
If your CPU is 32 bit and your OS is 64 bit, tell me how you managed that!

The long version:

Most of what comes back from Windows API Parameters is DWORD. Usually the documentation specifies this, but sometimes not. Where not explicitly specified as something, always assume DWORD.

A DWORD is always equivalent to a runtime-system native WORD, which means that on an x86 Platform it's 32 bit and on an x64 it's 64 bit.

Your simplest solution looks like this:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        'The SystemBitCount Size provided by the OS.
        'If BitVal is 8, system is x64 (64 bit).
        'If BitVal is 4, system is x86 (32 bit).
        Dim SystemBitCount As System.Int32 = System.IntPtr.Size
        'Use an Object instead of an explicitly bounded integer word
        Dim cmd As System.Object = Nothing

        If m.Msg = &H319 Then   ' WM_APPCOMMAND
            If SystemBitCount = 4 Then
                cmd = CType(((m.LParam.ToInt32() >> 16) And &HFFF), System.Object)
            ElseIf SystemBitCount = 8 Then
                cmd = CType(((m.LParam.ToInt64() >> 16) And &HFFF), System.Object)
            End If


            '--- Do your stuff
            '...

            'When-or-where-ever you need to employ this object-cast value in code...
            If SystemBitCount = 4 Then
                Dim MyOutputValue As System.Int32 = CType(cmd, System.Int32)
            ElseIf SystemBitCount = 8 Then
                Dim MyOutputValue As System.Int64 = CType(cmd, System.Int64)
            End If
        End If
        MyBase.WndProc(m)
    End Sub






It never hurts to try. In a worst case scenario, you'll learn from it.
Andrew B. Painter  10 hours 51 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• Help with vb .net 2008 Windows Service
• Crystal Report inside VB Code
• Listbox Item Value
• List Folderames in a folder
• sendmail function VBA Excel/Outlook
• Sending e-mail from Vis Basic
• "Can't register PopUpCombo class" error message
• Multiple Select Case problem
• TLB File using Visual Studio
• Request Failed Exception