### Benchmark Profile Definitions (C++) Source: https://context7.com/hiyohiyo/crystaldiskmark/llms.txt Defines various benchmark profiles using an enum and provides example implementations for setting default and NVMe-optimized profile configurations. These profiles dictate test parameters such as type, size, queues, and threads. ```cpp // Benchmark profile definitions in DiskBench.h enum PROFILE { PROFILE_DEFAULT = 0, // Standard desktop/laptop benchmark PROFILE_PEAK, PROFILE_REAL, PROFILE_DEMO, PROFILE_DEFAULT_MIX, PROFILE_PEAK_MIX, PROFILE_REAL_MIX, }; // Default profile settings (Settings Dialog) void CSettingsDlg::OnSetDefault() { // Test configurations: Type (0=Sequential, 1=Random), Size (KB), Queues, Threads int type[9] = { 0, 0, 1, 1, 0, 1, 0, 1, 0 }; int size[9] = { 1024, 1024, 4, 4, 1024, 4, 1024, 4, 1024 }; int queues[9] = { 8, 1, 32, 1, 8, 32, 1, 1, 8 }; int threads[9] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 }; for (int i = 0; i < 9; i++) { m_BenchType[i] = type[i]; m_BenchSize[i] = size[i]; m_BenchQueues[i] = queues[i]; m_BenchThreads[i] = threads[i]; } m_MeasureTime = 5; // 5 second measurement m_IntervalTime = 5; // 5 second interval between tests } // NVMe optimized profile void CSettingsDlg::OnSetNVMe8() { int type[9] = { 0, 0, 1, 1, 0, 1, 0, 1, 0 }; int size[9] = { 1024, 128, 4, 4, 1024, 4, 1024, 4, 1024 }; int queues[9] = { 8, 32, 32, 1, 8, 32, 1, 1, 8 }; int threads[9] = { 1, 1, 16, 1, 1, 16, 1, 1, 1 }; m_MeasureTime = 5; m_IntervalTime = 5; } ``` -------------------------------- ### Configure Test Data Types for Disk Benchmarking (C++) Source: https://context7.com/hiyohiyo/crystaldiskmark/llms.txt Defines an enumeration for test data types (random, all zeros, all ones) used in disk write operations. It also shows example usage for setting the test data type in benchmark mode selection and saving it to an INI file. ```cpp // Test data type definitions enum TEST_DATA_TYPE { TEST_DATA_RANDOM = 0, // Random data (incompressible) TEST_DATA_ALL0X00, // All zeros (highly compressible) TEST_DATA_ALL0XFF, // All ones }; // Usage in benchmark mode selection void CDiskMarkDlg::OnModeDefault() { m_TestData = TEST_DATA_RANDOM; WritePrivateProfileString(L"Setting", L"TestData", L"0", m_Ini); } void CDiskMarkDlg::OnModeAll0x00() { m_TestData = TEST_DATA_ALL0X00; WritePrivateProfileString(L"Setting", L"TestData", L"1", m_Ini); } ``` -------------------------------- ### Initialize Benchmark Environment (C++) Source: https://context7.com/hiyohiyo/crystaldiskmark/llms.txt Initializes the benchmark environment by selecting the appropriate DiskSpd executable, creating the test directory and file, and validating disk capacity. It handles platform-specific executable selection and ensures sufficient disk space before creating and preparing the test file. ```cpp // Initialize benchmark test environment BOOL Init(void* dlg) { TCHAR temp[MAX_PATH]; ::GetModuleFileName(NULL, temp, MAX_PATH); // Select appropriate DiskSpd executable for platform #ifdef _M_ARM64 DiskSpdExe.Format(L"%s\CdmResource\diskspd\diskspdA64.exe", temp); #elif _M_X64 if (IsWin8orLater()) DiskSpdExe.Format(L"%s\CdmResource\diskspd\diskspd64.exe", temp); else DiskSpdExe.Format(L"%s\CdmResource\diskspd\diskspd64L.exe", temp); #else if (IsWin8orLater()) DiskSpdExe.Format(L"%s\CdmResource\diskspd\diskspd32.exe", temp); else DiskSpdExe.Format(L"%s\CdmResource\diskspd\diskspd32L.exe", temp); #endif // Verify DiskSpd exists if (!IsFileExist(DiskSpdExe)) { AfxMessageBox(((CDiskMarkDlg*)dlg)->m_MesDiskSpdNotFound); return FALSE; } // Configure test parameters DiskTestCount = ((CDiskMarkDlg*)dlg)->m_IndexTestCount + 1; DiskTestSize = (UINT64)_tstoi(testSize) * 1024; // Convert to MiB // Create test directory and file CString RootPath; RootPath.Format(L"%c:\", drive); TestFileDir.Format(L"%sCrystalDiskMark%08X", RootPath.GetString(), timeGetTime()); CreateDirectory(TestFileDir, NULL); TestFilePath.Format(L"%s\CrystalDiskMark%08X.tmp", TestFileDir.GetString(), timeGetTime()); // Check disk capacity ULARGE_INTEGER FreeBytesAvailable, TotalBytes, TotalFreeBytes; GetDiskFreeSpaceEx(RootPath, &FreeBytesAvailable, &TotalBytes, &TotalFreeBytes); if (DiskTestSize > TotalFreeBytes.QuadPart / 1024 / 1024) { AfxMessageBox(((CDiskMarkDlg*)dlg)->m_MesDiskCapacityError); return FALSE; } // Create test file with specified size hFile = CreateFile(TestFilePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING, NULL); LARGE_INTEGER nFileSize; nFileSize.QuadPart = 1024 * 1024 * DiskTestSize; SetFilePointerEx(hFile, nFileSize, NULL, FILE_BEGIN); SetEndOfFile(hFile); // Fill test file with random or zero data char* buf = (char*)VirtualAlloc(NULL, 1024*1024, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); for (int i = 0; i < 1024*1024; i++) buf[i] = (char)(rand() % 256); for (int i = 0; i < DiskTestSize; i++) WriteFile(hFile, buf, 1024*1024, &writesize, NULL); VirtualFree(buf, 0, MEM_RELEASE); CloseHandle(hFile); return TRUE; } ``` -------------------------------- ### Execute Benchmark Suite and UI Integration in C++ Source: https://context7.com/hiyohiyo/crystaldiskmark/llms.txt This snippet demonstrates the orchestration of a full benchmark suite using a worker thread and the corresponding UI event handler. It manages the sequential execution of read and write tests based on the selected profile and ensures thread safety during initialization and termination. ```cpp UINT ExecDiskBenchAll(LPVOID dlg) { int benchmark = ((CDiskMarkDlg*)dlg)->m_Benchmark; if(Init(dlg)) { if (benchmark & BENCHMARK_READ) { DiskSpd(dlg, TEST_READ_0); Interval(dlg); DiskSpd(dlg, TEST_READ_1); Interval(dlg); DiskSpd(dlg, TEST_READ_2); Interval(dlg); DiskSpd(dlg, TEST_READ_3); } if ((benchmark & BENCHMARK_READ) && (benchmark & BENCHMARK_WRITE)) { Interval(dlg); } if (benchmark & BENCHMARK_WRITE) { DiskSpd(dlg, TEST_WRITE_0); Interval(dlg); DiskSpd(dlg, TEST_WRITE_1); Interval(dlg); DiskSpd(dlg, TEST_WRITE_2); Interval(dlg); DiskSpd(dlg, TEST_WRITE_3); } } return Exit(dlg); } void CDiskMarkDlg::OnAll() { if (m_WinThread != NULL) { Stop(); return; } m_DiskBenchStatus = TRUE; InitScore(); switch (m_Profile) { case PROFILE_DEFAULT: m_WinThread = AfxBeginThread(ExecDiskBenchAll, (LPVOID)this); break; case PROFILE_PEAK: m_WinThread = AfxBeginThread(ExecDiskBenchAllPeak, (LPVOID)this); break; case PROFILE_REAL: m_WinThread = AfxBeginThread(ExecDiskBenchAllReal, (LPVOID)this); break; case PROFILE_DEMO: m_WinThread = AfxBeginThread(ExecDiskBenchAllDemo, (LPVOID)this); break; } } ``` -------------------------------- ### Priscilla UI Framework: CStaticFx Enhanced Static Control (C++) Source: https://context7.com/hiyohiyo/crystaldiskmark/llms.txt An enhanced static control class that supports custom rendering, meter displays, glass effects, and tooltips. It provides methods for initialization, setting meter progress, configuring glass effects, setting label text, font customization, and tooltip text. ```cpp // Static control with meter and theming support class CStaticFx : public CStatic { public: // Initialize control with position, size, and rendering options BOOL InitControl(int x, int y, int width, int height, double zoomRatio, HPALETTE hPal, CDC* bkDC, LPCTSTR imagePath, int imageCount, DWORD textAlign, int renderMode, BOOL bHighContrast, BOOL bDarkMode, DWORD drawFrame); // Configure meter display (progress bar style) void SetMeter(BOOL bMeter, double meterRatio); void SetGlassColor(COLORREF glassColor, BYTE glassAlpha); // Set label and unit text void SetLabelUnit(CString label, CString unit); // Font configuration void SetFontEx(CString face, int size, int sizeToolTip, double zoomRatio, double fontRatio = 1.0, COLORREF textColor = RGB(0,0,0), LONG fontWeight = FW_NORMAL, BYTE fontRender = CLEARTYPE_NATURAL_QUALITY); // Tooltip support void SetToolTipText(LPCTSTR pText); }; // Example: Initialize benchmark result meter void CDiskMarkDlg::UpdateDialogSize() { // Initialize read score displays as meters m_TestRead0.InitControl(140 + offsetX, 96, 320, 80, m_ZoomRatio, m_hPal, &m_BkDC, IP(L"Meter"), 2, SS_RIGHT, OwnerDrawImage, m_bHighContrast, FALSE, FALSE); m_TestRead0.SetFontEx(m_FontFace, 24, 12, m_ZoomRatio, m_FontRatio, m_MeterText, FW_BOLD, m_FontRender); // Update meter with benchmark score double score = m_ReadScore[0]; double maxScore = 10000.0; // 10 GB/s max for display m_TestRead0.SetMeter(TRUE, score / maxScore); m_TestRead0.SetWindowText(FormatScore(score)); } ``` -------------------------------- ### Benchmark Result Clipboard Export Source: https://context7.com/hiyohiyo/crystaldiskmark/llms.txt Demonstrates the implementation of the OnCopy method to format benchmark results and copy them to the system clipboard. It iterates through test results and appends them to a formatted string. ```cpp void CDiskMarkDlg::OnCopy() { CString result; result.Format(L"CrystalDiskMark %s\n", PRODUCT_VERSION); result += L"* MB/s = 1,000,000 bytes/s [SATA/600 = 600,000,000 bytes/s]\n\n"; for (int i = 0; i < 4; i++) { result += GetResultString(i, m_ReadScore[i], m_ReadLatency[i], m_BenchSize[i], m_BenchQueues[i], m_BenchThreads[i]); } SetClipboardText(result); } ``` -------------------------------- ### Detect Windows OS Version and Architecture Source: https://context7.com/hiyohiyo/crystaldiskmark/llms.txt Provides utility functions to identify the current Windows version and architecture, useful for selecting appropriate binary dependencies like DiskSpd. ```cpp BOOL IsWin8orLater(); BOOL IsWin81orLater(); BOOL IsDarkModeSupport(); BOOL IsX64(); BOOL IsArm64(); void SelectDiskSpdExe() { #ifdef _M_ARM64 DiskSpdExe = L"diskspdA64.exe"; #elif _M_X64 if (IsWin8orLater()) DiskSpdExe = L"diskspd64.exe"; else DiskSpdExe = L"diskspd64L.exe"; #else if (IsWin8orLater()) DiskSpdExe = L"diskspd32.exe"; else DiskSpdExe = L"diskspd32L.exe"; #endif } ``` -------------------------------- ### Execute Individual Benchmark Test with DiskSpd (C++) Source: https://context7.com/hiyohiyo/crystaldiskmark/llms.txt This C++ function executes a single benchmark test using Microsoft DiskSpd. It configures various test parameters such as block size, queue depth, threads, and access pattern (sequential/random) based on the provided command type. The function then runs DiskSpd with the specified options and collects performance metrics like score and latency. ```cpp // Execute a specific benchmark command using DiskSpd void DiskSpd(void* dlg, DISK_SPD_CMD cmd) { CString command; CString option; double *maxScore = NULL; double *minLatency = NULL; int index = 0; int duration = 5; // Configure test based on command type switch (cmd) { case TEST_READ_0: // Sequential Read with Q8T1 index = 0; if (BenchType[index]) // Random { option.Format(L"-b%dK -o%d -t%d -W0 -S -w0 -r", BenchSize[index], BenchQueues[index], BenchThreads[index]); } else // Sequential { option.Format(L"-b%dK -o%d -t%d -W0 -S -w0", BenchSize[index], BenchQueues[index], BenchThreads[index]); } maxScore = &(((CDiskMarkDlg*)dlg)->m_ReadScore[index]); minLatency = &(((CDiskMarkDlg*)dlg)->m_ReadLatency[index]); break; case TEST_WRITE_0: // Sequential Write with Q8T1 index = 0; if (BenchType[index]) { option.Format(L"-b%dK -o%d -t%d -W0 -S -w100 -r", BenchSize[index], BenchQueues[index], BenchThreads[index]); } else { option.Format(L"-b%dK -o%d -t%d -W0 -S -w100", BenchSize[index], BenchQueues[index], BenchThreads[index]); } maxScore = &(((CDiskMarkDlg*)dlg)->m_WriteScore[index]); minLatency = &(((CDiskMarkDlg*)dlg)->m_WriteLatency[index]); break; // ... additional cases for TEST_READ_1-3, TEST_WRITE_1-3, etc. } // Execute DiskSpd and collect results for (int j = 0; j <= DiskTestCount; j++) { command.Format(L"\"%s\" %s -d%d -A%d -L \"%s\"", DiskSpdExe.GetString(), option.GetString(), duration, GetCurrentProcessId(), TestFilePath.GetString()); double latency = 0.0; double score = ExecAndWait((TCHAR*)command.GetString(), TRUE, &latency) / 10 / 1000.0; if (j > 0 && score > *maxScore) { *maxScore = score; ::PostMessage(((CDiskMarkDlg*)dlg)->GetSafeHwnd(), WM_UPDATE_SCORE, 0, 0); } } } ``` -------------------------------- ### Initialize CButtonFx Enhanced Button Source: https://context7.com/hiyohiyo/crystaldiskmark/llms.txt Defines the CButtonFx class for custom-rendered buttons with image states and hover effects, and demonstrates initializing benchmark buttons in a dialog. ```cpp class CButtonFx : public CButton { public: BOOL InitControl(int x, int y, int width, int height, double zoomRatio, HPALETTE hPal, CDC* bkDC, LPCTSTR imagePath, int imageCount, DWORD textAlign, int renderMode, BOOL bHighContrast, BOOL bDarkMode, BOOL bDrawFrame); BOOL ReloadImage(LPCTSTR imagePath, UINT imageCount); void SetHandCursor(BOOL bHandCursor = TRUE); void SetSelected(BOOL bSelected = TRUE); void SetToolTipText(LPCTSTR text); }; void CDiskMarkDlg::UpdateDialogSize() { m_ButtonAll.InitControl(8, 8, 72, 48, m_ZoomRatio, m_hPal, &m_BkDC, IP(L"Button"), 3, BS_CENTER, OwnerDrawImage, m_bHighContrast, FALSE, FALSE); m_ButtonAll.SetHandCursor(TRUE); m_ButtonAll.SetToolTipText(L"Run all benchmarks (Ctrl+A)"); } ``` -------------------------------- ### File and Clipboard Utility Functions Source: https://context7.com/hiyohiyo/crystaldiskmark/llms.txt Provides declarations for file existence checks, clipboard management, and character encoding conversions. These functions are essential for handling data persistence and user interaction within the application. ```cpp BOOL IsFileExist(const TCHAR* fileName); BOOL CanWriteFile(const TCHAR* fileName); int GetFileVersion(const TCHAR* fileName, TCHAR* version = NULL); void SetClipboardText(CString clip); CStringW UTF8toUTF16(const CStringA& utf8str); CStringA UTF16toUTF8(const CStringW& utf16str); CStringA URLEncode(const CStringA& str); ``` -------------------------------- ### Priscilla UI Framework: CDialogFx Base Dialog (C++) Source: https://context7.com/hiyohiyo/crystaldiskmark/llms.txt The base dialog class for the Priscilla UI Framework, offering theme support, DPI awareness, and dark mode. It includes methods for font scaling, dark mode toggling, dialog initialization, size updates, and internationalization. ```cpp // Dialog initialization with theme and zoom support class CDialogFx : public CDialog { public: CDialogFx(UINT dlgResource, CWnd* pParent = NULL); // Font configuration int GetFontScale(); BYTE GetFontRender(); double GetFontRatio(); CString GetFontFace(); // Dark mode support BOOL IsDisableDarkMode(); protected: // Dialog setup virtual BOOL OnInitDialog(); virtual void UpdateDialogSize(); virtual void SetClientSize(int sizeX, int sizeY, double zoomRatio); virtual void UpdateBackground(BOOL resize, BOOL darkMode); // Zoom handling DWORD ChangeZoomType(DWORD zoomType); // Internationalization CString i18n(CString section, CString key, BOOL inEnglish = FALSE); // Utility virtual CString IP(CString imageName); // Get image path void OpenUrl(CString url); int GetDpi(); protected: BOOL m_bInitializing; BOOL m_bDarkMode; int m_Dpi; DWORD m_ZoomType; double m_ZoomRatio; CString m_ThemeDir; CString m_CurrentTheme; CString m_CurrentLang; }; // Example usage in main dialog BOOL CDiskMarkDlg::OnInitDialog() { CMainDialogFx::OnInitDialog(); // Configure zoom based on saved settings switch(GetPrivateProfileInt(L"Setting", L"ZoomType", 0, m_Ini)) { case 100: CheckRadioZoomType(ID_ZOOM_100, 100); break; case 125: CheckRadioZoomType(ID_ZOOM_125, 125); break; case 150: CheckRadioZoomType(ID_ZOOM_150, 150); break; case 200: CheckRadioZoomType(ID_ZOOM_200, 200); break; default: CheckRadioZoomType(ID_ZOOM_AUTO, 0); break; } ChangeZoomType(m_ZoomType); SetClientSize(m_SizeX, m_SizeY, m_ZoomRatio); return TRUE; } ``` -------------------------------- ### File and Utility Functions Source: https://context7.com/hiyohiyo/crystaldiskmark/llms.txt Provides utility functions for file operations, clipboard access, and string manipulation, including encoding conversions and INI file operations with Unicode support. ```APIDOC ## File and Utility Functions ### Description Utility functions for file operations, clipboard access, and string manipulation. ### File Utilities (UtilityFx.h) - `BOOL IsFileExist(const TCHAR* fileName)`: Checks if a file exists. - `BOOL CanWriteFile(const TCHAR* fileName)`: Checks if a file can be written to. - `int GetFileVersion(const TCHAR* fileName, TCHAR* version = NULL)`: Retrieves the version of a file. ### Clipboard Operations - `void SetClipboardText(CString clip)`: Sets the text content of the clipboard. ### Character Encoding Conversion - `CStringW UTF8toUTF16(const CStringA& utf8str)`: Converts a UTF-8 encoded string to UTF-16. - `CStringA UTF16toUTF8(const CStringW& utf16str)`: Converts a UTF-16 encoded string to UTF-8. - `CStringA URLEncode(const CStringA& str)`: URL-encodes a string. ### INI File Operations (Unicode Support) - `DWORD GetPrivateProfileStringFx(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPTSTR lpReturnedString, DWORD nSize, LPCTSTR lpFileName)`: Retrieves a string from an INI file with Unicode support. - `UINT GetPrivateProfileIntFx(LPCTSTR lpAppName, LPCTSTR lpKeyName, INT nDefault, LPCTSTR lpFileName)`: Retrieves an integer from an INI file with Unicode support. - `BOOL WritePrivateProfileStringFx(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpString, LPCTSTR lpFileName)`: Writes a string to an INI file with Unicode support. ### Example: Save benchmark results to clipboard This example demonstrates how to format benchmark results and save them to the system clipboard using `SetClipboardText`. ``` -------------------------------- ### Initialize CComboBoxFx Enhanced ComboBox Source: https://context7.com/hiyohiyo/crystaldiskmark/llms.txt Defines the CComboBoxFx class for owner-drawn combo boxes with glass effects, and demonstrates initializing a drive selection dropdown. ```cpp class CComboBoxFx : public CComboBox { public: BOOL InitControl(int x, int y, int width, int height, double zoomRatio, CDC* bkDC, LPCWSTR imagePath, int imageCount, DWORD textAlign, int renderMode, BOOL bHighContrast, BOOL bDarkMode, COLORREF bkColor, COLORREF bkColorSelected, COLORREF glassColor, BYTE glassAlpha); void SetFontEx(CString face, int size, int sizeToolTip, double zoomRatio, double fontRatio = 1.0, COLORREF textColor = RGB(0,0,0), COLORREF textColorSelected = RGB(0,0,0), LONG fontWeight = FW_NORMAL, BYTE fontRender = CLEARTYPE_NATURAL_QUALITY); void SetAlpha(BYTE alpha); void SetGlassColor(COLORREF glassColor, BYTE glassAlpha); }; void CDiskMarkDlg::OnInitDialog() { m_ComboDrive.InitControl(212, 8, 188, 300, m_ZoomRatio, &m_BkDC, NULL, 0, ES_LEFT, OwnerDrawGlass, m_bHighContrast, FALSE, m_ComboBk, m_ComboBkSelected, m_Glass, m_GlassAlpha); } ``` -------------------------------- ### INI Configuration File Operations Source: https://context7.com/hiyohiyo/crystaldiskmark/llms.txt Wrappers for Windows API functions to handle INI file reading and writing with Unicode support. These functions facilitate the portable configuration system used by CrystalDiskMark. ```cpp DWORD GetPrivateProfileStringFx(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPTSTR lpReturnedString, DWORD nSize, LPCTSTR lpFileName); UINT GetPrivateProfileIntFx(LPCTSTR lpAppName, LPCTSTR lpKeyName, INT nDefault, LPCTSTR lpFileName); BOOL WritePrivateProfileStringFx(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpString, LPCTSTR lpFileName); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.