Announcement

Collapse
No announcement yet.

Msg and wParam in WndProc

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cliff Nichols
    replied
    Code:
    %DBT_DEVICEARRIVAL = &H8000 '32768 - Device or piece of media has been inserted and is now available
    %DBT_DEVICEARRIVAL_DECIMAL = 32768
    Cast these (and all) equates to a 32-bit type here:
    Code:
    %DBT_DEVICEARRIVAL = &H8000&
    %DBT_DEVICEARRIVAL_DECIMAL = 32768&
    Five bucks says you are running into compiler defaults treating &h8000 as a 16-bit item and 32768 as a 32-bit item, or vice versa.

    Just make 'em all 32-bit by suffixing "&" or "??"

    MCM
    Right you are MCM.....I did some further testing and found that although I declared
    %DBT_DEVICEARRIVAL = &H8000
    Integer has range of -32,768 to +32,767
    Long has range of -2,147,483,648 to +2,147,483,647
    Dword has a range of 0 to 4,294,967,295

    But declaring equates technically no matter the value the equates is
    -32,768 to +32,767

    So the value passed was -32768 and not the expected 32768 and I was only looking for positive values, not the inverse

    %DBT_DEVICEARRIVAL = &H8000 '32768
    No matter how I declare the value passed, both my equates and the value passed must match in order for me to catch the value passed......

    Leave a comment:


  • Michael Mattias
    replied
    Still not sure why this would affect results when I am checking for the equates so the values must match at some point wouldn't they????
    Code not shown.

    But ....I think untyped '&h8000' will be assigned to an integer, and thus be "negative" whereas '&h8000&' will be assigned to a long and will be "positive" ; therefore they will not compare "equal" unless you do something imaginative at the point of comparison.

    Leave a comment:


  • Cliff Nichols
    replied
    Taking another look back, I did like MCM said, and ended all Hex values with the ampersand, and sure enough the hex values are caught.

    Five bucks says you are running into compiler defaults treating &h8000 as a 16-bit item and 32768 as a 32-bit item, or vice versa.
    Still not sure why this would affect results when I am checking for the equates so the values must match at some point wouldn't they????

    Anyways, the fix in this case is found.....

    Off to figure out other anomalies like the horizontal scrollbar not working, and the device name not being read.

    Leave a comment:


  • Cliff Nichols
    replied
    Thanks for the try Jose....but same results unfortunately.

    One idea I have (since I am still learning this one) is to create a demo involving a complete different concept, and see if I get the same symptoms? or if my problem lays with API that I have not used much and need to learn more????

    Leave a comment:


  • José Roca
    replied
    Quite sure. For example, %DBT_USERDEFINED = &HFFFF equates to -1, not 65535. Use &HFFFF& or &HFFFF?? or &H0FFFF.

    Leave a comment:


  • Michael Mattias
    replied
    Code:
    %DBT_DEVICEARRIVAL                      = &H8000  '32768 - Device or piece of media has been inserted and is now available
    %DBT_DEVICEARRIVAL_DECIMAL              = 32768
    Cast these (and all) equates to a 32-bit type here:
    Code:
    %DBT_DEVICEARRIVAL                      = &H8000[B][COLOR="Red"]&[/COLOR][/B] 
    %DBT_DEVICEARRIVAL_DECIMAL          = 32768[B][COLOR="Red"]&[/COLOR][/B]
    Five bucks says you are running into compiler defaults treating &h8000 as a 16-bit item and 32768 as a 32-bit item, or vice versa.

    Just make 'em all 32-bit by suffixing "&" or "??"

    MCM

    Leave a comment:


  • Cliff Nichols
    replied
    Still kind of complicated, but the "MyWindowProc" is the core demo of the problem.

    I created equates for both Hex and Decimal values and tried a compile in PB8.04 in case it was a 9 problem...but same results....so I am obviously doing something wrong.

    "Demo.bas"
    Code:
    #PBFORMS CREATED V1.51
    '------------------------------------------------------------------------------
    ' The first line in this file is a PB/Forms metastatement.
    ' It should ALWAYS be the first line of the file. Other
    ' PB/Forms metastatements are placed at the beginning and
    ' end of "Named Blocks" of code that should be edited
    ' with PBForms only. Do not manually edit or delete these
    ' metastatements or PB/Forms will not be able to reread
    ' the file correctly.  See the PB/Forms documentation for
    ' more information.
    ' Named blocks begin like this:    #PBFORMS BEGIN ...
    ' Named blocks end like this:      #PBFORMS END ...
    ' Other PB/Forms metastatements such as:
    '     #PBFORMS DECLARATIONS
    ' are used by PB/Forms to insert additional code.
    ' Feel free to make changes anywhere else in the file.
    '------------------------------------------------------------------------------
    
    #COMPILE EXE
    #DIM ALL
        GLOBAL hDlg  AS DWORD
    
    '------------------------------------------------------------------------------
    '   ** Includes **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN INCLUDES
    #IF NOT %DEF(%WINAPI)
        #INCLUDE "WIN32API.INC"
    #ENDIF
    #INCLUDE "DBT.INC"
    #PBFORMS END INCLUDES
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Constants **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN CONSTANTS
    %IDD_DIALOG1 = 101
    %TxtDeviceNotify = 102
    #PBFORMS END CONSTANTS
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Declarations **
    '------------------------------------------------------------------------------
    DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    #PBFORMS DECLARATIONS
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN()
        ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowDIALOG1Proc()
    
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                ' Initialization handler
    
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CBWPARAM THEN
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
    
            CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CBCTL
    
                END SELECT
        END SELECT
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Dialogs **
    '------------------------------------------------------------------------------
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
        LOCAL lRslt AS LONG
    
    #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
    
        DIALOG NEW hParent, "Dialog1", 70, 70, 401, 230, %WS_POPUP OR %WS_BORDER _
            OR %WS_DLGFRAME OR %WS_THICKFRAME OR %WS_CAPTION OR %WS_SYSMENU OR _
            %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_CLIPSIBLINGS OR _
            %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
            %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
            %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
      CONTROL ADD LISTBOX, hDlg, %TxtDeviceNotify,, 5, 5, 390, 225, %LBS_NOTIFY OR %WS_BORDER OR %LBS_WANTKEYBOARDINPUT _
                              OR %LBS_DISABLENOSCROLL OR %WS_VSCROLL OR %WS_HSCROLL OR %WS_GROUP _
                              OR %WS_TABSTOP OR %LBS_NOINTEGRALHEIGHT', %WS_EX_CLIENTEDGE
    '     SendMessage GetDlgItem(hDlg, %TxtDeviceNotify), %LB_SETHORIZONTALEXTENT, 20, 0
    CONTROL SEND hDlg, %TxtDeviceNotify, %LB_SETHORIZONTALEXTENT, 100, 0
    #PBFORMS END DIALOG
    
    
    '  CALL DoRegisterDeviceInterface(hDlg , hDevNotify)             '<--- Docs say do not register for Attach Detach???
       glngPrevWndProc = GetWindowLong(hDlg , %GWL_WNDPROC)
       SetWindowLong hDlg , %GWL_WNDPROC, CODEPTR(MyWindowProc)
    
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
    
    
        IF hDevNotify <> 0 THEN
    LOCAL Success AS LONG
            success = UnregisterDeviceNotification(hDevNotify)
    MSGBOX "Success = " + STR$(success)
    
        END IF
       'pass control back to previous windows
    '   SetWindowLong hDlg, %GWL_WNDPROC, glngPrevWndProc
    
    #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
    #PBFORMS END CLEANUP
    
        FUNCTION = lRslt
    END FUNCTION
    '------------------------------------------------------------------------------
    
    SUB AddToList (BYVAL LbString AS STRING)
      LOCAL Result AS LONG
      LISTBOX ADD  hDlg, %TxtDeviceNotify, LbString
      CONTROL SEND hDlg, %TxtDeviceNotify, %LB_GETCOUNT, 0, 0 TO Result
      IF Result => 300 THEN LISTBOX DELETE hDlg, %TxtDeviceNotify, 1
      CONTROL SEND hDlg, %TxtDeviceNotify, %LB_GETCOUNT, 0, 0 TO Result
      CONTROL SEND hDlg, %TxtDeviceNotify, %LB_SETCURSEL, Result-1, 0
    END SUB
    "Dbt.inc"
    Code:
    '*** %WM_DEVICECHANGE/CBWPARAM specifies the event/CBLPARAM specifies data
    '***
    %WM_DEVICECHANGE                        = &H219   '537 - Notifies application of change to hardware configuration of device or computer. (received through WindowProc)
    %WM_DEVICECHANGE_DECIMAL                = 537     '&H219 - Notifies application of change to hardware configuration of device or computer. (received through WindowProc)
    'wParam - One of the following
    %DBT_CONFIGCHANGECANCELED               = &H19    '25 - Request to change the current configuration (dock or undock) has been canceled
    %DBT_CONFIGCHANGECANCELED_DECIMAL       = 25      '&H19 - Request to change the current configuration (dock or undock) has been canceled
    %DBT_CONFIGCHANGED                      = &H18    '24 - Current configuration changed, due to a dock or undock
    %DBT_CONFIGCHANGED_DECIMAL              = 24      '&H18 - Current configuration changed, due to a dock or undock
    %DBT_CUSTOMEVENT                        = &H8006  '32774 - Custom event
    %DBT_CUSTOMEVENT_DECIMAL                = 32774   '&H8006 - Custom event
    %DBT_DEVICEARRIVAL                      = &H8000  '32768 - Device or piece of media has been inserted and is now available
    %DBT_DEVICEARRIVAL_DECIMAL              = 32768   '&H8000 - Device or piece of media has been inserted and is now available
    %DBT_DEVICEQUERYREMOVE                  = &H8001  '32769 - Permission requested to remove Device or media. (Any application can deny this request and cancel the removal.)
    %DBT_DEVICEQUERYREMOVE_DECIMAL          = 32769   '&H8001 - Permission requested to remove Device or media. (Any application can deny this request and cancel the removal.)
    %DBT_DEVICEQUERYREMOVEFAILED            = &H8002  '32770 - Request to remove device or media canceled.
    %DBT_DEVICEQUERYREMOVEFAILED_DECIMAL    = 32770   '&H8002 - Request to remove device or media canceled.
    %DBT_DEVICEREMOVECOMPLETE               = &H8004  '32772 - Device or Media removed.
    %DBT_DEVICEREMOVECOMPLETE_DECIMAL       = 32772   '&H8004 - Device or Media removed.
    %DBT_DEVICEREMOVEPENDING                = &H8003  '32771 - Device or Media about to be removed. (Cannot be denied)
    %DBT_DEVICEREMOVEPENDING_DECIMAL        = 32771   '&H8003 - Device or Media about to be removed. (Cannot be denied)
    %DBT_DEVICETYPESPECIFIC                 = &H8005  '32773 - Device-specific event
    %DBT_DEVICETYPESPECIFIC_DECIMAL         = 32773   '&H8005 - Device-specific event
    %DBT_DEVNODES_CHANGED                   = &H7     '7 - Device added or removed from the system.
    %DBT_DEVNODES_CHANGED_DECIMAL           = 7       '&H7 - Device added or removed from the system.
    %DBT_QUERYCHANGECONFIG                  = &H17    '23 - Permission requested to change current configuration (dock or undock)
    %DBT_QUERYCHANGECONFIG_DECIMAL          = 23      '&H17 - Permission requested to change current configuration (dock or undock)
    %DBT_USERDEFINED                        = &HFFFF  '65535 - User-Defined
    %DBT_USERDEFINED_DECIMAL                = 65535   '&HFFFF - User-Defined
    'lParam - Pointer to structure that contains event-specific data. (Format depends on wParam)
    
    
    'Drive or media, networked or not
    %DBTF_MEDIA                  = 1     'Media comings and goings
    %DBTF_NET                    = 2     'Network volume
    
    %DEVICE_NOTIFY_ALL_INTERFACE_CLASSES    = &H4     'All Interfaces
    %DEVICE_NOTIFY_WINDOW_HANDLE            = 0       'Notifications sent using WM_POWERBROADCAST with wParam = PBT_POWERSETTINGCHANGE.
    %DEVICE_NOTIFY_SERVICE_HANDLE           = 1       'Notifications sent to HandlerEx callback function with dwControl = SERVICE_CONTROL_POWEREVENT and dwEventType = PBT_POWERSETTINGCHANGE.
    %GWL_WNDPROC                            = (-4)    'Sets new address for the window procedure. (Windows NT/2000/XP: You cannot change this attribute if the window does not belong to the same process as the calling thread.)
    %UNSAFE_REMOVE                          = &H1C    'Unsafe removal of device
    
    'DEV_BROADCAST_HDR Structure
    %DBT_DEVTYP_OEM                 = &H0   '0 - Original Equipment Manufacturer(OEM) or Independent Hardware Vendor(IHV) defined device type. This structure is a DEV_BROADCAST_OEM structure.
    %DBT_DEVTYP_DEVNODE             = &H1   '1 - Devnode number (specific to Windows 95)
    %DBT_DEVTYP_VOLUME              = &H2   '2 - Logical volume. This structure is a DEV_BROADCAST_VOLUME structure.
    %DBT_DEVTYP_PORT                = &H3   '3 - Port device (serial or parallel). This structure is a DEV_BROADCAST_PORT structure.
    %DBT_DEVTYP_NET                 = &H4   '4 - Network Resource (UNC)
    %DBT_DEVTYP_DEVICEINTERFACE     = &H5   '5 - Class of devices. This structure is a DEV_BROADCAST_DEVICEINTERFACE structure.
    %DBT_DEVTYP_HANDLE              = &H6   '6 - File system handle. This structure is a DEV_BROADCAST_HANDLE structure.
    
    TYPE DEV_BROADCAST_DEVICEINTERFACE
         DbDiSize AS LONG                   'Size of Structure
         DbDiDeviceType AS LONG             'Set to %DBT_DEVTYP_DEVICEINTERFACE.    '<--- Set to get Interface Type
         DbDiReserved AS LONG               'Reserved; do not use.                  '<--- No idea why, but its what the doc says
         DbDiClassguid AS GUID              'GUID for Interface Device Class
         DbDiName AS ASCIIZ * %MAX_PATH     'When returned through %WM_DEVICECHANGE message, it is converted to ANSI as appropriate. Services always receive a Unicode string, both (RegisterDeviceNotificationW or RegisterDeviceNotificationA)
    END TYPE
    
    TYPE DEV_BROADCAST_PORT
         DbpSize AS LONG                    'Size of Structure
         DbpDeviceType AS LONG              'Set to %DBT_DEVTYP_PORT                '<--- Set to check if a port device (see DEV_BROADCAST_DEVICEINTERFACE to find interface)
         DbpReserved AS LONG                'Reserved; do not use.                  '<--- No idea why, but its what the doc says
         DbpName AS ASCIIZ * %MAX_PATH      'Device 'Friendly' Name such as "Com1" and "Standard 28800 bps Modem"
    END TYPE
    
    TYPE DEV_BROADCAST_OEM
         DboSize       AS DWORD             'Size of Structure
         DboDeviceType AS DWORD             'Set to %DBT_DEVTYPE_OEM.
         DboReserved   AS DWORD             'Reserved; do not use.                  '<--- No idea why, but its what the doc says
         DboIdentifier AS DWORD             'OEM-specific identifier for the device.
         DboSuppfunc   AS DWORD             'OEM-specific function value. Possible values depend on the device.
    END TYPE
    
    TYPE DEV_BROADCAST_VOLUME
         Dbvsize       AS DWORD             'Size of Structure
         DbvDeviceType AS DWORD             'Set to %DBT_DEVTYP_VOLUME.
         DbvReserved   AS DWORD             'Reserved; do not use.                  '<--- No idea why, but its what the doc says
         DbvUnitmask   AS DWORD             'Logical drive, bit 0 is A:, bit 1 is B:...
         DbvFlags      AS WORD              'If %DBTF_MEDIA (Change affects media in drive). If Not %DBTF_MEDIA (Change affects physical device or drive.), If %DBTF_NET = network volume.
    END TYPE
    
    TYPE DEV_BROADCAST_HANDLE
         DbhSize       AS DWORD             'Size of Structure
         DbhDeviceType AS DWORD             'Set to %DBT_DEVTYP_HANDLE
         DbhReserved   AS DWORD             'Reserved; do not use.                  '<--- No idea why, but its what the doc says
         DbhHandle     AS DWORD             'Handle in RegisterDeviceNotification function.
         DbhHdevNotify AS DWORD             'Handle to device notification, returned by the RegisterDeviceNotification.
    '*** The following are valid only for DBT_CUSTOMEVENT
         DbhEventGuid  AS GUID              'Custom event GUID
         DbhNameOffset AS LONG              'The offset to event name.
         DbhData(0)    AS BYTE              'Optional binary data.
    END TYPE
    
    TYPE DEV_BROADCAST_HDR
         DbhSize AS LONG                    'Size of Structure (If User-Defined event, this must be size of header, plus size of variable-length data in _DEV_BROADCAST_USERDEFINED structure.
         DbhDeviceType AS LONG              'Device Type (Could be Interface/Handle/OEM/Port/Volume)
         DbhReserved AS LONG                'Reserved; do not use.                  '<--- No idea why, but its what the doc says
    END TYPE
    
    GLOBAL glngPrevWndProc AS LONG          'Original Proc to be notified
    GLOBAL hDevNotify AS LONG               'Handle to RegisterDeviceNotification function
    
    DECLARE SUB AddToList (BYVAL LbString AS STRING)
    
    FUNCTION MyWindowProc(BYVAL hWnd AS LONG, BYVAL Msg AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
         STATIC Message AS STRING
         DIM DeviceBroadCastHeader AS DEV_BROADCAST_HDR
         DIM DeviceBroadCastDeviceInterface AS DEV_BROADCAST_DEVICEINTERFACE
         SELECT CASE Msg
              CASE %WM_DEVICECHANGE
                   Message = Message + $TAB + "WM_DEVICECHANGE " '& Message
    '*** <--- For Some reason Hex values are not caught for wParam, but Decimal values are caught???????
                   SELECT CASE wParam
                        CASE %DBT_CONFIGCHANGECANCELED
                             Message = Message + $TAB + "wParam = DBT_CONFIGCHANGECANCELED"
                        CASE %DBT_CONFIGCHANGED
                             Message = Message + $TAB + "wParam = DBT_CONFIGCHANGED"
                        CASE %DBT_CUSTOMEVENT
                             Message = Message + $TAB + "wParam = DBT_CUSTOMEVENT"
                        CASE %DBT_DEVICEARRIVAL
                             ZeroMemory VARPTR(DeviceBroadCastHeader), LEN(DeviceBroadCastHeader)
                             ZeroMemory VARPTR(DeviceBroadCastDeviceInterface), LEN(DeviceBroadCastDeviceInterface)
                             Message = Message + $TAB + "wParam = DBT_DEVICEARRIVAL"
                             CopyMemory VARPTR(DeviceBroadCastHeader), BYVAL (lParam), LEN(DeviceBroadCastHeader)
                             SELECT CASE DeviceBroadCastHeader.DbhDevicetype
                                  CASE %DBT_DEVTYP_OEM
                                       Message = Message + $TAB + "Device Type: DBT_DEVTYP_OEM"
                                  CASE %DBT_DEVTYP_DEVNODE
                                       Message = Message + $TAB + "Device Type: DBT_DEVTYP_DEVNODE"
                                  CASE %DBT_DEVTYP_VOLUME
                                       Message = Message + $TAB + "Device Type: DBT_DEVTYP_VOLUME"
                                  CASE %DBT_DEVTYP_PORT
                                       Message = Message + $TAB + "Device Type: DBT_DEVTYP_PORT"
                                  CASE %DBT_DEVTYP_NET
                                       Message = Message + $TAB + "Device Type: DBT_DEVTYP_NET"
                                  CASE %DBT_DEVTYP_DEVICEINTERFACE
                                       Message = Message + $TAB + "Device Type: DBT_DEVTYP_DEVICEINTERFACE"
                                       CopyMemory VARPTR(DeviceBroadCastDeviceInterface), BYVAL (lParam), BYVAL (DeviceBroadCastHeader.DbhSize)
                                       Message = Message + $TAB + "Device Name: " & MID$(DeviceBroadCastDeviceInterface.DbDiName, 1, INSTR(DeviceBroadCastDeviceInterface.DbDiName, CHR$(0)))
                                  CASE %DBT_DEVTYP_HANDLE
                                       Message = Message + $TAB + "Device Type: DBT_DEVTYP_HANDLE"
                                  CASE ELSE
                                       Message = Message + $TAB + "Device Type unknown: " & STR$(DeviceBroadCastHeader.DbhDevicetype)
                             END SELECT
                        CASE %DBT_DEVICEQUERYREMOVE
                             Message = Message + $TAB + "wParam = DBT_DEVICEQUERYREMOVE"
                        CASE %DBT_DEVICEQUERYREMOVEFAILED
                             Message = Message + $TAB + "wParam = DBT_DEVICEQUERYREMOVEFAILED"
                        CASE %DBT_DEVICEREMOVECOMPLETE
                             Message = Message + $TAB + "wParam = DBT_DEVICEREMOVECOMPLETE"
                        CASE %DBT_DEVICEREMOVEPENDING
                             Message = Message + $TAB + "wParam = DBT_DEVICEREMOVEPENDING"
                        CASE %DBT_DEVICETYPESPECIFIC
                             Message = Message + $TAB + "wParam = DBT_DEVICETYPESPECIFIC"
                        CASE %DBT_DEVNODES_CHANGED
                             Message = Message + $TAB + "wParam = DBT_DEVNODES_CHANGED" + $TAB + STR$(lParam)
    'Message = Message + $tab + Str(glngPrevWndProc) + vbCr + Str(hWnd)
                        CASE %DBT_QUERYCHANGECONFIG
                             Message = Message + $TAB + "wParam = DBT_QUERYCHANGECONFIG"
                        CASE %DBT_USERDEFINED
                             Message = Message + $TAB + "wParam = DBT_USERDEFINED"
    
    
    
    '*** <--- For Some reason Hex values are not caught for wParam, but Decimal values are caught???????
                        CASE %DBT_CONFIGCHANGECANCELED_DECIMAL
                             Message = Message + $TAB + "wParam = DBT_CONFIGCHANGECANCELED_DECIMAL"
                        CASE %DBT_CONFIGCHANGED_DECIMAL
                             Message = Message + $TAB + "wParam = DBT_CONFIGCHANGED_DECIMAL"
                        CASE %DBT_CUSTOMEVENT_DECIMAL
                             Message = Message + $TAB + "wParam = DBT_CUSTOMEVENT_DECIMAL"
                        CASE %DBT_DEVICEARRIVAL_DECIMAL
                             ZeroMemory VARPTR(DeviceBroadCastHeader), LEN(DeviceBroadCastHeader)
                             ZeroMemory VARPTR(DeviceBroadCastDeviceInterface), LEN(DeviceBroadCastDeviceInterface)
                             Message = Message + $TAB + "wParam = DBT_DEVICEARRIVAL_DECIMAL"
                             CopyMemory VARPTR(DeviceBroadCastHeader), BYVAL (lParam), LEN(DeviceBroadCastHeader)
                             SELECT CASE DeviceBroadCastHeader.DbhDevicetype
                                  CASE %DBT_DEVTYP_OEM
                                       Message = Message + $TAB + "Device Type: DBT_DEVTYP_OEM"
                                       CopyMemory VARPTR(DeviceBroadCastDeviceInterface), BYVAL (lParam), BYVAL (DeviceBroadCastHeader.DbhSize)
                                       Message = Message + $TAB + "Device Name: " & MID$(DeviceBroadCastDeviceInterface.DbDiName, 1, INSTR(DeviceBroadCastDeviceInterface.DbDiName, CHR$(0)))
                                  CASE %DBT_DEVTYP_DEVNODE
                                       Message = Message + $TAB + "Device Type: DBT_DEVTYP_DEVNODE"
                                       CopyMemory VARPTR(DeviceBroadCastDeviceInterface), BYVAL (lParam), BYVAL (DeviceBroadCastHeader.DbhSize)
                                       Message = Message + $TAB + "Device Name: " & MID$(DeviceBroadCastDeviceInterface.DbDiName, 1, INSTR(DeviceBroadCastDeviceInterface.DbDiName, CHR$(0)))
                                  CASE %DBT_DEVTYP_VOLUME
                                       Message = Message + $TAB + "Device Type: DBT_DEVTYP_VOLUME"
                                       CopyMemory VARPTR(DeviceBroadCastDeviceInterface), BYVAL (lParam), BYVAL (DeviceBroadCastHeader.DbhSize)
                                       Message = Message + $TAB + "Device Name: " & MID$(DeviceBroadCastDeviceInterface.DbDiName, 1, INSTR(DeviceBroadCastDeviceInterface.DbDiName, CHR$(0)))
                                  CASE %DBT_DEVTYP_PORT
                                       Message = Message + $TAB + "Device Type: DBT_DEVTYP_PORT"
                                       CopyMemory VARPTR(DeviceBroadCastDeviceInterface), BYVAL (lParam), BYVAL (DeviceBroadCastHeader.DbhSize)
                                       Message = Message + $TAB + "Device Name: " & MID$(DeviceBroadCastDeviceInterface.DbDiName, 1, INSTR(DeviceBroadCastDeviceInterface.DbDiName, CHR$(0)))
                                  CASE %DBT_DEVTYP_NET
                                       Message = Message + $TAB + "Device Type: DBT_DEVTYP_NET"
                                       CopyMemory VARPTR(DeviceBroadCastDeviceInterface), BYVAL (lParam), BYVAL (DeviceBroadCastHeader.DbhSize)
                                       Message = Message + $TAB + "Device Name: " & MID$(DeviceBroadCastDeviceInterface.DbDiName, 1, INSTR(DeviceBroadCastDeviceInterface.DbDiName, CHR$(0)))
                                  CASE %DBT_DEVTYP_DEVICEINTERFACE
                                       Message = Message + $TAB + "Device Type: DBT_DEVTYP_DEVICEINTERFACE"
                                       CopyMemory VARPTR(DeviceBroadCastDeviceInterface), BYVAL (lParam), BYVAL (DeviceBroadCastHeader.DbhSize)
                                       Message = Message + $TAB + "Device Name: " & MID$(DeviceBroadCastDeviceInterface.DbDiName, 1, INSTR(DeviceBroadCastDeviceInterface.DbDiName, CHR$(0)))
                                  CASE %DBT_DEVTYP_HANDLE
                                       Message = Message + $TAB + "Device Type: DBT_DEVTYP_HANDLE"
                                       CopyMemory VARPTR(DeviceBroadCastDeviceInterface), BYVAL (lParam), BYVAL (DeviceBroadCastHeader.DbhSize)
                                       Message = Message + $TAB + "Device Name: " & MID$(DeviceBroadCastDeviceInterface.DbDiName, 1, INSTR(DeviceBroadCastDeviceInterface.DbDiName, CHR$(0)))
                                  CASE ELSE
                                       Message = Message + $TAB + "Device Type unknown: " & STR$(DeviceBroadCastHeader.DbhDevicetype)
                                       CopyMemory VARPTR(DeviceBroadCastDeviceInterface), BYVAL (lParam), BYVAL (DeviceBroadCastHeader.DbhSize)
                                       Message = Message + $TAB + "Device Name: " & MID$(DeviceBroadCastDeviceInterface.DbDiName, 1, INSTR(DeviceBroadCastDeviceInterface.DbDiName, CHR$(0)))
                             END SELECT
                        CASE %DBT_DEVICEQUERYREMOVE_DECIMAL
                             Message = Message + $TAB + "wParam = DBT_DEVICEQUERYREMOVE_DECIMAL"
                        CASE %DBT_DEVICEQUERYREMOVEFAILED_DECIMAL
                             Message = Message + $TAB + "wParam = DBT_DEVICEQUERYREMOVEFAILED_DECIMAL"
                        CASE %DBT_DEVICEREMOVECOMPLETE_DECIMAL
                             Message = Message + $TAB + "wParam = DBT_DEVICEREMOVECOMPLETE_DECIMAL"
                        CASE %DBT_DEVICEREMOVEPENDING_DECIMAL
                             Message = Message + $TAB + "wParam = DBT_DEVICEREMOVEPENDING_DECIMAL"
                        CASE %DBT_DEVICETYPESPECIFIC_DECIMAL
                             Message = Message + $TAB + "wParam = DBT_DEVICETYPESPECIFIC_DECIMAL"
                        CASE %DBT_DEVNODES_CHANGED_DECIMAL
                             Message = Message + $TAB + "wParam = DBT_DEVNODES_CHANGED" + $TAB + STR$(lParam)
    'Message = Message + $tab + Str(glngPrevWndProc) + vbCr + Str(hWnd)
                        CASE %DBT_QUERYCHANGECONFIG_DECIMAL
                             Message = Message + $TAB + "wParam = DBT_QUERYCHANGECONFIG_DECIMAL"
                        CASE %DBT_USERDEFINED_DECIMAL
                             Message = Message + $TAB + "wParam = DBT_USERDEFINED_DECIMAL"
    
    
    
                        CASE ELSE
    '                         Message = Message + $tab + "wParam = unknown = " & STR$(wParam) & $tab & "Device Type unknown: " & STR$(DeviceBroadCastHeader.DbhDevicetype)
                             Message = Message + $TAB + "wParam = " & STR$(wParam) & $TAB & "Device unknown: " & STR$(DeviceBroadCastHeader.DbhDevicetype)
                   END SELECT
                   AddToList Message
                   Message = ""
         END SELECT
    'Message = Message + $tab + Str(Message)
     ' pass the rest messages onto VB's own Window Procedure
      MyWindowProc = CallWindowProc(glngPrevWndProc, hWnd, Msg, wParam, lParam)
    END FUNCTION
    
    
    FUNCTION DoRegisterDeviceInterface(hWnd AS LONG, BYREF hDevNotify AS LONG) AS LONG
         LOCAL Message AS STRING
        DIM NotificationFilter AS DEV_BROADCAST_DEVICEINTERFACE
        NotificationFilter.DbDiSize = SIZEOF(NotificationFilter)
        NotificationFilter.DbDiDevicetype = %DBT_DEVTYP_DEVICEINTERFACE
    '    NotificationFilter.DbDiClassguid
    'TYPE DEV_BROADCAST_DEVICEINTERFACE
    '     DbDiSize AS LONG                   'Size of Structure
    '     DbDiDeviceType AS LONG             'Set to %DBT_DEVTYP_DEVICEINTERFACE.    '<--- Set to get Interface Type
    '     DbDiReserved AS LONG               'Reserved; do not use.                  '<--- No idea why, but its what the doc says
    '     DbDiClassguid AS GUID              'GUID for Interface Device Class
    '     DbDiName AS ASCIIZ * %MAX_PATH     'When returned through %WM_DEVICECHANGE message, it is converted to ANSI as appropriate. Services always receive a Unicode string, both (RegisterDeviceNotificationW or RegisterDeviceNotificationA)
    'END TYPE
    '    DIM NotificationFilter AS DEV_BROADCAST_PORT
    '    NotificationFilter.DbpSize = sizeof(NotificationFilter)
    '    NotificationFilter.DbpDevicetype = %DBT_DEVTYP_PORT
    
        hDevNotify = RegisterDeviceNotification(hWnd, VARPTR(NotificationFilter), %DEVICE_NOTIFY_WINDOW_HANDLE OR %DEVICE_NOTIFY_ALL_INTERFACE_CLASSES)
    
        IF hDevNotify = 0 THEN
            Message = Message + $TAB + "RegisterDeviceNotification failed: " '& STR$(Err.LastDllError)', vbOKOnly
    '        DoRegisterDeviceInterface = %False
            FUNCTION = %False
            EXIT FUNCTION
        END IF
    
    '    DoRegisterDeviceInterface = %True
        FUNCTION = %True
    END FUNCTION
    Still a work in progress....but should demo the problem.

    One other side problem I am having is getting the listbox to let me Horizontal Scroll (missing something there too I guess)

    Leave a comment:


  • Michael Mattias
    replied
    >Am I missing something??????

    Only the demo you said you are making up.

    I have never had a problem freely interspersing hex and decimal decimal literals with PB.

    I also would never use a numeric literal for wMSG (I'd always use the equate).

    I do use numeric literals for wParam and lparam, but only when sending or posting a message, never when reading.

    BTW, "msg.. and wparam are declared as hex values" does not make sense.
    Do you mean..
    Code:
     SELECT CASE AS LONG wMSg 
         CASE &h123 
             IF wParam = &h87B THEN 
              ....
    ..???

    UNLESS... you have those defined AS LONG and bit 31 is set (when cast as LONG is negative)... I know HEX$ does some unusual things with negative arguments.

    But either SELECT CASE AS LONG or the new BITSE function should clean those up for you.

    Leave a comment:


  • Edwin Knoppert
    replied
    >and wParam are declared as hex values

    Ploink!

    Maybe.. if you need to 'send' something to a parent, use the WM_NOTIFY and create a custom NMHDR based structure..
    ?

    Leave a comment:


  • Cliff Nichols
    started a topic Msg and wParam in WndProc

    Msg and wParam in WndProc

    I am working on a a demo of the problem, but maybe someone knows before I demo.

    I have a situation that in my callback, if my checks for Msg, and wParam are declared as hex values, then my procedure catches the Msg, but not the wParam for values I am checking for. If I declare my wParam checks as Decimal value they do get caught.

    Debugger shows both values when checking the actual value (yep I checked, just in case I made a mistake in converting Decimal to Hex and back again, and all the numbers match)

    Am I missing something??????

    (Hope to have a demo worked up soon to show actual code)
Working...
X