[WINAPI]取得磁碟空間

可使用GetDiskFreeSpaceEx()來取得目前可使用的磁碟空間、總磁碟空間以及總剩餘磁碟空間。

使用方式如下:


    char szDiskDir[MAX_PATH]  = "C:\\";

    //A pointer to a variable that receives the total number of free bytes on a disk that are available to the user who is associated with the calling thread.
    //This parameter can be NULL.
    //If per-user quotas are being used, this value may be less than the total number of free bytes on a disk.
    __int64 n64AvailableFreeDiskBytes;       

    //A pointer to a variable that receives the total number of bytes on a disk that are available to the user who is associated with the calling thread.
    //This parameter can be NULL.
    //If per-user quotas are being used, this value may be less than the total number of bytes on a disk.
    //To determine the total number of bytes on a disk or volume, use IOCTL_DISK_GET_LENGTH_INFO.        
    __int64 n64TotalDiskBytes;

    //A pointer to a variable that receives the total number of free bytes on a disk.
    //This parameter can be NULL.
    __int64 n64TotalFreeDiskBytes;

    if ( !::GetDiskFreeSpaceEx(szDiskDir, (PULARGE_INTEGER) &n64AvailableFreeDiskBytes, (PULARGE_INTEGER) &n64TotalDiskBytes,
                                                            (PULARGE_INTEGER) &n64TotalFreeDiskBytes) )
    {
        printf("Fail to get disk fress space in %s (Err = %d).\n", szDiskDir, ::GetLastError());
    }else{
        printf("%s has %lld bytes available free disk.\nTotal disk size is %lld bytes.\nTotal free space is %lld bytes.\n", 
                    szDiskDir, n64AvailableFreeDiskBytes, n64TotalDiskBytes, n64TotalFreeDiskBytes);
    }

[CListCtrl]排序Contorl List內之資料

這邊以檔案清單來說明,需要的欄位有:檔案名稱、副檔名、檔案路徑。

首先先建立用來排序用的資料結構

typedef struct {
    char pszFileName[_MAX_FNAME];
    char pszExtName[_MAX_EXT];
    char pszFilePath[MAX_PATH];
} ITEMDATA, *PITEMDATA; 


再來建立給CListCtrl::SortItems()使用的Call back函式,函式內部就放需要用來sort比對的方法
Head File

friend int CALLBACK SortFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);

Cpp File

int CALLBACK SortFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
    int nRetVal = 0;

    PITEMDATA pData1 = (PITEMDATA)lParam1;
    PITEMDATA pData2 = (PITEMDATA)lParam2;

    switch(lParamSort)
    {
    case 0:    // File Name
        nRetVal = strcmp(pData1->pszFileName, pData2->pszFileName);
        break;

    case 1:    // Extension File Name
        nRetVal = strcmp(pData1->pszExtName, pData2->pszExtName);
        break;

    case 2: // TerFile Path
        nRetVal = strcmp(pData1->pszFilePath, pData2->pszFilePath);
        break;

    default:
        break;
    }

    return nRetVal;
}


再來是建立接收到滑鼠事件後需要執行的函式,在函式內就把先前建立好的Call back函式,SortFunc塞給CListCtrl::SortItems()。
Head File

afx_msg void OnItemClick2Sort(NMHDR* pNMHDR, LRESULT* pResult);

Cpp File

void CFileSearchDlg::OnItemClick2Sort(NMHDR* pNMHDR, LRESULT* pResult)
{
    NMLISTVIEW *pLV = (NMLISTVIEW *) pNMHDR;
    
    m_lstFileItem.SortItems(SortFunc, pLV->iSubItem);

    *pResult = 0;
}



然後在message map鍵入

ON_NOTIFY(LVN_COLUMNCLICK, IDC_LST_FILE, OnItemClick2Sort)

來接收滑鼠點選List的欄位標題時的訊息。

以上動作完成後,就可以利用點擊欄位標題來進行排序了。

[WINDOWS]延遲載入的特定服務的方式

根據MS技術支援的文件內顯示:
1.先至服務的登陸子機碼,HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ < 服務名稱 >
2.在此子機碼內新增 DependOnService 值(可擴充字串值)
3. 鍵入與此服務之前啟動的服務名稱
4.之後在電腦啟動時,它會使用這個項目,來確認啟動服務或服務列在這個值,再嘗試啟動相依的服務。

測試平台:Win7 x64
測試結果:有效

Ref:延遲載入的特定服務的方式

Build docker image from multiple build contexts

Build docker image from multiple build contexts ...