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

📄 utils.h

📁 This ZIP archive includes the sources (and executable) for the FileTest utility, written by Ladisla
💻 H
字号:
/*****************************************************************************/
/* Utils.h                                Copyright (c) Ladislav Zezula 2004 */
/*---------------------------------------------------------------------------*/
/* Main header file for the Utils library. Include in your project to have   */
/* access to all utility functions                                           */
/*---------------------------------------------------------------------------*/
/*   Date    Ver   Who  Comment                                              */
/* --------  ----  ---  -------                                              */
/* 29.05.04  1.00  Lad  The first version of Utils.h                         */
/*****************************************************************************/

#ifndef __UTILS_H__
#define __UTILS_H__

// In MSVC 8.0, there are some functions declared as deprecated.
#if _MSC_VER >= 1400
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_NON_CONFORMING_SWPRINTFS
#endif

#include <tchar.h>
#include <assert.h>
#include <stdio.h>
#include <windows.h>
#include <commctrl.h>

//-----------------------------------------------------------------------------
// Use the appropriate library
//
// The library type is encoded in the library name as the following UtilsXYZ.lib:
// 
//  X - D for Debug version, R for Release version
//  Y - A for ANSI version, U for Unicode version
//  Z - S for static C library, D for multithreaded DLL library
//

#ifndef __UTILS_SELF

#ifdef _MSC_VER

  #ifdef _DEBUG                               // DEBUG VERSIONS
    #ifndef _UNICODE                            
      #ifdef _DLL
        #pragma comment(lib, "UtilsDAD.lib")  // Debug Ansi Dynamic version
      #else        
        #pragma comment(lib, "UtilsDAS.lib")  // Debug Ansi Static version
      #endif
    #else
      #ifdef _DLL
        #pragma comment(lib, "UtilsDUD.lib")  // Debug Unicode Dynamic version
      #else        
        #pragma comment(lib, "UtilsDUS.lib")  // Debug Unicode Static version
      #endif
    #endif
  #else                                       // RELEASE VERSIONS
    #ifndef _UNICODE
      #ifdef _DLL
        #pragma comment(lib, "UtilsRAD.lib")  // Release Ansi Dynamic version
      #else        
        #pragma comment(lib, "UtilsRAS.lib")  // Release Ansi Static version
      #endif
    #else
      #ifdef _DLL
        #pragma comment(lib, "UtilsRUD.lib")  // Release Unicode Dynamic version
      #else        
        #pragma comment(lib, "UtilsRUS.lib")  // Release Unicode Static version
      #endif
    #endif
  #endif

#endif
#endif

//-----------------------------------------------------------------------------
// Strings

#define   IDS_ERROR       1             // "Error"
#define   IDS_CONFIRM     2             // "Confirmation"
#define   IDS_QUESTION    3             // "Question"
#define   IDS_INFO        4             // "Information"    
#define   IDS_WARNING     5             // "Warning"
#define   IDS_REQUEST     6             // "Request"
#define   IDS_RETRYCANCEL 7             // Dummy string for "Retry/Cancel" MessageBox
#define   IDS_ENTERINT    8             // "Please, enter an integer"
#define   IDS_ENTERINT2   9             // "Please, enter an integer in the range from %i to %i"

//-----------------------------------------------------------------------------
// Macros

// Use with #pragma FIX_LATER("This needs to be fixed")
#ifndef TODO
#define chSTR2(x) #x
#define chSTR(x)  chSTR2(x)
#define TODO(todo)  message(__FILE__ "(" chSTR(__LINE__) ") : TODO: " #todo)
#endif // TODO

// Macro for getting max. number of characters in a buffer
#ifndef _tsize
#define _tsize(buf)  ((sizeof(buf) / sizeof(TCHAR)) - 1)
#endif  // _tsize

//-----------------------------------------------------------------------------
// Structures

struct TListViewColumns
{
    UINT nIDTitle;                      // The title of the list view (string resource ID)
    int  nWidth;                        // The width of the list view. -1 means that the item's
                                        // width is up to the listview width 
};

//-----------------------------------------------------------------------------
// Global variables

// Must be defined by the application. It is the instance of the
// module where to load resources from
extern HINSTANCE g_hInst;

//-----------------------------------------------------------------------------
// Utility function prototypes

// Adds/removes backslash to/from end of path name
void AddBackslash(TCHAR * szPathName);
void RemoveBackslash(TCHAR * szPathName);

// Adds a new string to the existing one. The existing must have been
// allocated by new, the result must be freed using "DeleteAppendedString", when no longer needed.
// The "szString" may be NULL.
TCHAR * AppendString(TCHAR * szString, TCHAR * szAdd, LPCTSTR szSeparator = _T("\r\n"));
void DeleteAppendedString(TCHAR * szString);

// Browses for a file. The initial dir and/or the file may be
// entered by a string or by a control ID.
int BrowseForFile(HWND hParent, LPTSTR szDir, LPTSTR szFile, UINT nIDTitle, UINT nIDFilters);

// Browses for a folder. The folder is stored into the "nIDEdit"
// control
int BrowseForDirectory(HWND hDlg, UINT nIDEdit, UINT nIDTitle);

// Centers a window by its parent or screen
void CenterWindow(HWND hWnd);

// This function compares a string with a wildcard search string.
// returns TRUE, when the string matches with the wildcard.
BOOL CompareStringWildCard(LPCTSTR szString, LPCTSTR szWildCard);

BOOL CompareWindowsTexts(HWND hDlg, UINT nID1, UINT nID2, UINT nIDMsg);

// Creates a HDROP structure for the file.
// The caller must free it using GlobalFree.
HDROP CreateDropForFile(TCHAR * szFileName);

// Shows the message box dialog with "Don't display again" text
INT_PTR DontDisplayAgainDialog(HWND hParent, UINT nIDTemplate, int * piLastAnswer);

// Converts a GUID to registry string format (i.e. {XXXXXXXX-XXXX-...})
int GuidToString(GUID * pGuid, LPTSTR szBuffer);

// Enables/disables a group of dialog items by their ID.
// The ID list must end with 0.
int ShowDlgItems(HWND hDlg, int nCmdShow, ...);
int EnableDlgItems(HWND hDlg, BOOL bEnable, ...);

// Enables a privilege to the current process
int EnablePrivilege(LPCTSTR szPrivilegeName);

// Gets the rectangle of a dialog's template
BOOL GetDialogRect(HWND hParent, UINT nIDDlgTemplate, RECT & rect);

// Get the title of the page from the dialog template
int GetDialogTitleFromTemplate(HINSTANCE hInstance, LPCTSTR szDlgTemplate, LPTSTR szTitle);

// Retrieves the error text. The caller must free the text using
// delete [] szText;
LPTSTR GetErrorText(int nError);

// Fills the module version
int GetModuleVersion(LPCTSTR szModuleName, LARGE_INTEGER * pVersion);

// Returns a localized string for a few IDS_XXX strings.
const TCHAR * GetString(UINT_PTR nIDString);

// Returns the language of current Windows installation
// (Not the value set by the user in Regional Settings)
USHORT GetSystemLanguage();

// Fills the buffer by the current user's specific directory name
int GetShellFolderPath(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath);
   
// Gets the widths of the window borders (non-client area)
// and stores them to the "pRect" parameter
void GetWindowBorders(HWND hWnd, LPRECT pRect);

// Initializes the dialog controls, like combo boxes and list boxes.
int InitDialogControls(HWND hDlg, LPCTSTR lpszResourceName);

// Returns true if the user runs as administrator (or elevated in Vista)
BOOL IsAdministrator();

// REMOVED:
// This function decodes the WM_COMMAND message. If another message, this function
// returns FALSE. If it is a WM_COMMAND, it decodes the motification code, and control ID
// (Control ID is 0 for a menu and 1 for an accelerator).
//BOOL IsCommandMessage(UINT uMsg, WPARAM wParam, UINT & nNotify, UINT_PTR & nIDCtrl);
#define WMC_NOTIFY(wParam)  HIWORD(wParam)
#define WMC_CTRLID(wParam)  LOWORD(wParam)

// Checks of the directory is accessible at least for listin files
BOOL IsDirectoryAccessible(const TCHAR * szDirectory);

// REMOVED:
// Decodes the WM_NOTIFY message
// BOOL IsNotifyMessage (UINT uMsg,b LPARAM lParam, UINT & nNotify, UINT_PTR & nIDCtrl, HWND * hWnd = NULL);

// Verifies the presence of SAG.sys in memory.
BOOL IsSagInMemoryAndEnabled();

// Shows a message box using resource strings
int MessageBoxRc(HWND hParent, UINT_PTR nIDCaption, UINT_PTR nIDText, ...);

// Sets an icon to the dialog
void SetDialogIcon(HWND hDlg, UINT nIDIcon);

// Searches all available processes by given name.
// If the name is found, the function returns the process ID.
#define INVALID_PROCESS_ID ((DWORD)-1)
DWORD FindProcess(LPCTSTR szExeName);

// Ensures that the path exists.
int ForcePathExist(const TCHAR * szPathName, BOOL bIsDirectory = FALSE);

// Returns the domain name for currently logged on user
int GetDomainName(TCHAR * szText, LPDWORD pdwSize);

// Retrieves the pointer to plain name and extension
LPTSTR GetPlainName(LPCTSTR szFileName);
LPTSTR GetFileExt(LPCTSTR szFileName);

// RadioButton functions
DWORD GetRadioValue(HWND hDlg, UINT nIDFirst);
void  SetRadioValue(HWND hDlg, UINT nIDFirst, UINT nValue);

// CheckBox functions
DWORD GetCheckBoxMask(HWND hDlg, UINT nIDFirst);
void  SetCheckBoxMask(HWND hDlg, UINT nIDFirst, DWORD dwMask, DWORD dwEnabled);

BOOL HandleButtons(HWND hDlg, WPARAM wParam, void * SaveProc = NULL, BOOL bChanged = FALSE);

// URL Buttons functions
BOOL ClickURLButton(HWND hButton);
BOOL DrawURLButton(HWND hDlg, LPDRAWITEMSTRUCT dis, BOOL bCentered = FALSE);
int  InitURLButton(HWND hDlg, UINT nIDCtrl, BOOL bBigFont);
int  InitURLButtons(HWND hDlg);
BOOL IsURLButton(HWND hWnd);
void SetURLCursors(UINT nIDUrlPoint, UINT nIDUrlWait);

// Functions related to ListView columns and items
int    ListView_CreateColumns(HWND hList, TListViewColumns * pColumns);
int    InsertLVItem(HWND hList, int nIcon, LPTSTR szText, LPARAM lParam);
int    ListView_SetSubItem(HWND hList, int nItem, int nSubItem, LPCTSTR szText);
LPARAM ListView_GetItemParam(HWND hList, int nItem);
BOOL   ListView_SetItemParam(HWND hList, int nItem, LPARAM lParam);


// TabControl support
int TabCtrl_Create(HWND hTabCtrl, LPPROPSHEETHEADER ppsh);
int TabCtrl_SelectPageByIndex(HWND hTabCtrl, UINT nPageIndex);
int TabCtrl_SelectPageByID(HWND hTabCtrl, LPCTSTR pszPageID);
int TabCtrl_SendMessageToPages(HWND hTabCtrl, UINT uMsg, WPARAM wParam, LPARAM lParam);
INT_PTR TabCtrl_HandleMessages(HWND hTabControl, UINT uMsg, WPARAM wParam, LPARAM lParam);


// Reads line from text file. The file must be opened in text mode
// Returns -1 if end of file, otherwise number of characters read
int ReadLine(FILE * fp, TCHAR * szBuffer, int nMaxChars);

// Replaces the file name with the another one
int ReplaceFileName(LPTSTR szFullPath, LPCTSTR szPlainName);

// Replaces the file extension with another one.
int ReplaceFileExt(TCHAR * szFileName, TCHAR * szNewExt);

// Like sprintf, but the format string is taken from resources
int rsprintf(TCHAR * szBuffer, UINT nIDFormat, ...);

// Recalculates a screen window position (such as retrieved by GetWindowRect)
// to the client coordinates of the window "hWnd".
void ScreenRectToClientRect(HWND hWnd, LPRECT pRect);
void ClientRectToScreenRect(HWND hWnd, LPRECT pRect);

// Sets a bold font for a dialog control
int SetBoldFont(HWND hDlg, UINT nIDCtrl, int nFontSize);

// Sets a window text from resource
int SetWindowTextRc(HWND hWnd, UINT nIDText, ...);

// Shows a systray baloon or a timed messagebox
int ShowSystrayBaloon(HWND hDlg, UINT nIDIcon, UINT nIDTitle, UINT nIDText, ...);

// Verifies if the user's password is valid.
BOOL VerifyUserPassword(TCHAR * szUserName,
                        TCHAR * szDomain,
                        TCHAR * szPassword);

#endif // __UTILS_H__

⌨️ 快捷键说明

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