2008年7月21日 星期一

ListCtrl in MFC

//======毛毛介紹 listctrl =====================
http://blog.csdn.net/handsomerun/archive/2006/04/13/662462.aspx

2008年7月9日 星期三

CFileDialog in MFC

Search File Sample

/************ using WIN32 API **************/
HANDLE hSearch;
CString path_name;
bool bFinished = false;
WIN32_FIND_DATA find_data;

m_curpath = path_name.Left(path_name.GetLength()-strlen("kghost.exe"));
path_name = m_curpath + "*.txt";
hSearch = FindFirstFile(path_name, &find_data);
if( hSearch==INVALID_HANDLE_VALUE )
return;

while( bFinished==false )
{
CString str = find_data.cFileName;
...
if( !FindNextFile(hSearch, &find_data) )
bFinished = true;
}
FindClose(hSearch);
/****************************************/
其中
WIN32_FIND_DATA
typedef struct _WIN32_FIND_DATA {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;
TCHAR cFileName[ MAX_PATH ];
TCHAR cAlternateFileName[ 14 ];
} WIN32_FIND_DATA, *PWIN32_FIND_DATA;

2008年7月8日 星期二

Performance Tuning of Code

http://www.newlc.com/performance-tuning-code

Double Buffer in MFC and .NET

http://zjyzjy.blog.51cto.com/329429/67390

2008年7月1日 星期二

Using Mutex Objects

Mutex is a kernel object.

//**************************************
* Sample of how to create Mutex
**************************************//
HANDLE hMutex;

// Create a mutex with no initial owner.

hMutex = CreateMutex(
NULL, // no security attributes
FALSE, // initially not owned
"MutexToProtectDatabase"); // name of mutex

if (hMutex == NULL)
{
// Check for error.
}

//**************************************
* Use WaitForSingleObject to use Mutex
**************************************//

BOOL FunctionToWriteToDatabase(HANDLE hMutex)
{
DWORD dwWaitResult;

// Request ownership of mutex.

dwWaitResult = WaitForSingleObject(
hMutex, // handle to mutex
5000L); // five-second time-out interval

switch (dwWaitResult)
{
// The thread got mutex ownership.
case WAIT_OBJECT_0:
__try {
// Write to the database.
}

__finally {
// Release ownership of the mutex object.
if (! ReleaseMutex(hMutex)) {
// Deal with error.
}

break;
}

// Cannot get mutex ownership due to time-out.
case WAIT_TIMEOUT:
return FALSE;

// Got ownership of the abandoned mutex object.
case WAIT_ABANDONED:
return FALSE;
}

return TRUE;
}