📄 uicommon.cpp
字号:
::SetBkColor(hDC, clr);
::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, lpRect, NULL, 0, NULL);
}
void FillSolidRect(HDC hDC, int x, int y, int cx, int cy, COLORREF clr)
{
ASSERT(hDC != NULL);
::SetBkColor(hDC, clr);
RECT rect;
SetRect(&rect, x, y, x + cx, y + cy);
::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
}
// **************************************************************
// Intialize functions
//
// **************************************************************
//
// FUNCTION: FreeNavBird()
// PURPOSE: Free resoures.
// COMMENTS:
// This function free all resources appled for this app, call it
// before terminating the application.
//
void FreeNavGPS(void)
{
FreeUI();
}
// do UI initialization
BOOL InitUI()
{
// get system time to initialize GPS time.
GetLocalTime( GetGPSTime() );
// create font used for UI, buttons, captions, ...
if( FALSE == InitNavFont() )
return FALSE;
// Load cursor for all windows in the app.
g_hNavCursor = LoadCursor(NGetInstanceHandle(),(LPCTSTR)IDC_NAVCURSOR);
if ( NULL == g_hNavCursor )
{
TRACE(_T("Fail to load cursor.\n"));
return FALSE;
}
// creat temp memory dc
g_hTempMemDC = ::CreateCompatibleDC( GetDC(NULL) );
if ( NULL == g_hTempMemDC )
{
TRACE(_T("Fail to create temp mem dc. \n"));
return FALSE;
}
// create a null region
g_hRgnNULL = CreateRectRgn(0,0,0,0);//(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
// create the memdc for UI. all windows are drawed in the memdc,
// when finished, copy it to screen.
// in target version we get the DC from DD surface.
HBITMAP hbmp;
BITMAPINFO *pBmpInfo; //
pBmpInfo = (BITMAPINFO*)malloc(sizeof(BITMAPINFO)+2*sizeof(RGBQUAD));
memset(pBmpInfo, 0, sizeof(BITMAPINFO));
pBmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pBmpInfo->bmiHeader.biWidth = SCREEN_WIDTH;
pBmpInfo->bmiHeader.biHeight = SCREEN_HEIGHT;
pBmpInfo->bmiHeader.biPlanes = 1;
pBmpInfo->bmiHeader.biBitCount = 16;
pBmpInfo->bmiHeader.biCompression = BI_BITFIELDS;
*((DWORD*)(&pBmpInfo->bmiColors[0])) = 0xf800;
*((DWORD*)(&pBmpInfo->bmiColors[1])) = 0x07e0;
*((DWORD*)(&pBmpInfo->bmiColors[2])) = 0x1f;
hbmp = CreateDIBSection (NULL, pBmpInfo, DIB_RGB_COLORS, (void**)NULL, 0, 0) ;
// HDC hdc = ::GetDC(GetDesktopWindow());
// m_bmpDialog = CreateCompatibleBitmap(hdc, SCREEN_WIDTH, SCREEN_HEIGHT);
// ::ReleaseDC(GetDesktopWindow(), hdc);
g_hdcUI = CreateCompatibleDC(NULL);
ASSERT( g_hdcUI );
g_hbmpUIOld = (HBITMAP)SelectObject(g_hdcUI, hbmp);
free(pBmpInfo);
return TRUE;
}
void FreeUI()
{
FreeNavFont();
DeleteObject(g_hNavCursor);
g_hNavCursor = NULL;
DeleteObject(g_hTempMemDC);
// free memdc for UI
DeleteObject( SelectObject(g_hdcUI, g_hbmpUIOld) );
DeleteObject(g_hdcUI);
}
LPCTSTR NGetCurrentDir()
{
// get current working dircectory
static TCHAR szCurrentDir[MAX_PATH+1];
static BOOL bInit = FALSE;
if( !bInit )
{
// GetCurrentDirectory(sizeof(szCurrentDir)/sizeof(TCHAR), szCurrentDir);
_tcscpy(szCurrentDir, _T("."));
bInit = TRUE;
}
return (LPCTSTR)szCurrentDir;
}
BOOL InitNavGPS()
{
//Initialize UI
if ( FALSE == InitUI() )
{
TRACE(_T("Fail to init UI.\n"));
return FALSE;
}
// Init current dir
NGetCurrentDir();
return TRUE;
}
/*
*****************************************************************
******************** File Search ********************************
*****************************************************************
*/
static FILE_NAME *gs_pBuffer = NULL;
static int gs_nNext = 0; // the index of the entry to write to.
static int gs_nCount = 0; // the max num files could be write to.
static int gs_nIndex = 0; // the index of the current entry.
// Searching files in the specified directory.
// pPath -- specify the searching path (could be "..\\dirname\\" or ..\\dirname)
// pstrFilter -- the file name that will be searched, it can include wildcard characters.
// format in "*.DOC | *.txt", use '|' to separate filename in order to search
// different type files.
//
// return value: the buffer that stores the file name list.
FILE_NAME* GetFileList(const LPCTSTR pPath, const LPCTSTR pstrFilter)
{
ASSERT(pPath && pstrFilter);
// don't call this function again before calling ReleaseFileList()
ASSERT(gs_nNext==0 && gs_nCount==0 && gs_pBuffer==NULL);
// ensure the searching path ends with "\"
TCHAR szFullPath[MAX_PATH];
int len = _tcslen(pPath);
_tcscpy(szFullPath, pPath);
if (szFullPath[len-1] != _T('\\'))
{
szFullPath[len] = _T('\\');
szFullPath[len+1] = 0;
}
// parse pstrFilter to extract filename to do searching.
// they are separated by '|'
TCHAR szFullFileName[MAX_PATH] = {0,};
LPCTSTR pTemp = pstrFilter;
LPTSTR pFullFileName = szFullFileName;
while ( *pTemp )
{
if (*pTemp == _T('|'))
{
*pFullFileName = 0;
if( _tcslen(szFullFileName) > 0 ) // extract a filename.
{
SearchFile(szFullPath, szFullFileName);
pFullFileName = szFullFileName;
//*pFullFileName = 0;
}
pTemp++;
continue;
}
if( *pTemp != _T(' ')) // ignore white space.
*pFullFileName++ = *pTemp;
pTemp++;
}
*pFullFileName = 0;
if( _tcslen(szFullFileName) > 0 )
{
SearchFile(szFullPath, szFullFileName);
}
if( GetCount() >0 )
return gs_pBuffer;
else
return NULL;
}
void ReleaseFileList()
{
free(gs_pBuffer);
gs_pBuffer = NULL;
gs_nNext = 0;
gs_nCount = 0;
}
int GetCount()
{
return gs_nNext;
}
static void AddToFileList(const LPCTSTR pFilePath, const LPCTSTR pFileName)
{
if(gs_pBuffer == NULL)
{
gs_nCount = 32;
gs_pBuffer = (FILE_NAME*)malloc( gs_nCount*sizeof(FILE_NAME) );
ASSERT(gs_pBuffer);
}
else if(gs_nNext >= gs_nCount) // the memeroy allocated is not sufficient,
{ // need to reallocate mem.(double it)
gs_nCount = 2*gs_nCount;
gs_pBuffer = (FILE_NAME*)realloc(gs_pBuffer, gs_nCount*sizeof(FILE_NAME));
ASSERT(gs_pBuffer);
}
// copy data to buffer.
_tcscpy(gs_pBuffer[gs_nNext].FilePath, pFilePath);
_tcscpy(gs_pBuffer[gs_nNext].FileName, pFileName);
gs_nNext++;
}
// INPUT path and file name.
// pleas ensure the searching path ends with "\"
static BOOL SearchFile(LPCTSTR buf_path, LPCTSTR file_name)
{
BOOL bSearchFlag = FALSE;
TCHAR buf_temp[MAX_PATH] = {0};
WIN32_FIND_DATA findinfo;
memset(&findinfo, 0, sizeof (WIN32_FIND_DATA));
_tcscpy(buf_temp, buf_path);
_tcscat(buf_temp, file_name);
//
// search matched files in directory specified by parameters buf_path
//
HANDLE hFind = FindFirstFile(buf_temp, &findinfo);
if (hFind != INVALID_HANDLE_VALUE)
{
// add all matched files to list, but not include the files in subdir.
do
{
// it's not a directory
if ( !(findinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
{
AddToFileList(buf_path, findinfo.cFileName);
bSearchFlag = TRUE;
}
}while( FindNextFile(hFind, &findinfo) != 0 );
FindClose(hFind);
}
//
// search mathced files in sub directories
//
_tcscpy(buf_temp, buf_path);
_tcscat(buf_temp, _T("*.*"));
hFind = FindFirstFile(buf_temp, &findinfo);
// no sub directory or errors occur
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if (findinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
// it's not sub directory . or ..
if ( (0 != _tcscmp(findinfo.cFileName, _T(".")))
&& (0 != _tcscmp(findinfo.cFileName, _T(".."))) )
{
TCHAR buf_dir[MAX_PATH] = {0};
_tcscpy(buf_dir, buf_path);
_tcscat(buf_dir, findinfo.cFileName);
_tcscat(buf_dir, _T("\\")); // ensure path ends with "\"
bSearchFlag = SearchFile(buf_dir, file_name);
}
}
}while( FindNextFile(hFind, &findinfo) != 0 );
FindClose(hFind);
}
return bSearchFlag;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -