⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 freeotfeguilib.c

📁 文件驱动加密,功能强大,可产生加密分区,支持AES,MD2,MD4,MD5MD2, MD4, MD5, RIPEMD-128, RIPEMD-160, SHA-1, SHA-224, SHA-256,
💻 C
📖 第 1 页 / 共 2 页
字号:
// Description: 
// By Sarah Dean
// Email: sdean12@sdean12.org
// WWW:   http://www.FreeOTFE.org/
//
// -----------------------------------------------------------------------------
//



#include "FreeOTFEGUIlib.h"
#include "main.h"

#include "SDUGeneral.h"
#include "FreeOTFElib.h"

//#include <commctrl.h>
#include <Winbase.h>
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>

#include <aygshell.h>  // Required for SH... functions/definitions/etc
#pragma comment(lib, "aygshell") // Link in aygshell.lib


// =========================================================================
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcecoreos5/html/wce50lrfformatmessage.asp
void SDUDisplayLastError_Number()
{
    DWORD error;

    error = GetLastError();
    MsgErrorDWORD_AsHex(NULL, error);
}

// =========================================================================
void SDUDisplayLastError_Text()
{
    DWORD error;

    error = GetLastError();
    SDUDisplayLastError_TextForCode(error);
}


// =========================================================================
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcecoreos5/html/wce50lrfformatmessage.asp
void SDUDisplayLastError_TextForCode(DWORD error)
{
    LPVOID lpMsgBuf;

    FormatMessage( 
                  (
                   FORMAT_MESSAGE_ALLOCATE_BUFFER | 
                   FORMAT_MESSAGE_FROM_SYSTEM | 
                   FORMAT_MESSAGE_IGNORE_INSERTS
                  ),
                  NULL,
                  error,
                  0, // Default language
                  (LPTSTR)&lpMsgBuf,
                  0,
                  NULL 
                 );
    MessageBox(
               NULL, 
               (LPCTSTR)lpMsgBuf, 
               TEXT("Error"), 
               (MB_ICONERROR | MB_OK)
              );
    LocalFree(lpMsgBuf);
}


// =========================================================================
void MsgOutOfMemory(HWND hWnd)
{
    MessageBox(
               hWnd,
               TEXT("Out of memory; please try again"),
               TEXT("Information"),
               (MB_ICONINFORMATION | MB_OK)
              );
}


// =========================================================================
void MsgInfo(HWND hWnd, LPCTSTR lpText)
{
    MessageBox(
               hWnd,
               lpText,
               TEXT("Information"),
               (MB_ICONINFORMATION | MB_OK)
              );
}


// =========================================================================
void MsgWarn(HWND hWnd, LPCTSTR lpText)
{
    MessageBox(
               hWnd,
               lpText,
               TEXT("Warning"),
               (MB_ICONWARNING | MB_OK)
              );
}


// =========================================================================
void MsgError(HWND hWnd, LPCTSTR lpText)
{
    MessageBox(
               hWnd,
               lpText,
               TEXT("Error"),
               (MB_ICONERROR | MB_OK)
              );
}


// =========================================================================
void MsgInfoDWORD_AsHex(HWND hWnd, DWORD number)
{
    WCHAR msg[50]; // Must be large enough to store a DWORD as a hex string

    wsprintf(msg, TEXT("0x%0.8x"), number);
    MsgInfo(hWnd, msg);
}


// =========================================================================
void MsgWarnDWORD_AsHex(HWND hWnd, DWORD number)
{
    WCHAR msg[50]; // Must be large enough to store a DWORD as a hex string

    wsprintf(msg, TEXT("0x%0.8x"), number);
    MsgWarn(hWnd, msg);
}


// =========================================================================
void MsgErrorDWORD_AsHex(HWND hWnd, DWORD number)
{
    WCHAR msg[50]; // Must be large enough to store a DWORD as a hex string

    wsprintf(msg, TEXT("0x%0.8x"), number);
    MsgError(hWnd, msg);
}


// =========================================================================
void MsgInfoString(HWND hWnd, HINSTANCE hInstance, int stringID)
{
    WCHAR* str;

    str = GetString(hInstance, stringID);
    if (str != NULL)
        {
        MsgInfo(hWnd, str);
        free(str);
        }
}


// =========================================================================
void MsgWarnString(HWND hWnd, HINSTANCE hInstance, int stringID)
{
    WCHAR* str;

    str = GetString(hInstance, stringID);
    if (str != NULL)
        {
        MsgWarn(hWnd, str);
        free(str);
        }
}


// =========================================================================
void MsgErrorString(HWND hWnd, HINSTANCE hInstance, int stringID)
{
    WCHAR* str;

    str = GetString(hInstance, stringID);
    if (str != NULL)
        {
        MsgError(hWnd, str);
        free(str);
        }
}


// =========================================================================
// Set static text, resizing the control as appropriate
void SetStaticText(HWND hWnd, int nIDDlgItem, LPCTSTR lpText)
{
    HFONT hfont;
    HDC hdc;
    SIZE size;
    HWND hWndTmp;

    // Identify the size of the text to be displayed...
    hfont = (HFONT)SendDlgItemMessage(
                                      hWnd,
                                      nIDDlgItem,
                                      WM_GETFONT,
                                      0,
                                      0
                                     );
    hdc = GetDC(hWnd);
    hfont = (HFONT)SelectObject(hdc, hfont);
    GetTextExtentPoint32(hdc, lpText, wcslen(lpText), &size);

    // Clean up...
    hfont = (HFONT)SelectObject(hdc, hfont);
    ReleaseDC(hWnd, hdc);

    // Resize the control...
    hWndTmp = GetDlgItem(hWnd, nIDDlgItem); 
    SetWindowPos(
                 hWndTmp, 
                 HWND_TOP, 
                 0,
                 0, 
                 size.cx+5, 
                 size.cy, 
                 (SWP_NOMOVE | SWP_NOZORDER)
                );

    // Set the text.
    SetDlgItemText(hWnd, nIDDlgItem, lpText);
}


// =========================================================================
void AppendStaticText(HWND hWnd, int ctrlID, LPCTSTR lpText)
{
    AppendStaticText_Simple(hWnd, ctrlID, lpText);
}

// =========================================================================
void AppendStaticText_Simple(HWND hWnd, int ctrlID, LPCTSTR lpText)
{
    AppendText(hWnd, ctrlID, lpText, FALSE);
}

// =========================================================================
void AppendStaticText_ResizeToText(HWND hWnd, int ctrlID, LPCTSTR lpText)
{
    AppendText(hWnd, ctrlID, lpText, TRUE);
}

// =========================================================================
void AppendText(HWND hWnd, int ctrlID, LPCTSTR lpText, BOOL resizeCtrl)
{
    WCHAR* pwWS;
    int pwWSSize;
    int pwLen;

    pwLen = GetWindowTextLength(GetDlgItem(hWnd, ctrlID));
        
    // +1 for terminating NULL
    pwWSSize = (pwLen + wcslen(lpText) + 1) * sizeof(*pwWS);
    pwWS = malloc(pwWSSize);

    if (pwWS == NULL)
        {
        MsgOutOfMemory(hWnd);
        }
    else
        {
        memset(pwWS, 0, pwWSSize);
        GetDlgItemText( 
                       hWnd, 
                       ctrlID,
                       pwWS,
                       pwWSSize
                     ); 

        wcscat(pwWS, lpText);

        // Set the text.
        if (resizeCtrl)
            {
            SetStaticText(hWnd, ctrlID, pwWS);
            }
        else
            {
            SetDlgItemText(hWnd, ctrlID, pwWS);
            }
        }

    SecZeroAndFreeMemory(pwWS, pwWSSize);
}


// =========================================================================
// Setup menu
// Returns: Menu HWND, or NULL on failure
HWND SetupMenu(HWND hWnd, int menuID)
{
    HWND retval = NULL;
    SHMENUBARINFO mbi;

    // Setup menu...
    memset(&mbi, 0, sizeof(mbi));

    mbi.cbSize     = sizeof(mbi);
    mbi.hwndParent = hWnd;

    if (menuID == IDR_MENU_NULL)
        {
        mbi.dwFlags = SHCMBF_EMPTYBAR;
        mbi.nToolBarId = 0;
        }
    else
        {
        // Needed if mbi.nToolBarId is a menu ID
        mbi.dwFlags = SHCMBF_HMENU;
        mbi.nToolBarId = menuID;
        }
                                       
    mbi.hInstRes   = G_hInstance;
    mbi.nBmpId     = 0;
    mbi.cBmpImages = 0; 

    if (!(SHCreateMenuBar(&mbi)))
        {
        MsgError(hWnd, TEXT("SHCreateMenuBar Failed"));
        }
    else
        {
        retval = mbi.hwndMB;        
        }

    return retval;
}


// =========================================================================
// Add button to menu
// Returns: TRUE/FALSE on success/failure
BOOL MenuButtonAdd(
                   HWND hWndMenu, 
                   UINT bitmapResource, 
                   UINT bitmapIdx, 
                   UINT cmdID
                  )
{
    BOOL retval = TRUE;
    TBBUTTON tbbButton;
    TBADDBITMAP tbabBitmap;

    // TB_BUTTONSTRUCTSIZE message, required for backward
    // compatibility(?)
    SendMessage(
                hWndMenu,
                TB_BUTTONSTRUCTSIZE,
                (WPARAM)sizeof(tbbButton),
                0
               );

    tbabBitmap.hInst = G_hInstance;
    tbabBitmap.nID = bitmapResource;
    SendMessage(hWndMenu, TB_ADDBITMAP, 0, (LPARAM)&tbabBitmap);

    ZeroMemory(&tbbButton, sizeof(tbbButton));

    // Add button...
    tbbButton.iBitmap = bitmapIdx; 
    tbbButton.fsState = TBSTATE_ENABLED;
    tbbButton.fsStyle = TBSTYLE_BUTTON;
    tbbButton.idCommand = cmdID;
    SendMessage(hWndMenu, TB_ADDBUTTONS, 1, (LPARAM)&tbbButton);

    return retval;
}


// =========================================================================
// Enable/disable a menu button
// Returns: TRUE/FALSE on success/failure
void MenuButtonEnable(
                   HWND hWndMenu, 
                   UINT cmdID,
                   BOOL enable
                  )
{
    SendMessage(
                hWndMenu, 
                TB_ENABLEBUTTON, 
                cmdID, 
                (LPARAM)enable
               );
}


// =========================================================================
// Enable/disable a menu item
// Returns: TRUE/FALSE on success/failure
void MenuItemEnableWnd(
                   HWND hWndMenu, 
                   UINT cmdID,
                   BOOL enable
                  )

{
    HMENU hMenu;

    hMenu = (HMENU)SendMessage(
                               hWndMenu, 
                               SHCMBM_GETMENU, 
                               (WPARAM)0,
                               (LPARAM)0
                              ); 

    MenuItemEnableMenu(hMenu, cmdID, enable);

    DrawMenuBar(hWndMenu);
}


// =========================================================================
// Enable/disable a menu item
// Returns: TRUE/FALSE on success/failure
void MenuItemEnableMenu(
                   HMENU hMenu, 
                   UINT cmdID,
                   BOOL enable
                  )
{
    UINT uEnable;

    uEnable = MF_BYCOMMAND;
    if (enable)
        {
        uEnable |= MF_ENABLED;
        }
    else
        {
        uEnable |= MF_GRAYED;
        }
    

    EnableMenuItem(hMenu, cmdID,uEnable); 
}


// =========================================================================
// Remove a menu item
// Returns: TRUE/FALSE on success/failure
void MenuItemRemoveWnd(
                   HWND hWndMenu, 
                   UINT cmdID
)
{
    HMENU hMenu;

    hMenu = (HMENU)SendMessage(

⌨️ 快捷键说明

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