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

📄 gsfinder.cpp

📁 PocketPC上很好用的文件管理器,而且里面的封装性很好,学windows mobile开发的兄弟,值得一看
💻 CPP
📖 第 1 页 / 共 4 页
字号:
BOOL IsFolderShortcut(LPCTSTR lpszPath, LPCTSTR lpszFileName)
{
//	TCHAR szBuf[MAX_PATH] = _T(""); //DEL TODA
	TCHAR szPath[MAX_PATH] = _T("");

//MOD START TODA (wcscmp -> wcsicmp, szExt -> szBuf)
//	wcscpy(szExt, lpszFileName);
//	wcsupr(szExt);
	LPTSTR lpszExt = wcsrchr(lpszFileName, _T('.'));
	if (lpszExt != NULL)
	{
		if (wcsicmp(lpszExt, _T(".LNK"))==0)
		{
			//儕儞僋僼傽僀儖偲擣幆
			TCHAR szBuf[MAX_PATH] = _T("");			//ADD TODA
			memset(szBuf, 0, sizeof(szBuf));
			wsprintf(szBuf, _T("%s\\%s"), lpszPath, lpszFileName);
			if (SHGetShortcutTarget(szBuf, szPath, MAX_PATH))
			{
				LPCTSTR lpszStart = szPath;
				if (szPath[0] == _T('\"'))
				{
					lpszStart++;
					memset(szBuf, 0, sizeof(szBuf));
					LPCTSTR lpszEnd = wcsrchr(lpszStart, _T('\"'));
					if (lpszEnd)
						wcsncpy(szBuf, lpszStart, lpszEnd-lpszStart);
					else
						wcsncpy(szBuf, lpszStart, wcslen(lpszStart)-1);
				}

				DWORD dwAttr = GetFileAttributes(szBuf);
				if ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY && dwAttr != 0xFFFFFFFF)
					return TRUE; //僼僅儖僟偺儕儞僋偲擣幆
			}
		}
	}
//MOD END
	return FALSE;
}

////////////////////////////////////////////////////////////////
int CALLBACK PropSheetCallback(HWND hwndDlg, UINT message, LPARAM lParam)
{
#ifdef __POCKET_PC
	switch(message) 
	{
		case PSCB_INITIALIZED:
		{
			HWND hwndChild = GetWindow(hwndDlg, GW_CHILD);
			while (hwndChild)
			{
				TCHAR szTemp[32];
				GetClassName(hwndChild, szTemp, 32);
				if (wcscmp(szTemp, _T("SysTabControl32"))==0)
					break;
				hwndChild = GetWindow(hwndChild, GW_HWNDNEXT);
			}
			if (hwndChild)
			{
				DWORD dwStyle = GetWindowLong(hwndChild, GWL_STYLE) | TCS_BOTTOM;
				::SetWindowLong(hwndChild, GWL_STYLE, dwStyle);
			}
			break;
		}
		case PSCB_GETVERSION:
			return COMCTL32_VERSION;
			break;
		default:
			break;
	}
#endif
	return 0;
}

//////////////////////////////////////////////////////////////////////////////////////
BOOL DefDlgPaintProc(HWND hDlg, WPARAM wParam, LPARAM lParam)
{
#ifdef __POCKET_PC
	//ADD START TODA
	DWORD bottom = 0;
	if(VGACheck())
		bottom = 50;
	else
		bottom = 24;
	//ADD END
	PAINTSTRUCT ps;
	HDC hDC = BeginPaint(hDlg, &ps);
	POINT pt[2] = {{0, bottom},{GetSystemMetrics(SM_CXSCREEN),bottom}};	//MOD TODA (24 -> bottom)
	Polyline(hDC, pt, sizeof(pt)/sizeof(POINT));
	EndPaint(hDlg, &ps);
#endif
	return TRUE;
}

//////////////////////////////////////////////////////////////////////////////////////
BOOL DefDlgPaintProc2(HWND hDlg, WPARAM wParam, LPARAM lParam)
{
#ifdef __POCKET_PC
	DWORD bottom1 = 0;
	DWORD bottom2 = 0;
	DWORD bottom3 = 0;
	if(VGACheck())
	{
		bottom1 = 50;		//墶僨僶僀僗岦偗偵廋惓 by kawa
		bottom2 = 90;       //
		bottom3 = 190;      //
	}
	else
	{
		bottom1 = 25;       //
		bottom2 = 43;       // 
		bottom3 = 95;       //
	}

	PAINTSTRUCT ps;
	HDC hDC = BeginPaint(hDlg, &ps);
	POINT pt[2] = {{0, bottom1},{GetSystemMetrics(SM_CXSCREEN),bottom1}};
	Polyline(hDC, pt, sizeof(pt)/sizeof(POINT));
	
	HPEN hPen = CreatePen(PS_SOLID, 1, RGB(192, 192, 192));
	HPEN hPenOld = (HPEN)SelectObject(hDC, hPen);
	int nWidth = GetSystemMetrics(SM_CXSCREEN);
	pt[0].y = pt[1].y = bottom2;
	Polyline(hDC, pt, sizeof(pt)/sizeof(POINT));
	pt[0].y = pt[1].y = bottom3;
	Polyline(hDC, pt, sizeof(pt)/sizeof(POINT));
	SelectObject(hDC, hPenOld);
	DeleteObject(hPen);
	EndPaint(hDlg, &ps);
#endif
	return TRUE;
}

//////////////////////////////////////////////////////////////////////////////////////
BOOL DefDlgCtlColorStaticProc(HWND hDlg, WPARAM wParam, LPARAM lParam)
{
#ifdef __POCKET_PC
	HDC hDC = (HDC)wParam;
	if (GetDlgCtrlID((HWND)lParam)==IDC_TITLE	||
		GetDlgCtrlID((HWND)lParam)==IDC_TITLE2	||
		GetDlgCtrlID((HWND)lParam)==IDC_TITLE3)
	{
		SetBkMode(hDC, TRANSPARENT);
		SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHT));
		return (long)GetStockObject(WHITE_BRUSH);
	}
	else
#endif
		return FALSE;
}

//////////////////////////////////////////////////////////////////////////////////////
void SetFormatSize(DWORD dwSize, TCHAR szBuff[64], LPTSTR lpszFmtKB, LPTSTR lpszFmtMB)
{
	double fSize;
	TCHAR szSize[64];
	if (dwSize < 1024000)
		fSize = (double)dwSize/1024;	
	else
		fSize = (double)dwSize/1048576;
	wsprintf(szSize, _T("%f"), fSize);
	SetFormatDouble(szSize, 64);
		
	if (dwSize < 1024000)
		wsprintf(szBuff, lpszFmtKB, szSize);
	else
		wsprintf(szBuff, lpszFmtMB, szSize);
}

//ADD START TODA
//////////////////////////////////////////////////////////////////////////////////////
#define KEY_MYCOMPUTER _T("{000214A0-0000-0000-C000-000000000046}")
LPCTSTR GetRootName()
{
	if (!*g_szRootName) {
		wcscpy(g_szRootName, APP_ROOT_FOLDER_NAME);
#ifndef __POCKET_PC
		HKEY hKey;
		if (RegOpenKeyEx(HKEY_CLASSES_ROOT, KEY_MYCOMPUTER, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
			DWORD dwType, dwSize;
			dwSize = sizeof(g_szRootName);
			RegQueryValueEx(hKey, _T("DisplayName"), 0, &dwType, (LPBYTE)g_szRootName, &dwSize);
			RegCloseKey(hKey);
		}
#endif
	}
	return g_szRootName;
}

//////////////////////////////////////////////////////////////////////////////////////
int AddRootIcon(HIMAGELIST hImageList)
{
	int nRet = -1;
#if 0
	HKEY hKey;
	HINSTANCE hInst = NULL;
	HICON hIcon = NULL;
	if (RegOpenKeyEx(HKEY_CLASSES_ROOT, KEY_MYCOMPUTER, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
		DWORD dwType, dwSize;
		TCHAR szValue[MAX_PATH] = {0};
		dwSize = sizeof(szValue);
		if (RegQueryValueEx(hKey, _T("DefaultIcon"), 0, &dwType, (LPBYTE)szValue, &dwSize) == ERROR_SUCCESS) {
			LPTSTR p = wcsrchr(szValue, _T(','));
			if (p) {
				*p = NULL;
				int nIndex = wcstol(p + 1, 0, 10);
				hInst = LoadLibrary(szValue);
				if (hInst)
					hIcon = (HICON)LoadImage(hInst, (LPCTSTR)abs(nIndex), IMAGE_ICON, 16, 16, 0);
			}
		}
		RegCloseKey(hKey);
	}

	if (!hIcon)
		hIcon = (HICON)LoadImage(g_hInst, (LPCTSTR)IDI_ROOT, IMAGE_ICON, 16, 16, 0);
	nRet = ImageList_AddIcon(hImageList, hIcon);
	DeleteObject(hIcon);

	if (hInst)
		FreeLibrary(hInst);
	return nRet;
#else
	HICON hIcon = (HICON)LoadImage(g_hInst, (LPCTSTR)IDI_ROOT, IMAGE_ICON, 16, 16, 0);
	nRet = ImageList_AddIcon(hImageList, hIcon);
	DeleteObject(hIcon);
	return nRet;
#endif
}

//////////////////////////////////////////////////////////////////////////////////////
HFONT MyCreateFont(int nHeight, BYTE dwCharSet, LPTSTR lpszName)
{
	LOGFONT logfont;
	logfont.lfHeight = nHeight;								//僼僅儞僩崅偝
	logfont.lfWidth = 0;									//暥帤暆
	logfont.lfEscapement = 0;								//僥僉僗僩偺妏搙
	logfont.lfOrientation = 0;								//儀乕僗儔僀儞偲倶幉偲偺妏搙
	logfont.lfWeight = FW_DONTCARE;							//僼僅儞僩偺廳偝乮懢偝乯
	logfont.lfItalic = FALSE;								//僀僞儕僢僋懱
	logfont.lfUnderline = FALSE;							//傾儞僟乕儔僀儞
	logfont.lfStrikeOut = FALSE;							//懪偪徚偟慄
	logfont.lfCharSet = dwCharSet;							//暥帤僙僢僩
	logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;			//弌椡惛搙
	logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;			//僋儕僢僺儞僌惛搙
	logfont.lfQuality = DEFAULT_QUALITY;					//弌椡昳幙
//	logfont.lfQuality = ANTIALIASED_QUALITY;				//弌椡昳幙
	logfont.lfPitchAndFamily= DEFAULT_PITCH|FF_DONTCARE;	//僺僢僠偲僼傽儈儕乕
	wcscpy(logfont.lfFaceName, lpszName);					//彂懱柤

	return (CreateFontIndirect(&logfont));
}

#if _WIN32_WCE < 400
///////////////////////////////////////////////////////////////
//彫暥帤->戝暥帤曄姺
char *_strupr( char *string )
{
	char *ptr;

	for(ptr=string; *ptr!=0x00; ptr++)
	{
		if((*ptr >= 0x81 && *ptr <= 0x9F) ||
		   (*ptr >= 0xE0 && *ptr <= 0xEF) ||
		   (*ptr >= 0xF0 && *ptr <= 0xFC)) {

			if(*(ptr+1) >= 0x40)
			{
				ptr++;
				continue;
			}
		}
		(*ptr) = toupper(*ptr);
	} //End of for

	return string;
}

///////////////////////////////////////////////////////////////
//戝暥帤->彫暥帤曄姺
char *_strlwr( char *string )
{
	char *ptr;

	for(ptr=string; *ptr!=0x00; ptr++)
	{
		if((*ptr >= 0x81 && *ptr <= 0x9F) ||
		   (*ptr >= 0xE0 && *ptr <= 0xEF) ||
		   (*ptr >= 0xF0 && *ptr <= 0xFC)) {

			if(*(ptr+1) >= 0x40)
			{
				ptr++;
				continue;
			}
		}
		(*ptr) = tolower(*ptr);
	} //End of for

	return string;
}
#endif
//ADD END

//ADD START TODA (僼傽僀儖曄峏捠抦 from Y.Nagamidori)
//////////////////////////////////////////////////////////////////////////////////////
BOOL g_bNotifyExit = FALSE;
BOOL g_bEnableNotify = FALSE;
HANDLE g_hNotifyThread = NULL;
HANDLE g_hUpdateNotify = INVALID_HANDLE_VALUE;
HANDLE g_hEventBreak = NULL;
DWORD g_dwNotifyThreadId = 0;
TCHAR g_szNotifyDir[MAX_PATH] = {0};
CRITICAL_SECTION g_csec;
////////////////////////////////////////////////////////////////
#if _WIN32_WCE >= 400
DWORD CALLBACK UpdateNotifyThreadProc(LPVOID pParam)
{
	DWORD dwRet;
	while (!g_bNotifyExit) {
		EnterCriticalSection(&g_csec);
		if (g_bEnableNotify) {
			g_hUpdateNotify = FindFirstChangeNotification(g_szNotifyDir, FALSE, 
											FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME);
		}
		LeaveCriticalSection(&g_csec);
		if (g_hUpdateNotify == INVALID_HANDLE_VALUE) {
			WaitForSingleObject(g_hEventBreak, INFINITE);
			ResetEvent(g_hEventBreak);
			continue;
		}

		if (WaitForSingleObject(g_hEventBreak, 5000) == WAIT_OBJECT_0) {
			ResetEvent(g_hEventBreak);
			FindCloseChangeNotification(g_hUpdateNotify);
			g_hUpdateNotify = INVALID_HANDLE_VALUE;
			continue;
		}

		HANDLE handles[] = {g_hEventBreak, g_hUpdateNotify};
		dwRet = WaitForMultipleObjects(sizeof(handles) / sizeof(HANDLE), handles, FALSE, INFINITE);
		if (dwRet - WAIT_OBJECT_0 == 0)
			ResetEvent(g_hEventBreak);
		else {
			EnterCriticalSection(&g_csec);
			//if (g_bEnableNotify) {
			PostMessage(g_MainWnd.m_hWnd, WM_UPDATENOTIFY, 0, 0);
			//}
			LeaveCriticalSection(&g_csec);
		}
		FindCloseChangeNotification(g_hUpdateNotify);
		g_hUpdateNotify = INVALID_HANDLE_VALUE;
	}

	if (g_hUpdateNotify != INVALID_HANDLE_VALUE) {
		FindCloseChangeNotification(g_hUpdateNotify);
		g_hUpdateNotify = INVALID_HANDLE_VALUE;
	}
	return 0;
}
#endif
////////////////////////////////////////////////////////////////
void InitUpdateNotify()
{
#if _WIN32_WCE >= 400
	InitializeCriticalSection(&g_csec);
	g_hEventBreak = CreateEvent(0, TRUE, FALSE, NULL);
	g_hNotifyThread = CreateThread(NULL, 0, UpdateNotifyThreadProc, NULL, 0, &g_dwNotifyThreadId);
#endif
}
////////////////////////////////////////////////////////////////
void EnableUpdateNotify()
{
#if _WIN32_WCE >= 400
	MSG msg;
	EnterCriticalSection(&g_csec);
	g_bEnableNotify = TRUE;
	while (PeekMessage(&msg, g_MainWnd.m_hWnd, WM_UPDATENOTIFY, WM_UPDATENOTIFY, PM_REMOVE));
	SetEvent(g_hEventBreak);
	LeaveCriticalSection(&g_csec);
#endif
}
////////////////////////////////////////////////////////////////
void DisableUpdateNotify()
{
#if _WIN32_WCE >= 400
	MSG msg;
	EnterCriticalSection(&g_csec);
	g_bEnableNotify = FALSE;
	while (PeekMessage(&msg, g_MainWnd.m_hWnd, WM_UPDATENOTIFY, WM_UPDATENOTIFY, PM_REMOVE));
	SetEvent(g_hEventBreak);
	LeaveCriticalSection(&g_csec);
#endif
}
////////////////////////////////////////////////////////////////
void SetUpdateNotify(LPCTSTR pszDir)
{
#if _WIN32_WCE >= 400
	if (wcsicmp(pszDir, g_szNotifyDir) == 0)
		return;

	EnterCriticalSection(&g_csec);
	wcscpy(g_szNotifyDir, pszDir);
	if (!wcslen(g_szNotifyDir))
		wcscpy(g_szNotifyDir, _T("\\"));
	SetEvent(g_hEventBreak);
	LeaveCriticalSection(&g_csec);
#endif
}
////////////////////////////////////////////////////////////////
void UninitUpdateNotify()
{
#if _WIN32_WCE >= 400
	g_bNotifyExit = TRUE;
	SetEvent(g_hEventBreak);
	WaitForSingleObject(g_hNotifyThread, INFINITE);
	DeleteCriticalSection(&g_csec);
	CloseHandle(g_hEventBreak);
#endif
}
//ADD END

⌨️ 快捷键说明

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