123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746 |
- #include "StdAfx.h"
- #include <stdlib.h>
- #include <string>
- #include <wchar.h>
- #include <shlwapi.h>
- #include "common_funcs.h"
- //#include "debug.h"
- #include <mmsystem.h>
- #pragma comment(lib, "winmm.lib")
- #pragma warning(push)
- #pragma warning(disable:4996)
- Common_Funcs::Common_Funcs(void)
- {
- }
- Common_Funcs::~Common_Funcs(void)
- {
- }
- void GetModulePath(string &path)
- {
- TCHAR szPathBuffer[MAX_PATH] = {0};
- ::GetModuleFileName(NULL, szPathBuffer, MAX_PATH);
- string prc = szPathBuffer;
- std::size_t found = prc.find_last_of("/");
- path = prc.substr(0,found+1);
- }
- UINT64 GetC_M_N(UINT64 M,UINT64 N)
- {
- UINT64 d = 1;
- UINT64 c = 1;
- for(UINT64 i = N;i > (N - M);i --)
- {
- c = c * i;
- }
- for(UINT64 i = 1;i <= M;i++)
- {
- c = c / i;
- }
- //ASSERT(0);//need test
- return c;
- }
- int GetRandomNumber(int Begin,int End)
- {
- srand(GetTickCount());
- return rand() % (End - Begin + 1) + Begin;
- }
- DWORD WaitForObjectAcurateTime(HANDLE event,DWORD dwMilliseconds)
- {
- double elapsed;
- DWORD passedTime = 0;
- LARGE_INTEGER startCount;
- LARGE_INTEGER endCount;
- LARGE_INTEGER freq;
- QueryPerformanceFrequency(&freq);
- while(passedTime < dwMilliseconds)
- {
- passedTime = 0;
- QueryPerformanceCounter(&startCount);
- if(WaitForSingleObject(event,dwMilliseconds) == WAIT_OBJECT_0)
- {
- return WAIT_OBJECT_0;
- }
- QueryPerformanceCounter(&endCount);
- elapsed = (double)(endCount.QuadPart - startCount.QuadPart) / freq.QuadPart;
- passedTime = (DWORD)(elapsed * 1000);
- if(dwMilliseconds > passedTime)
- {
- dwMilliseconds -= passedTime;
- }
- else
- {
- break;
- }
- }
- return WAIT_TIMEOUT;
- }
- BOOL StrToInt(char * str,int *result)
- {
- int value = 0;
- int sign = 1;
- int radix;
- if(*str == '-')
- {
- sign = -1;
- str++;
- }
- // 16=xVF5DJWWVD8JGx;rU_0x
- if(*str == '0' && (*(str+1) == 'x' || *(str+1) == 'X'))
- {
- radix = 16;
- str += 2;
- }
- else if(*str == '0') // 0K=xVFJWWV7{N*0
- {
- radix = 8;
- str++;
- }
- else
- {
- radix = 10;
- }
- while(*str)
- {
- if(radix == 16)
- {
- if(*str >= '0' && *str <= '9')
- {
- value = value * radix + *str - '0';
- }
- else
- {
- if((*str | 0x20) >= 'a' && (*str | 0x20) <= 'f')
- {
- value = value * radix + (*str | 0x20) - 'a' + 10;
- }
- else
- {
- return FALSE;
- }
- }
- }
- else
- {
- value = value * radix + *str - '0';
- }
- str++;
- }
- *result = sign*value;
- return TRUE;
- }
- int sundaySearch(const unsigned char *src,int len_s,const unsigned char *keystr,int len_key)
- {
- int i,j,pos=0;
- int next[256]={0};//nextJ}Wi#,T$4&@zOuJ<;/
- for(j=0;j<256;++j)//3uJ<;/nextJ}?E
- next[j]=len_key+1;
- for(j=0;j<len_key;++j)//IhVCnextJ}?E
- next[keystr[j]]=len_key-j;
- while( pos<(len_s-len_key+1) )//1i@zT-4.
- {
- i=pos;
- for(j=0;j<len_key;++j,++i)//1H=O
- {
- if(src[i]!=keystr[j])//R;5)2;F%Ed#,T-4.>M04UUnextLxW*
- {
- pos+=next[src[pos+len_key]];
- break;
- }
- }
- if(j==len_key)
- return pos;
- }
- return -1;//N^WS4.Tr75;X-1
- }
- DWORD GetMyTickCount()
- {
- return timeGetTime();
- }
- HBITMAP OutPutToBitMap16(BYTE* pBits,LONG width,LONG height)
- {
- BITMAPINFO bmpInfo;
- HBITMAP hBackBitmap;//
- //HDC hBackDC;
- LPVOID pBitBits;
- BYTE *pBitMapBits;
- ZeroMemory(&bmpInfo,sizeof(BITMAPINFO));
- bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
- bmpInfo.bmiHeader.biBitCount=16;
- bmpInfo.bmiHeader.biCompression = BI_RGB;
- bmpInfo.bmiHeader.biWidth=width;
- bmpInfo.bmiHeader.biHeight=height;
- bmpInfo.bmiHeader.biPlanes=1;
- bmpInfo.bmiHeader.biSizeImage=abs(bmpInfo.bmiHeader.biHeight)*bmpInfo.bmiHeader.biWidth*bmpInfo.bmiHeader.biBitCount/8;
- HDC hdc=GetDC(GetDesktopWindow());
- //hBackDC=CreateCompatibleDC(hdc);
- hBackBitmap= CreateDIBSection(hdc,&bmpInfo,DIB_RGB_COLORS,&(pBitBits),NULL,0);
- if(hBackBitmap==NULL)
- {
- MessageBox(NULL,"Unable to Create BackBuffer Bitamp","ERROR",MB_OK); return FALSE;
- }
- ReleaseDC(GetDesktopWindow(),hdc);
- //copy it
- pBitMapBits = (BYTE *)pBitBits;
- for(int i=0;i<height;i++)
- {
- memcpy((BYTE*)pBitBits+(i)*width*BITSPERPIXEL/16,
- (BYTE*)pBits+(i)*width*BITSPERPIXEL/16,
- width*BITSPERPIXEL/16);
- }
- //do the bitblt
- return hBackBitmap;
- }
- HBITMAP OutPutToBitMap(BYTE* pBits,LONG width,LONG height)
- {
- BITMAPINFO bmpInfo;
- HBITMAP hBackBitmap;//
- //HDC hBackDC;
- LPVOID pBitBits;
- BYTE *pBitMapBits;
- ZeroMemory(&bmpInfo,sizeof(BITMAPINFO));
- bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
- bmpInfo.bmiHeader.biBitCount=BITSPERPIXEL;
- bmpInfo.bmiHeader.biCompression = BI_RGB;
- bmpInfo.bmiHeader.biWidth=width;
- bmpInfo.bmiHeader.biHeight=height;
- bmpInfo.bmiHeader.biPlanes=1;
- bmpInfo.bmiHeader.biSizeImage=abs(bmpInfo.bmiHeader.biHeight)*bmpInfo.bmiHeader.biWidth*bmpInfo.bmiHeader.biBitCount/8;
- HDC hdc=GetDC(GetDesktopWindow());
- //hBackDC=CreateCompatibleDC(hdc);
- hBackBitmap= CreateDIBSection(hdc,&bmpInfo,DIB_RGB_COLORS,&(pBitBits),NULL,0);
- if(hBackBitmap==NULL)
- {
- MessageBox(NULL,"Unable to Create BackBuffer Bitamp","ERROR",MB_OK); return FALSE;
- }
- ReleaseDC(GetDesktopWindow(),hdc);
- //copy it
- pBitMapBits = (BYTE *)pBitBits;
- for(int i=0;i<height;i++)
- {
- memcpy((BYTE*)pBitBits+(i)*width*BITSPERPIXEL/8,
- (BYTE*)pBits+(i)*width*BITSPERPIXEL/8,
- width*BITSPERPIXEL/8);
- }
- //do the bitblt
- return hBackBitmap;
- }
- BOOL SaveImageDataToBMP( TCHAR *lpFileName, DWORD width, DWORD height, DWORD bits, void* pData )
- {
- if( bits != 32 )//bits != 24 &&
- return FALSE;
- BITMAPFILEHEADER bfh;
- ZeroMemory( &bfh, sizeof(BITMAPFILEHEADER) );
- bfh.bfType = ((WORD)('M'<<8)|'B');
- bfh.bfSize = 0;
- bfh.bfReserved2 = 0;
- bfh.bfReserved1 = 0;
- bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
- BITMAPINFO BitmapInfo;
- BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- BitmapInfo.bmiHeader.biPlanes = 1;
- BitmapInfo.bmiHeader.biBitCount = (WORD)bits;
- BitmapInfo.bmiHeader.biCompression = BI_RGB;
- BitmapInfo.bmiHeader.biSizeImage = 0;
- BitmapInfo.bmiHeader.biXPelsPerMeter = 0;
- BitmapInfo.bmiHeader.biYPelsPerMeter = 0;
- BitmapInfo.bmiHeader.biClrUsed = 0;
- BitmapInfo.bmiHeader.biClrImportant = 0;
- BitmapInfo.bmiHeader.biWidth = width;
- BitmapInfo.bmiHeader.biHeight = height;
- int dwPitch = width * bits / 8;
- while( dwPitch % 4 != 0 )
- dwPitch++;
- FILE* pFile = _tfopen( lpFileName, _T("wb") );
- fwrite( &bfh, sizeof(BITMAPFILEHEADER), 1, pFile );
- fwrite( &BitmapInfo, sizeof(BITMAPINFOHEADER), 1, pFile );
- fwrite( pData, sizeof(char), height * dwPitch, pFile );
- fclose( pFile );
- return TRUE;
- }
- BOOL SaveBitmap32To24(TCHAR *szFilename,BYTE* pBits,LONG width,LONG height)
- {
- BITMAPINFO bmpInfo;
- HBITMAP hBackBitmap;//
- LPVOID pBitBits;
- BYTE *pBitMapBits;
- ZeroMemory(&bmpInfo,sizeof(BITMAPINFO));
- bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
- bmpInfo.bmiHeader.biBitCount=32;
- bmpInfo.bmiHeader.biCompression = BI_RGB;
- bmpInfo.bmiHeader.biWidth=width;
- bmpInfo.bmiHeader.biHeight=height;
- bmpInfo.bmiHeader.biPlanes=1;
- bmpInfo.bmiHeader.biSizeImage=0;//abs(bmpInfo.bmiHeader.biHeight)*bmpInfo.bmiHeader.biWidth*4;
- HDC hdc=GetDC(GetDesktopWindow());
- hBackBitmap= CreateDIBSection(hdc,&bmpInfo,DIB_RGB_COLORS,&(pBitBits),NULL,0);
- if(hBackBitmap==NULL)
- {
- MessageBox(NULL,"Unable to Create BackBuffer Bitamp","ERROR",MB_OK); return FALSE;
- }
- ReleaseDC(GetDesktopWindow(),hdc);
- //copy it
- pBitMapBits = (BYTE *)pBitBits;
- LONG pointindex = 0;
- for(int i=0;i<height;i++)
- {
- for(int j = 0;j < width;j++)
- {
- pointindex = (i * width + j);
- //cpy(RGB,RGBA)
- memcpy(&pBitMapBits[pointindex*(BITMAPBITSPERPIXEL/8)],&pBits[pointindex*4],BITMAPBITSPERPIXEL/8);
- }
- }
- BOOL ret = SaveBitmap(szFilename,hBackBitmap);
- if(hBackBitmap)
- {
- DeleteObject(hBackBitmap);
- }
- return ret;
- }
- VOID GetMainDirctory(TCHAR *szDir)
- {
- TCHAR csCurrentPath[MAX_PATH] = {0};
- ::GetModuleFileName(NULL,csCurrentPath,MAX_PATH);
- //cut off last \
- //
- for(size_t i = strlen(csCurrentPath) - 1;i > 0;i--)
- {
- if(csCurrentPath[i] == '/')
- {
- csCurrentPath[i] = 0;
- break;
- }
- }
- strcpy(szDir,csCurrentPath);
- }
- void TrimTheA(PBYTE pBuff,DWORD width,DWORD height)
- {
- LONG pointindex = 0;
- LONG pointindex32 = 0;
- DWORD RealWidth = width*4;
- for(DWORD i=0;i<height;i++)
- {
- for(DWORD j = 0;j < width;j++)
- {
- pointindex = (i * RealWidth + j*(32/8));
- //erase last one
- pBuff[pointindex + 3] = 0;
- }
- }
- }
- PBYTE LoadBitMapFromFile(const TCHAR *szFilename,DWORD &width,DWORD &height)
- {
- BITMAPFILEHEADER bmpFileHeader;
- BITMAPINFOHEADER bmpInfo;
- PBYTE pBuff = NULL;
- PBYTE p32BitmapBuff = NULL;
- DWORD buffSize = 0;
- DWORD returnedLenth = 0;
- HANDLE fp = CreateFile(szFilename,GENERIC_READ | GENERIC_WRITE,0,0,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
- if(fp==INVALID_HANDLE_VALUE)
- {
- MessageBox(NULL,"Unable to Open Bitmap File","Error",MB_OK|MB_ICONERROR);
- return NULL;
- }
- ReadFile(fp,&bmpFileHeader,sizeof(BITMAPFILEHEADER),&returnedLenth,0);
- if(returnedLenth != sizeof(BITMAPFILEHEADER))
- {
- MessageBox(NULL,"Wrong Bitmap File Format ","Error",MB_OK|MB_ICONERROR);
- CloseHandle(fp);
- return NULL;
- }
- ReadFile(fp,&bmpInfo,sizeof(BITMAPINFOHEADER),&returnedLenth,0);
- if(returnedLenth != sizeof(BITMAPINFOHEADER) || bmpFileHeader.bfType != 'MB')
- {
- MessageBox(NULL,"Wrong Bitmap File Format ","Error",MB_OK|MB_ICONERROR);
- CloseHandle(fp);
- return NULL;
- }
- pBuff = new BYTE[bmpInfo.biSizeImage];
- width = bmpInfo.biWidth;
- height = bmpInfo.biHeight;
- DWORD RealWidth = bmpInfo.biSizeImage / height;
- ReadFile(fp,pBuff,bmpInfo.biSizeImage,&returnedLenth,0);
- if(returnedLenth != bmpInfo.biSizeImage)
- {
- MessageBox(NULL,"Wrong Bitmap File Format ","Error",MB_OK|MB_ICONERROR);
- CloseHandle(fp);
- delete []pBuff;
- return NULL;
- }
- LONG pointindex = 0;
- LONG pointindex32 = 0;
- p32BitmapBuff = new BYTE[width*height*sizeof(COLORREF)];
- memset(p32BitmapBuff,0,width*height*sizeof(COLORREF));
- for(DWORD i=0;i<height;i++)
- {
- for(DWORD j = 0;j < width;j++)
- {
- pointindex = (i * RealWidth + j*(BITMAPBITSPERPIXEL/8));
- pointindex32 = (i *width + j);
- //cpy(RGB,RGBA)
- memcpy(&p32BitmapBuff[pointindex32*(BITSPERPIXEL/8)],&pBuff[pointindex],BITMAPBITSPERPIXEL/8);
- }
- }
- CloseHandle(fp);
- delete []pBuff;
- return p32BitmapBuff;
- }
- BOOL SaveBitmap(TCHAR *szFilename,HBITMAP hBitmap)
- {
- HDC hdc=NULL;
- HANDLE fp=NULL;
- LPVOID pBuf=NULL;
- BITMAPINFO bmpInfo;
- BITMAPFILEHEADER bmpFileHeader;
- DWORD returnedLenth = 0;
- BOOL bret = TRUE;
- TCHAR csCurrentPath[MAX_PATH] = {0};
- ::GetModuleFileName(NULL,csCurrentPath,MAX_PATH);
- //cut off last \
- //
- for(int i = (int)strlen(csCurrentPath) - 1;i > 0;i--)
- {
- if(csCurrentPath[i] == '/')
- {
- csCurrentPath[i] = 0;
- break;
- }
- }
- strcat(csCurrentPath,"/");
- strcat(csCurrentPath, szFilename);
- do{
- if(szFilename == NULL)
- {
- break;
- }
- hdc=GetDC(NULL);
- ZeroMemory(&bmpInfo,sizeof(BITMAPINFO));
- bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
- GetDIBits(hdc,hBitmap,0,0,NULL,&bmpInfo,DIB_RGB_COLORS);
- if(bmpInfo.bmiHeader.biSizeImage<=0)
- bmpInfo.bmiHeader.biSizeImage=bmpInfo.bmiHeader.biWidth*abs(bmpInfo.bmiHeader.biHeight)*(bmpInfo.bmiHeader.biBitCount+7)/8;
- if((pBuf=malloc(bmpInfo.bmiHeader.biSizeImage))==NULL)
- {
- MessageBox(NULL,"Unable to Allocate Bitmap Memory","Error",MB_OK|MB_ICONERROR);
- bret = FALSE;
- break;
- }
- bmpInfo.bmiHeader.biCompression=BI_RGB;
- GetDIBits(hdc,hBitmap,0,bmpInfo.bmiHeader.biHeight,pBuf,&bmpInfo,DIB_RGB_COLORS);
- fp = CreateFile(csCurrentPath,GENERIC_READ | GENERIC_WRITE,0,0,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
- if(fp==INVALID_HANDLE_VALUE)
- {
- MessageBox(NULL,"Unable to Create Bitmap File","Error",MB_OK|MB_ICONERROR);
- bret = FALSE;
- break;
- }
- bmpFileHeader.bfReserved1=0;
- bmpFileHeader.bfReserved2=0;
- bmpFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bmpInfo.bmiHeader.biSizeImage;
- bmpFileHeader.bfType='MB';
- bmpFileHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
- WriteFile(fp,&bmpFileHeader,sizeof(BITMAPFILEHEADER),&returnedLenth,0);
- //fwrite(&bmpFileHeader,sizeof(BITMAPFILEHEADER),1,fp);
- WriteFile(fp,&bmpInfo.bmiHeader,sizeof(BITMAPINFOHEADER),&returnedLenth,0);
- //fwrite(&bmpInfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp);
- WriteFile(fp,pBuf,bmpInfo.bmiHeader.biSizeImage,&returnedLenth,0);
- //fwrite(pBuf,bmpInfo.bmiHeader.biSizeImage,1,fp);
- }while(false);
- if(hdc)
- ReleaseDC(NULL,hdc);
- if(pBuf)
- free(pBuf);
- if(fp && fp != INVALID_HANDLE_VALUE)
- CloseHandle(fp);
- return bret;
- }
- BOOL GetWcharFromChar(WCHAR *pWcharBuff,DWORD nWcharBuffLen,const char *pChar)
- {
- if(!pWcharBuff || nWcharBuffLen == 0 )
- {
- return FALSE;
- }
- std::wstring str;
- int uLen = MultiByteToWideChar(CP_UTF8,0,pChar,-1,NULL,0);
- if(uLen > 0 && uLen < (INT)nWcharBuffLen)
- {
- str.resize(uLen);
- MultiByteToWideChar(CP_UTF8,0,pChar,-1, (LPWSTR )&str[0],uLen);
- wcsncpy(pWcharBuff,str.data(),nWcharBuffLen);
- return TRUE;
- }
- return FALSE;
- }
- BOOL ConvWcharToChar(LPSTR pCharBuff,DWORD nCharBuffLen,WCHAR *pUniStr)
- {
- if(!pCharBuff || nCharBuffLen == 0 )
- {
- return FALSE;
- }
- int uLen = WideCharToMultiByte(CP_UTF8,0,pUniStr,-1,NULL,0,NULL,NULL);
- if(uLen > 0 && uLen < (INT)nCharBuffLen)
- {
- WideCharToMultiByte(CP_UTF8,0,pUniStr,-1, (LPSTR)pCharBuff,uLen,NULL,NULL);
- return TRUE;
- }
- return FALSE;
- }
- DWORD WINAPI TheSystemShutdown(LPVOID pPara)
- {
- HANDLE hToken;
- TOKEN_PRIVILEGES tkp;
- // Get a token for this process.
- if (!OpenProcessToken(GetCurrentProcess(),
- TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
- return 0;
- // Get the LUID for the shutdown privilege.
- LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
- &tkp.Privileges[0].Luid);
- tkp.PrivilegeCount = 1; // one privilege to set
- tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
- // Get the shutdown privilege for this process.
- AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
- (PTOKEN_PRIVILEGES)NULL, 0);
- if (GetLastError() != ERROR_SUCCESS)
- return 0;
- // Shut down the system and force all applications to close.
- if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,
- 0))
- return 0;
- return 1;
- }
- DWORD WINAPI TheSystemReboot(LPVOID pPara)
- {
- HANDLE hToken;
- TOKEN_PRIVILEGES tkp;
- // Get a token for this process.
- if (!OpenProcessToken(GetCurrentProcess(),
- TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
- return 0;
- // Get the LUID for the shutdown privilege.
- LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
- &tkp.Privileges[0].Luid);
- tkp.PrivilegeCount = 1; // one privilege to set
- tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
- // Get the shutdown privilege for this process.
- AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
- (PTOKEN_PRIVILEGES)NULL, 0);
- if (GetLastError() != ERROR_SUCCESS)
- return 0;
- // Shut down the system and force all applications to close.
- if (!ExitWindowsEx(EWX_REBOOT | EWX_FORCE,
- 0))
- return 0;
- return 1;
- }
- char GetXorKeyWithString(char *pCharBuff,size_t len)
- {
- size_t i = 0;
- char xkey = 0;
- for(i =0;i < len;i++)
- {
- xkey ^= pCharBuff[i];
- }
- return xkey;
- }
- void EncryptWithXorKey(char key,char *pCharBuff,UINT len)
- {
- UINT i = 0;
- for(i =0;i < len;i++)
- {
- pCharBuff[i] ^= key;
- }
- }
- void DoTheCrapyWithPassword(char *pPassword,char *pCharBuff,UINT len)
- {
- char key = GetXorKeyWithString(pPassword,strlen(pPassword));
- EncryptWithXorKey(key,pCharBuff,len);
- }
- INT GetRectWidth(RECT &rect)
- {
- return (rect.right - rect.left + 1);
- }
- INT GetRectHeight(RECT &rect)
- {
- return (rect.bottom - rect.top + 1);
- }
- void NormalizeRect(RECT &rect)
- {
- LONG temp;
- if (rect.right < rect.left)
- {
- temp = rect.left;
- rect.left = rect.right;
- rect.right = temp;
- }
- if (rect.bottom < rect.top)
- {
- temp = rect.bottom;
- rect.bottom = rect.top;
- rect.top = temp;
- }
- }
- POINT GetRectTopLeft(RECT &rect)
- {
- POINT pt;
- pt.x = rect.left;
- pt.y = rect.top;
- return pt;
- }
- POINT GetRectBottomRight(RECT &rect)
- {
- POINT pt;
- pt.x = rect.right;
- pt.y = rect.bottom;
- return pt;
- }
- #pragma warning(pop)
- Common_Funcs g_Common_Funcs;
|