Home » Source Code » USB » usbview.c

usbview.c ( File view )

From:USB
  • By 2010-12-06
  • View(s):6
  • Download(s):0
  • Point(s): 1
			/*++

Copyright (c) 1997-1998 Microsoft Corporation

Module Name:

    USBVIEW.C

Abstract:

    This is the GUI goop for the USBVIEW application.

Environment:

    user mode

Revision History:

    04-25-97 : created

--*/

//*****************************************************************************
// I N C L U D E S
//*****************************************************************************
#include <windows.h>
#include <basetyps.h>
#include <windowsx.h>
#include <initguid.h>
#include "devioctl.h"
#include "usbioctl.h"
#include <dbt.h>
#include <stdio.h>

#include "resource.h"
#include "usbview.h"


typedef  PVOID           HDEVNOTIFY;
typedef struct _DEV_BROADCAST_DEVICEINTERFACE_A {

    DWORD       dbcc_size;
    DWORD       dbcc_devicetype;
    DWORD       dbcc_reserved;
    GUID        dbcc_classguid;
    char        dbcc_name[1];

} DEV_BROADCAST_DEVICEINTERFACE_A, *PDEV_BROADCAST_DEVICEINTERFACE_A;
typedef DEV_BROADCAST_DEVICEINTERFACE_A   DEV_BROADCAST_DEVICEINTERFACE;
typedef PDEV_BROADCAST_DEVICEINTERFACE_A  PDEV_BROADCAST_DEVICEINTERFACE;
#define DBT_DEVTYP_DEVICEINTERFACE      0x00000005  // device interface class
#define DBT_DEVTYP_HANDLE               0x00000006  // file system handle
#define DEVICE_NOTIFY_WINDOW_HANDLE     0x00000000
#define DEVICE_NOTIFY_SERVICE_HANDLE    0x00000001
WINUSERAPI
HDEVNOTIFY
WINAPI
RegisterDeviceNotificationA(
    IN HANDLE hRecipient,
    IN LPVOID NotificationFilter,
    IN DWORD Flags
    );
WINUSERAPI
HDEVNOTIFY
WINAPI
RegisterDeviceNotificationW(
    IN HANDLE hRecipient,
    IN LPVOID NotificationFilter,
    IN DWORD Flags
    );
#define RegisterDeviceNotification  RegisterDeviceNotificationA

WINUSERAPI
BOOL
WINAPI
UnregisterDeviceNotification(
    IN HDEVNOTIFY Handle
    );



//*****************************************************************************
// D E F I N E S
//*****************************************************************************

// window control defines
//
#define SIZEBAR             0
#define WINDOWSCALEFACTOR   15

//*****************************************************************************
// L O C A L    F U N C T I O N    P R O T O T Y P E S
//*****************************************************************************

int WINAPI
WinMain (
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR     lpszCmdLine,
    int       nCmdShow
);

BOOL
CreateMainWindow (
    int nCmdShow
);

VOID
ResizeWindows (
    BOOL    bSizeBar,
    int     BarLocation
);

LRESULT CALLBACK
MainDlgProc (
    HWND   hwnd,
    UINT   uMsg,
    WPARAM wParam,
    LPARAM lParam
);

BOOL
USBView_OnInitDialog (
    HWND    hWnd,
    HWND    hWndFocus,
    LPARAM  lParam
);

VOID
USBView_OnClose (
    HWND hWnd
);

VOID
USBView_OnCommand (
    HWND hWnd,
    int  id,
    HWND hwndCtl,
    UINT codeNotify
);

VOID
USBView_OnLButtonDown (
    HWND hWnd,
    BOOL fDoubleClick,
    int  x,
    int  y,
    UINT keyFlags
);

VOID
USBView_OnLButtonUp (
    HWND hWnd,
    int  x,
    int  y,
    UINT keyFlags
);

VOID
USBView_OnMouseMove (
    HWND hWnd,
    int  x,
    int  y,
    UINT keyFlags
);

VOID
USBView_OnSize (
    HWND hWnd,
    UINT state,
    int  cx,
    int  cy
);

LRESULT
USBView_OnNotify (
    HWND    hWnd,
    int     DlgItem,
    LPNMHDR lpNMHdr
);

BOOL
USBView_OnDeviceChange (
    HWND  hwnd,
    UINT  uEvent,
    DWORD dwEventData
);


VOID DestroyTree (VOID);

VOID RefreshTree (VOID);

LRESULT CALLBACK
AboutDlgProc (
    HWND   hwnd,
    UINT   uMsg,
    WPARAM wParam,
    LPARAM lParam
);

VOID
WalkTree (
    HTREEITEM        hTreeItem,
    LPFNTREECALLBACK lpfnTreeCallback,
    DWORD            dwRefData
);

VOID
ExpandItem (
    HWND      hTreeWnd,
    HTREEITEM hTreeItem
);

//*****************************************************************************
// G L O B A L S    P R I V A T E    T O    T H I S    F I L E
//*****************************************************************************

HINSTANCE       ghInstance;
HWND            ghMainWnd;
HMENU           ghMainMenu;
HWND            ghTreeWnd;
HWND            ghEditWnd;
HWND            ghStatusWnd;
HCURSOR         ghSplitCursor;

int             gBarLocation    = 0;
BOOL            gbButtonDown    = FALSE;
HTREEITEM       ghTreeRoot      = NULL;

BOOL            gDoAutoRefresh  = FALSE;
BOOL            gDoConfigDesc   = FALSE;

// added
int             giGoodDevice;
int             giBadDevice;
int             giComputer;
int             giHub;
int             giNoDevice;
HDEVNOTIFY      gNotifyDevHandle;
HDEVNOTIFY      gNotifyHubHandle;


//*****************************************************************************
//
// WinMain()
//
//*****************************************************************************

int WINAPI
WinMain (
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR     lpszCmdLine,
    int       nCmdShow
)
{

    MSG     msg;
    HACCEL  hAccel;

    ghInstance = hInstance;

    ghSplitCursor = LoadCursor(ghInstance,
                               MAKEINTRESOURCE(IDC_SPLIT));

    if (!ghSplitCursor)
    {

        OOPS();
        return 0;
    
}

    hAccel = LoadAccelerators(ghInstance,
                              MAKEINTRESOURCE(IDACCEL));

    if (!hAccel)
    {

        OOPS();
        return 0;
    
}

    if (!CreateTextBuffer())
    {

        return 0;
    
}

    if (!CreateMainWindow(nCmdShow))
    {

        return 0;
    
}

    while (GetMessage(&msg, NULL, 0, 0))
    {

        if (!TranslateAccelerator(ghMainWnd,
                                  hAccel,
                                  &msg) &&
            !IsDialogMessage(ghMainWnd,
                             &msg))
        {

            TranslateMessage(&msg);
            DispatchMessage(&msg);
        
}
    
}

    DestroyTextBuffer();

    CHECKFORLEAKS();

    return 1;

}

//*****************************************************************************
//
// CreateMainWindow()
//
//*****************************************************************************

BOOL
CreateMainWindow (
    int nCmdShow
)
{

    RECT rc;

    InitCommonControls();

    ghMainWnd = CreateDialog(ghInstance,
                             MAKEINTRESOURCE(IDD_MAINDIALOG),
                             NULL,
                             MainDlgProc);

    if (ghMainWnd == NULL)
    {

        OOPS();
        return FALSE;
    
}

    GetWindowRect(ghMainWnd, &rc);

    gBarLocation = (rc.right - rc.left) / 3;

    ResizeWindows(FALSE, 0);

    ShowWindow(ghMainWnd, nCmdShow);

    UpdateWindow(ghMainWnd);

    return TRUE;

}


//*****************************************************************************
//
// ResizeWindows()
//
// Handles resizing the two child windows of the main window.  If
// bSizeBar is true, then the sizing is happening because the user is
// moving the bar.  If bSizeBar is false, the sizing is happening
// because of the WM_SIZE or something like that.
//
//*****************************************************************************

VOID
ResizeWindows (
    BOOL    bSizeBar,
    int     BarLocation
)
{

    RECT    MainClientRect;
    RECT    MainWindowRect;
    RECT    TreeWindowRect;
    RECT    StatusWindowRect;
    int     right;

    // Is the user moving the bar?
    //
    if (!bSizeBar)
    {

        BarLocation = gBarLocation;
    
}

    GetClientRect(ghMainWnd, &MainClientRect);

    GetWindowRect(ghStatusWnd, &StatusWindowRect);

    // Make sure the bar is in a OK location
    //
    if (bSizeBar)
    {

        if (BarLocation <
            GetSystemMetrics(SM_CXSCREEN)/WINDOWSCALEFACTOR)
        {

            return;
        
}

        if ((MainClientRect.right - BarLocation) <
            GetSystemMetrics(SM_CXSCREEN)/WINDOWSCALEFACTOR)
        {

            return;
        
}
    
}

    // Save the bar location
    //
    gBarLocation = BarLocation;

    // Move the tree window
    //
    MoveWindow(ghTreeWnd,
               0,
               0,
               BarLocation,
               MainClientRect.bottom - StatusWindowRect.bottom + StatusWindowRect.top,
               TRUE);

    // Get the size of the window (in case move window failed
    //
    GetWindowRect(ghTreeWnd, &TreeWindowRect);
    GetWindowRect(ghMainWnd, &MainWindowRect);

    right = TreeWindowRect.right - MainWindowRect.left;

    // Move the edit window with respect to the tree window
    //
    MoveWindow(ghEditWnd,
               right+SIZEBAR,
               0,
               MainClientRect.right-(right+SIZEBAR),
               MainClientRect.bottom - StatusWindowRect.bottom + StatusWindowRect.top,
               TRUE);

    // Move the Status window with respect to the tree window
    //
    MoveWindow(ghStatusWnd,
               0,
               MainClientRect.bottom - StatusWindowRect.bottom + StatusWindowRect.top,
               MainClientRect.right,
               StatusWindowRect.bottom - StatusWindowRect.top,
               TRUE);

}


//*****************************************************************************
//
// MainWndProc()
//
//*****************************************************************************

LRESULT CALLBACK
MainDlgProc (
    HWND   hWnd,
    UINT   uMsg,
    WPARAM wParam,
    LPARAM lParam
)
{


    switch (uMsg)
    {
        

        HANDLE_MSG(hWnd, WM_INITDIALOG,     USBView_OnInitDialog);
        HANDLE_MSG(hWnd, WM_CLOSE,          USBView_OnClose);
        HANDLE_MSG(hWnd, WM_COMMAND,        USBView_OnCommand);
        HANDLE_MSG(hWnd, WM_LBUTTONDOWN,    USBView_OnLButtonDown);
        HANDLE_MSG(hWnd, WM_LBUTTONUP,      USBView_OnLButtonUp);
        HANDLE_MSG(hWnd, WM_MOUSEMOVE,      USBView_OnMouseMove);
        HANDLE_MSG(hWnd, WM_SIZE,           USBView_OnSize);
        HANDLE_MSG(hWnd, WM_NOTIFY,         USBVi
...
...
(Not finished, please download and read the complete file)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
<USBView>0.00 B05-09-05 13:02
USBView.opt57.50 kB04-09-05 02:36
USBView.dsw537.00 B04-09-05 01:23
USBView.ncb105.00 kB04-09-05 02:36
bang.ico1.80 kB30-12-99 06:09
debug.c4.03 kB27-07-00 01:33
dispaud.c32.57 kB27-07-00 01:34
display.c31.80 kB27-07-00 01:34
enum.c50.45 kB27-07-00 01:34
hub.ico766.00 B30-12-99 06:09
monitor.ico9.90 kB30-12-99 06:09
port.ico766.00 B30-12-99 06:09
resource.h978.00 B27-07-00 01:34
sources526.00 B27-07-00 01:34
split.cur326.00 B30-12-99 06:09
usb.ico766.00 B30-12-99 06:09
usbdesc.h9.04 kB27-07-00 01:34
usbview.htm7.03 kB30-12-99 06:09
vndrlist.h20.91 kB27-07-00 01:34
USBView.plg899.00 B04-09-05 02:02
usbview.rc3.24 kB04-09-05 01:29
devioctl.h3.90 kB07-07-00 18:04
usbioctl.h18.68 kB07-07-00 18:04
usb100.h7.45 kB07-07-00 18:04
usbview.h5.56 kB04-09-05 01:52
winuser.h238.47 kB07-07-00 18:04
usbview.c24.52 kB04-09-05 01:56
devnode.c3.97 kB04-09-05 01:56
cfg.h4.57 kB07-07-00 18:04
cfgmgr32.lib51.67 kB07-07-00 18:04
cfgmgr32.h82.86 kB04-09-05 02:00
COMCTL32.LIB71.04 kB13-05-98 18:04
USBView.dsp4.50 kB04-09-05 02:02
<Debug>0.00 B05-09-05 13:02
...
Sponsored links

usbview.c (142.58 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D