wndmain.c

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

C
1,763
字号
            _wndMain_ExploreSelected();
            break;
            }

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

        }  // switch(LOWORD(wParam))

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


// =========================================================================
BOOL CALLBACK wndMain_HandleMsg_WM_CONTEXTMENU(
                             HWND hWnd,
                             UINT msg,
                             WPARAM wParam,
                             LPARAM lParam
                             )
{
    BOOL retval;
    int x;
    int y;
    BOOL handled;
    HMENU popupMenu;

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

    x = GET_X_LPARAM(lParam);
    y = GET_Y_LPARAM(lParam);
    DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Context menu position: %d, %d\n"), x, y));

    handled = FALSE;
    if ((HWND)wParam != NULL)
        {
        if ((HWND)wParam == G_hWndListView)
            {
            DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Displaying context menu...\n")));
            popupMenu = GetSubMenu(G_hMenuContext, 0);
            TrackPopupMenu(
                           popupMenu,
                           (TPM_LEFTALIGN | TPM_TOPALIGN), 
                           x, 
                           y, 
                           0,
                           hWnd, 
                           NULL 
                         );

            handled = TRUE;
            retval = TRUE;
            }

        }

    if (!(handled))
        {
        retval = DefWindowProc(hWnd, msg, wParam, lParam);
        }

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

// =========================================================================
// [SORTRELATED]
// To sort the listview, call:
//SendMessage(
//            G_hWndListView,
//            LVM_SORTITEMS,
//            //LVM_SORTITEMSEX,  // NOT SUPPORTED under WinCE!
//            999,
//            (LPARAM)CompareFunc
//           );
// Which will call this function back with the lParam set on of each listitem
//
int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
    int retval;
    BOOL allOK;
    LV_ITEM listItem;
    WCHAR Text1[1024]; // [SORTRELATED] - replace with dynamicly allocated buffer
    WCHAR Text2[1024]; // [SORTRELATED] - replace with dynamicly allocated buffer

    allOK = TRUE;
    retval = 0; // Fallback if there's a problem

    // Get rid of PC-Lint warning
    memset(Text1, 0, sizeof(Text1));
    memset(Text2, 0, sizeof(Text2));

    if (allOK)
        {
        listItem.mask = LVIF_TEXT;
        listItem.iItem = lParam1;
        listItem.iSubItem = COL_IDX_MOUNTPOINT;
        listItem.pszText = Text1;
        listItem.cchTextMax = (sizeof(Text1) / sizeof(Text1[0]));
        allOK = ListView_GetItem(G_hWndListView, &listItem);
        }

    if (allOK)
        {
        listItem.mask = LVIF_TEXT;
        listItem.iItem = lParam2;
        listItem.iSubItem = COL_IDX_MOUNTPOINT;
        listItem.pszText = Text2;
        listItem.cchTextMax = (sizeof(Text2) / sizeof(Text2[0]));
        allOK = ListView_GetItem(G_hWndListView, &listItem);
        }

    if (allOK)
        {
        //retval = (wcscmp(Text1, Text2) * -1);
        retval = (wcscmp(Text1, Text2));
        }

    return retval;
}


// =========================================================================
LRESULT wndMain_HandleMsg_WM_DRAWITEM(
    HWND hWnd,
    UINT msg,
    WPARAM wParam,
    LPARAM lParam
)
{
    BOOL allOK;
    DRAWITEMSTRUCT* drawItem;
    int idx;
    int height;
    HIMAGELIST hil;
    int itemHilIdx;
    HBRUSH hBrush;
    LVITEM listItem;
    BOOL itemIsSelected;
    int iconDrawStyle;
    int iconX;
    int iconY;
    WCHAR* itemTextBuf;
    int itemTextBufSize;
    HFONT hFont;
    HFONT prevFont;
    LOGFONT lFont;
    RECT iconRect;
    int nudgeImageY;
    SIZE textSize;
    RECT textRect;
    int nudgeTextY;
    COLORREF prevTextColorFG;
    COLORREF prevTextColorBK;
    int maxText;
    int textLengthMountpoint;
    int textLengthFilename;

    allOK = FALSE;

    if (wParam == IDC_MAIN_LISTVIEW)
        {
        drawItem = (DRAWITEMSTRUCT*)lParam;
        idx = drawItem->itemID;
        if (idx < 0)
            {
            // Don't do anything - just exit
            allOK = TRUE;
            }
        else
            {
            listItem.mask = LVIF_IMAGE;
            listItem.iItem = idx;
            listItem.iSubItem = COL_IDX_MOUNTPOINT;

            allOK = ListView_GetItem(drawItem->hwndItem, &listItem);
            itemHilIdx = listItem.iImage;

            itemIsSelected = (drawItem->itemState & ODS_SELECTED);


            // Draw list item background...
            if (itemIsSelected)
                {
                // Item selected; draw highlighted background
                hBrush = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
                FillRect(drawItem->hDC, &(drawItem->rcItem), hBrush);
                DeleteObject(hBrush);
                }
            else // item not selected; draw black text on white background
                {
                // Item not selected; draw background colour
                // Is this actually needed??
                hBrush = GetStockObject(ListView_GetBkColor(drawItem->hwndItem));
                FillRect(drawItem->hDC, &(drawItem->rcItem), hBrush);
                // Note: Don't delete brush - it's a system object
                }

            // Display icon... 
            iconX = ICON_FALLBACK_SIZE_X;
            iconY = ICON_FALLBACK_SIZE_Y;
            hil = ListView_GetImageList(drawItem->hwndItem, LVSIL_NORMAL);
            if (hil != NULL)
                {
                if (!(ImageList_GetIconSize(
                                            hil,
                                            &iconX,
                                            &iconY
                                            )))
                    {
                    // Ensure iconX, iconY not overwritten...
                    iconX = ICON_FALLBACK_SIZE_X;
                    iconY = ICON_FALLBACK_SIZE_Y;
                    }

                iconRect = drawItem->rcItem;
                // Center icon within listview item display
                nudgeImageY = (((drawItem->rcItem.bottom - drawItem->rcItem.top) - iconX) / 2);
                // if ((nudgeImageY * 2) != ((drawItem->rcItem.bottom - drawItem->rcItem.top) - iconX))
                //     {
                //     nudgeImageY++;
                //     }
                iconRect.left += INDENT_ICON;
                iconRect.top += nudgeImageY;

                // Item spacing not used?
                //itemSpacing = ListView_GetItemSpacing(hWnd, TRUE);
                //DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("itemSpacing: %d\n"), itemSpacing));
                //itemSpacing = ListView_GetItemSpacing(hWnd, FALSE);
                //DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("itemSpacing: %d\n"), itemSpacing));
                //itemSpacing = ListView_GetItemSpacing(drawItem->hwndItem, TRUE);
                //DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("itemSpacing: %d\n"), itemSpacing));
                //itemSpacing = ListView_GetItemSpacing(drawItem->hwndItem, FALSE);
                //DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("itemSpacing: %d\n"), itemSpacing));

                iconDrawStyle = (
                                 ILD_NORMAL |                      
                                 ILD_TRANSPARENT
                                );
                if (itemIsSelected)
                    {
                    iconDrawStyle |= ILD_SELECTED; // ILD_FOCUS
                    }

                ImageList_Draw(
                               hil, 
                               itemHilIdx,
                               drawItem->hDC,
                               iconRect.left,
                               iconRect.top,
                               iconDrawStyle
                              );
                }

            // Get ready to draw on the text...
            if (itemIsSelected)
                {
                prevTextColorFG = SetTextColor(
                                               drawItem->hDC, 
                                               GetSysColor(COLOR_HIGHLIGHTTEXT)
                                              );
                prevTextColorBK = SetBkColor(
                                             drawItem->hDC, 
                                             GetSysColor(COLOR_HIGHLIGHT)
                                            );
                }

            // Display mountpoint...
            prevFont = NULL;
            // Set mountpoint text to bold
            hFont = (HFONT)SendMessage(
                                       drawItem->hwndItem,
                                       WM_GETFONT,
                                       0,
                                       0
                                      );
            if (hFont != NULL)
                {
                if (GetObject(hFont, sizeof(lFont), &lFont) != 0)
                    {
                    lFont.lfWeight = FW_BOLD;
                    hFont = CreateFontIndirect(&lFont);
                    prevFont = SelectObject(drawItem->hDC, hFont);
                    }
                }

            // Get the length of the largest string
            textLengthMountpoint = SDUListView_GetItemTextLength(
                                                        drawItem->hwndItem,
                                                        idx,
                                                        COL_IDX_MOUNTPOINT
                                                       );
            textLengthFilename = SDUListView_GetItemTextLength(
                                                        drawItem->hwndItem,
                                                        idx,
                                                        COL_IDX_FILENAME
                                                       );
            maxText = max(textLengthMountpoint, textLengthFilename);
            // Increment to store NULL terminator
            maxText++;

            // +1 for terminating NULL
            itemTextBufSize = (maxText + 1) * sizeof(*itemTextBuf);
            itemTextBuf = malloc(itemTextBufSize);
            if (itemTextBuf == NULL)
                {
                DEBUGOUTGUI(DEBUGLEV_ERROR, (TEXT("Unable to malloc memory for max listitem item text\n")));
                }
            else
                {
                ListView_GetItemText(
                                     drawItem->hwndItem,
                                     idx,
                                     COL_IDX_MOUNTPOINT,  // iSubItem,
                                     itemTextBuf,
                                     maxText
                                    );

                // Center the two lines of text vertically within the item's display
                // Determine the height of a line, then sou
                GetTextExtentPoint32(
                                     drawItem->hDC, 
                                     itemTextBuf,
                                     wcslen(itemTextBuf),
                                     &textSize
                                    );

                textRect = drawItem->rcItem;
                textRect.left += INDENT_ICON + iconX + INDENT_TEXT;
                nudgeTextY = (
                              (
                               (drawItem->rcItem.bottom - drawItem->rcItem.top)
                                             - (textSize.cy * 2)
                              ) / 2);
                if (
                    (nudgeTextY * 2) != 
                      (
                       (drawItem->rcItem.bottom - drawItem->rcItem.top) 
                                     - (textSize.cy * 2)
                      )
                   )
                    {
                    nudgeTextY--;
                    }
                textRect.top += nudgeTextY;
                height = SDUDrawTextEllipses(
                                             drawItem->hDC,
                                             itemTextBuf,
                                             wcslen(itemTextBuf),
                                             &textRect,
                                             (
                                              DT_LEFT |
                                              DT_NOPREFIX |
                                              DT_SINGLELINE 
                                             )
                                            );


                // Restore non-bold font
                if (prevFont != NULL)
                    {
                    SelectObject(drawItem->hDC, prevFont);
                    }
                // Dump the bold font
                if (hFont != NULL)
                    {
                    DeleteObject(hFont);
                    }


                // Display filename...
                ListView_GetItemText(
                                     drawItem->hwndItem,
                                     idx,
                                     COL_IDX_FILENAME,  // iSubItem,
                                     itemTextBuf,
                                     maxText // (sizeof(itemText) / sizeof(itemText[0]))
                                    );

                textRect.top += height;
                height = SDUDrawTextEllipses(
                                             drawItem->hDC,
                                             itemTextBuf,
                                             wcslen(itemTextBuf),
                                             &textRect,
                                             (
                                              DT_LEFT |
                                              DT_NOPREFIX |
                                              DT_SINGLELINE 
                                             )
                                            );

                SecZeroAndFreeMemory(itemTextBuf, itemTextBufSize);
                }
             
            // Restore colours if changed...
            if (itemIsSelected)
                {
                SetTextColor(drawItem->hDC, prevTextColorFG);
                SetBkColor(drawItem->hDC, prevTextColorBK);
                }
            
            allOK = TRUE;
            }
        }

    return allOK;
}


// =========================================================================
LRESULT CALLBACK wndMain_Proc(
                             HWND hWnd,
                             UINT msg,
                             WPARAM wParam,
                             LPARAM lParam
                            )
{
    LRESULT retval = 0;
    static SHACTIVATEINFO s_sai = {0};

    switch(msg)
        {
        case WM_CREATE:
            {
            DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("MSG: WM_CREATE\n")));
            s_sai.cbSize = sizeof(SHACTIVATEINFO);
            retval = wndMain_HandleMsg_WM_CREATE(hWnd);
            break;
            }

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

⌨️ 快捷键说明

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