Exemplo n.º 1
0
BOOL CScintillaWnd::OpenFile(LPCTSTR lpFileName)
{
	DWORD dwSize=0;
	const LPBYTE pbuf=map_file(lpFileName,&dwSize);
	if(!pbuf) return FALSE;
	SStringA str;
	if(dwSize>2 && pbuf[0]==0xFF  && pbuf[1]==0xFE)
	{//utf16
		SStringW strBuf((LPCWSTR)(pbuf+2),dwSize/2-1);
		str=S_CW2A(strBuf,CP_UTF8);
	}else if(dwSize>3 && pbuf[0]==0xEF && pbuf[1]==0xBB && pbuf[2]==0xBF)
	{//utf8有签名
		str=SStringA((LPCSTR)(pbuf+3),dwSize-3);
	}else
	{//utf8无签名
        str=SStringA((LPCSTR)pbuf,dwSize);
	}
	UnmapViewOfFile( pbuf );
	SendMessage(SCI_CLEARALL);
	SendMessage(SCI_ADDTEXT, str.GetLength(),
		reinterpret_cast<LPARAM>((LPCSTR)str));

	SendMessage(SCI_SETUNDOCOLLECTION, 1);
	::SetFocus(m_hWnd);
	SendMessage(EM_EMPTYUNDOBUFFER);
	SendMessage(SCI_SETSAVEPOINT);
	SendMessage(SCI_GOTOPOS, 0);
	UpdateLineNumberWidth();

	m_strFileName=lpFileName;
	return TRUE;
}
Exemplo n.º 2
0
bool San::FileIOStream::gloWriteFile(const SString &strFilePath, const SStringA &strData, const bool bCover)
{
	if (strFilePath.empty())
	{
		return false;
	}
	ios::openmode FileFlag = ios::binary | ios::out;
	if (bCover)
	{
		FileFlag = FileFlag | ios::trunc;
	}
	else
	{
		FileFlag = FileFlag | ios::ate;
	}
	fstream* pFile = new fstream(strFilePath, FileFlag, 0x40);
	if (pFile == nullptr)
	{
		return false;
	}
	(*pFile) << strData.c_str();
	pFile->close();
	delete pFile;
	pFile = nullptr;
	return true;
}
Exemplo n.º 3
0
void SQrCtrl::CreateQrImg( SStringT strContent )
{
	CQR_Encode qrEncode;
	int nLevel = 3;
	int nVersion = 0;
	bool bAutoExtent = true;
	int nMaskingNo = -1;
	SStringA strContentA = S_CT2A(strContent, CP_UTF8);
	if (qrEncode.EncodeData(nLevel, nVersion, bAutoExtent, nMaskingNo, strContentA, strContentA.GetLength()))
	{

		if (m_pSkin == NULL)
		{
			int qrSize = qrEncode.m_nSymbleSize + (QR_MARGIN * 2);
			CAutoRefPtr<IBitmap> bmp;
			GETRENDERFACTORY->CreateBitmap(&bmp);
			bmp->Init(qrSize, qrSize);
			LPDWORD pBits = (LPDWORD)bmp->LockPixelBits();
			memset(pBits, 0xFF, qrSize*qrSize * 4);
			int nLineWid = qrSize;
			LPDWORD pLine = pBits + QR_MARGIN*nLineWid;
			for (int i = 0; i < qrEncode.m_nSymbleSize; i++)
			{
				LPDWORD pLineData = pLine + QR_MARGIN;
				for (int j = 0; j < qrEncode.m_nSymbleSize; j++)
				{
					if (qrEncode.m_byModuleData[i][j])
					{
						pLineData[j] = RGBA(0, 0, 0, 255);
					}
				}
				pLine += qrSize;
			}
			bmp->UnlockPixelBits(pBits);
			SetImage(bmp);
		}
		else
		{
			int qrSize = qrEncode.m_nSymbleSize + 2;
			CAutoRefPtr<IBitmap> bmp;
			GETRENDERFACTORY->CreateBitmap(&bmp);
			SIZE skinSize = m_pSkin->GetSkinSize();
			CRect rcWind = GetWindowRect();

			bmp->Init(rcWind.Width(), rcWind.Height());

			CAutoRefPtr<IBitmap> qrbmp;
			GETRENDERFACTORY->CreateBitmap(&qrbmp);
			qrbmp->Init(qrSize, qrSize);
			LPDWORD pBits = (LPDWORD)qrbmp->LockPixelBits();
			memset(pBits, 0x00, qrSize*qrSize * 4);
			int nLineWid = qrSize;
			LPDWORD pLine = pBits + nLineWid;
			for (int i = 0; i < qrEncode.m_nSymbleSize; i++)
			{
				LPDWORD pLineData = pLine + 1;
				for (int j = 0; j < qrEncode.m_nSymbleSize; j++)
				{
					if (qrEncode.m_byModuleData[i][j])
					{
						pLineData[j] = RGBA(0xFF, 0xFF, 0xFF, 0xFF);
					}
				}
				pLine += qrSize;
			}
			qrbmp->UnlockPixelBits(pBits);
			MakeCacheApha(m_pSkin, bmp, qrbmp);
			SetImage(bmp);
		}
	}
}