wndmain.c

来自「文件驱动加密,功能强大,可产生加密分区,支持AES,MD2,MD4,MD5MD2」· C语言 代码 · 共 1,763 行 · 第 1/4 页

C
1,763
字号
        case WM_ACTIVATE:
            {
            DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("MSG: WM_ACTIVATE\n")));
            SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, 0);
            break;
            }

        case WM_SETTINGCHANGE:
            {
            DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("MSG: WM_SETTINGCHANGE\n")));
            SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
            break;
            }

        case WM_CLOSE:
            {
            DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("MSG: WM_CLOSE\n")));
            retval = wndMain_HandleMsg_WM_CLOSE(hWnd);
            break;
            }

        case WM_DESTROY:
            {
            DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("MSG: WM_DESTROY\n")));
            retval = wndMain_HandleMsg_WM_DESTROY();
            break;
            }
            
        case WM_NOTIFY:
            {
            DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("MSG: WM_NOTIFY\n")));
            retval = wndMain_HandleMsg_WM_NOTIFY(hWnd, wParam, lParam);
            break;
            } 

        case WM_COMMAND:
            {
            DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("MSG: WM_COMMAND\n")));
            retval = wndMain_HandleMsg_WM_COMMAND(hWnd, msg, wParam, lParam);
            break;
            } 

        case WM_CONTEXTMENU:
            {
            DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("MSG: WM_CONTEXTMENU\n")));
            retval = wndMain_HandleMsg_WM_CONTEXTMENU(hWnd, msg, wParam, lParam);
            break;
            }

        case WM_DRAWITEM:
            {
            DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("MSG: WM_DRAWITEM\n")));
            retval = wndMain_HandleMsg_WM_DRAWITEM(hWnd, msg, wParam, lParam);
            break;
            }

        default:
            {
            retval = DefWindowProc(hWnd, msg, wParam, lParam);
            }

        }  // switch(msg)

    return retval;
}


// =========================================================================
BOOL WndMainRegister()
{
    WNDCLASS wc;

    DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("WndMainRegister\n")));

    InitCommonControls();

    wc.style         = (CS_HREDRAW | CS_VREDRAW) ;
    wc.lpfnWndProc   = (WNDPROC)wndMain_Proc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hIcon         = LoadIcon(G_hInstance, MAKEINTRESOURCE(IDI_ICON_MAIN));
    wc.hInstance     = G_hInstance;
    wc.hCursor       = NULL; // No cursor for WinCE
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName  = NULL; // Must be set to NULL; WinCE doesn't support
                             // "MAKEINTRESOURCE(IDR_MAINMENU)" here
    wc.lpszClassName = APP_TITLE;

    DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("WndMainRegister\n")));
    return (RegisterClass(&wc) != 0);
}


// =========================================================================
HWND WndMainCreate()
{
    HWND retval = NULL;

    DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("WndMainCreate\n")));

    retval = CreateWindow(
                          APP_TITLE,      // Class name
                          APP_TITLE,      // Window title       
                          WS_VISIBLE,     // Style
                          CW_USEDEFAULT,  // X
                          CW_USEDEFAULT,  // Y
                          CW_USEDEFAULT,  // Width
                          CW_USEDEFAULT,  // Height
                          NULL,           // Parent window
                          NULL,           // Menu
                          G_hInstance, 
                          NULL
                         );

    if (retval == NULL)      
        {
        MsgError(NULL, TEXT("Unable to create main window"));
        }
    else
        {
        RECT rc;

        // Resize the main window to the size of the work area.
        SHFullScreen(
                     retval, 
                     (
                      SHFS_SHOWTASKBAR | 
                      SHFS_SHOWSTARTICON | 
                      SHFS_SHOWSIPBUTTON
                     )
                    );
        SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, FALSE);
        MoveWindow(
                   retval, 
                   rc.left, 
                   rc.top, 
                   (rc.right - rc.left),
                   (rc.bottom - rc.top),
                   TRUE
                  );
        }

    DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("WndMainCreate\n")));
    return retval;
}


// =========================================================================
void EnableDisableControls()
{
    int itemCount;    
    int selectedCount;    

    DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("EnableDisableControls\n")));

    itemCount = ListView_GetItemCount(G_hWndListView);
    selectedCount = ListView_GetSelectedCount(G_hWndListView);

    // Context menu items...
    MenuItemEnableMenu(
                   G_hMenuContext, 
                   ID_CONTEXTMENU_EXPLORE, 
                   (selectedCount > 0) 
                  ); 
    MenuItemEnableMenu(
                   G_hMenuContext, 
                   ID_FILE_DISMOUNT, 
                   (selectedCount > 0) 
                  ); 
    MenuItemEnableMenu(
                   G_hMenuContext, 
                   ID_FILE_DISMOUNTALL, 
                   (itemCount > 0) 
                  ); 
    MenuItemEnableMenu(
                   G_hMenuContext, 
                   ID_VIEW_PROPERTIES, 
                   (selectedCount > 0) 
                  ); 

    // Main menu items...
    MenuItemEnableWnd(
                     G_hWndMenuBar,
                     ID_FILE_DISMOUNT,
                     (selectedCount > 0)
                    );
    MenuItemEnableWnd(
                     G_hWndMenuBar,
                     ID_FILE_DISMOUNTALL,
                     (itemCount > 0)
                    );
    MenuItemEnableWnd(
                     G_hWndMenuBar,
                     ID_FILE_DISMOUNT,
                     (selectedCount > 0)
                    );
    MenuItemEnableWnd(
                     G_hWndMenuBar,
                     ID_FILE_DISMOUNTALL,
                     (itemCount > 0)
                    );
    MenuItemEnableWnd(
                     G_hWndMenuBar,
                     ID_VIEW_PROPERTIES,
                     (selectedCount > 0)
                    );

    // Menu toolbar buttons...
    MenuButtonEnable(
                     G_hWndMenuBar,
                     ID_FILE_DISMOUNT,
                     (selectedCount > 0)
                    );
    MenuButtonEnable(
                     G_hWndMenuBar,
                     ID_FILE_DISMOUNTALL,
                     (itemCount > 0)
                    );
    MenuButtonEnable(
                     G_hWndMenuBar,
                     ID_FILE_DISMOUNT,
                     (selectedCount > 0)
                    );
    MenuButtonEnable(
                     G_hWndMenuBar,
                     ID_FILE_DISMOUNTALL,
                     (itemCount > 0)
                    );

    DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("EnableDisableControls\n")));
}


// =========================================================================
void wndMain_RefreshList(HWND hWnd)
{
    int cnt = 0;
    int i;
    REGDETAILS_ACTIVE* mountedDetails = NULL;
    BOOL allOK = TRUE;
    int detailsByteSize;
    int rowNum;
    LVITEM listItem;
    HCURSOR csrHourglass;
    HCURSOR csrPrevious;

    // Debug; disable the listview to speed up...
    if (DISABLE_LIST_VIEW)
        {
        return;
        }

    DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("wndMain_RefreshList\n")));

    detailsByteSize = 0;

    csrHourglass = LoadCursor(NULL, IDC_WAIT);
    csrPrevious = SetCursor(csrHourglass);

    ListView_DeleteAllItems(G_hWndListView);

    allOK = driver_GetMountedCount(&cnt);
    if (allOK)
        {
        detailsByteSize = (cnt * sizeof(*mountedDetails)); 
        mountedDetails = malloc(detailsByteSize);
        if (mountedDetails == NULL)
            {
            DEBUGOUTGUI(DEBUGLEV_ERROR, (TEXT("Unable to malloc memory for all volumes mounted\n")));
            allOK = FALSE;
            }
        else
            {
            allOK = driver_MountedVolumes(detailsByteSize, mountedDetails);
            if (!(allOK))
                {
                SecZeroAndFreeMemory(mountedDetails, detailsByteSize);
                mountedDetails = NULL;
                }
            }
        }

    if (allOK) 
        {
        for(i = 0; i < cnt; i++)
            {
            SHFILEINFO shfi;
            HIMAGELIST hil;
            DIOC_DISK_DEVICE_STATUS volumeDetails;

            allOK = driver_GetVolumeInfo_DeviceName(
                                         mountedDetails[i].Name,
                                         &volumeDetails
                                        );
            if (!(allOK))
                {
                DEBUGOUTGUI(DEBUGLEV_ERROR, (TEXT("Unable to get volume details for: %ls\n"), mountedDetails[i].Mountpoint));
                // Bail out...
                break;
                }
            else
                {
                hil = (HIMAGELIST)SHGetFileInfo(
                                                mountedDetails[i].Mountpoint, 
                                                0,
                                                &shfi, 
                                                sizeof(shfi),
                                                (
                                                 SHGFI_SYSICONINDEX | 
                                                 SHGFI_LARGEICON
                                                )
                                               );
                // !! IMPORTANT  !!
                // LVS_SHAREIMAGELISTS must be specified for the listview - 
                // otherwise when the listview is destroyed, it'll try and 
                // destroy it's imagelist (the *SYSTEM* *IMAGELIST*) on it's
                // way out!
                // Destroying the system imagelist is a *really* silly thing
                // to do as it makes all the system icons disappear!)
                ListView_SetImageList(G_hWndListView, hil, LVSIL_NORMAL); 

                // To display large icons...
                if (G_Options->LargeIcons)
                    {
                    // We set the "small" icons to be the same as the normal
                    // sized icons here. The report view line height is taken
                    // from *this* (LVSIL_SMALL) imagelist
                    ListView_SetImageList(G_hWndListView, hil, LVSIL_SMALL); 
                    }
                else
                    {
                    // To display small icons...                
                    hil = (HIMAGELIST)SHGetFileInfo(
                                                    mountedDetails[i].Mountpoint, 
                                                    0,
                                                    &shfi, 
                                                    sizeof(shfi),
                                                    (
                                                     SHGFI_SYSICONINDEX | 
                                                     SHGFI_SMALLICON
                                                    )
                                                   );
                    // !! IMPORTANT  !!
                    // LVS_SHAREIMAGELISTS must be specified for the listview - 
                    // otherwise when the listview is destroyed, it'll try and 
                    // destroy it's imagelist (the *SYSTEM* *IMAGELIST*) on it's
                    // way out!
                    // Destroying the system imagelist is a *really* silly thing
                    // to do as it makes all the system icons disappear!)
                    ListView_SetImageList(G_hWndListView, hil, LVSIL_SMALL); 
                    }

                // We insert the new item, *then* set it's text.
                // This is because we *must* supply iSubItem set to 0 when
                // inserting - and gives us a little more freedom as to
                // whether we set COL_IDX_MOUNTPOINT to 0 and COL_IDX_FILENAME
                // to 1, or vice versa
                listItem.iItem = 0;  // Stick them onto the start of the list
                listItem.iSubItem = 0;
                listItem.mask = 0;

                listItem.mask |= LVIF_IMAGE;
                listItem.iImage = shfi.iIcon;

                // We *have* to set the text initially, or the next time
                // the list is refreshed, the ListView_InsertItem(...) will
                // cause a data abort for some unknown reason!
                // !! WARNING !!
                // [SORTRELATED]
                // atm, we just set this to an empty string. If
                // LVS_SORTASCENDING/LVS_SORTDESCENDING ever start working,
                // it may well be worth revisiting this, as the act of setting
                // the text may well change the insert position, getting the
                // subitem settext set on the wrong item in the list?
                listItem.mask |= LVIF_TEXT;
                listItem.pszText = TEXT("");
                listItem.cchTextMax = wcslen(listItem.pszText);

                rowNum = ListView_InsertItem(G_hWndListView, &listItem);
                if (rowNum < 0)
                    {
                    DEBUGOUTGUI(DEBUGLEV_ERROR, (TEXT("Unable to insert listview item\n")));
                    allOK = FALSE;
                    }
                else
                    {
                    ListView_SetItemText(
                                         G_hWndListView,
                                         rowNum, 
                                         COL_IDX_MOUNTPOINT, 
                                         mountedDetails[i].Mountpoint
                                        );

                    ListView_SetItemText(
                                         G_hWndListView,
                                         rowNum, 
                                         COL_IDX_FILENAME, 
                                         volumeDetails.Filename
                                        );

                    /*
                    [SORTRELATED]
                    Intended for use with sorting the list, this isn't
                    implemented, as there's no easy way of doing it...
                    Note: rowNum will typically always return 0 as we insert
                          into the start of the list
                    listItem.mask = LVIF_PARAM;
                    listItem.iItem = rowNum;
                    listItem.iSubItem = COL_IDX_MOUNTPOINT;
                    listItem.lParam = 9999;
                    ListView_SetItem(
                                     G_hWndListView,
                                     &listItem
                                    );
                    */
                    }

                }
            }

        EnableDisableControls();
        }

    RegDetailsFreeAllActive(cnt, mountedDetails);
    SecZeroAndFreeMemory(mountedDetails, detailsByteSize);

    SetCursor(csrPrevious);

    if (!(allOK))
        {
        MsgError(hWnd, TEXT("Unable to get details of all mounted volumes"));
        }

    DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("wndMain_RefreshList\n")));
}


// =========================================================================
// =========================================================================

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?