如何将此代码转换为NON-MFC格式? [英] How to convert this code to NON-MFC format?
本文介绍了如何将此代码转换为NON-MFC格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它不应该依赖于MFC.它应该作为服务运行.怎么做
It should not depend on MFC. And it should run as a service. How to do this
HDC hScrDC = ::GetDC(NULL);
HDC hMemDC = NULL;
BYTE *lpBitmapBits = NULL;
int nWidth = GetSystemMetrics(SM_CXSCREEN);
int nHeight = GetSystemMetrics(SM_CYSCREEN);
hMemDC = ::CreateCompatibleDC(hScrDC);
BITMAPINFO bi;
ZeroMemory(&bi, sizeof(BITMAPINFO));
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = nWidth;
bi.bmiHeader.biHeight = nHeight;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 24;
HBITMAP bitmap = ::CreateDIBSection(hMemDC, &bi, DIB_RGB_COLORS, (LPVOID*)&lpBitmapBits, NULL, 0);
HGDIOBJ oldbmp = ::SelectObject(hMemDC, bitmap);
::BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, 0, 0, SRCCOPY);
BITMAPFILEHEADER bh;
ZeroMemory(&bh, sizeof(BITMAPFILEHEADER));
bh.bfType = 0x4d42; //bitmap
bh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bh.bfSize = bh.bfOffBits + ((nWidth*nHeight)*3);
CFile file;
char buffer[1000];
DWORD threadId;
int value = 10;
//hThread = CreateThread( NULL, 0, runThread, &value, 0, &threadId);
for(int c=0;c<10;c++)
{
sprintf_s(buffer,"D:\image%u.jpg",c);
CString sName(buffer);
LPCTSTR lpszName = sName;
if(file.Open(lpszName, CFile::modeCreate | CFile::modeWrite))
{
file.Write(&bh, sizeof(BITMAPFILEHEADER));
file.Write(&(bi.bmiHeader), sizeof(BITMAPINFOHEADER));
file.Write(lpBitmapBits, 3 * nWidth * nHeight);
file.Close();
Sleep(10000);
}
}
::SelectObject(hMemDC, oldbmp);
::DeleteObject(bitmap);
::DeleteObject(hMemDC);
::ReleaseDC(NULL, hScrDC);
推荐答案
几乎都是用Win32 API编写的.我只看到MFCCString
和CFile
.
Windows API与LPCSTR和LPCTR一起使用,而不是CString,但这是用于非Unicode版本的.对于Unicode版本,请使用LPCWSTR和LPWSTR. LPCTSTR和LPTSTR声明用作泛型声明,具体取决于编译情况—是否为Unicode.
有关更多信息,请参见此CodeProject文章:
什么是TCHAR,WCHAR,LPSTR,LPWSTR,LPCTSTR等? [ ^ ].
HFILE句柄应与OpenFile
,<code>
CreateFile等函数一起使用,而不是CFile
, ^ ].
—SA
It is almost all written in Win32 API. I only see MFCCString
andCFile
.
Windows API works with LPCSTR and LPCTR instead of CString, but this is for non-Unicode version. For Unicode version, use LPCWSTR and LPWSTR. The declarations LPCTSTR and LPTSTR are used as generic ones, depending on compilation — as Unicode or not.
See this CodeProject article for more information:
What are TCHAR, WCHAR, LPSTR, LPWSTR, LPCTSTR etc?[^].
Instead ofCFile
, HFILE handle should be used with functions likeOpenFile
,<code>
CreateFile, etc., http://msdn.microsoft.com/en-us/library/aa364232(v=vs.85).aspx[^].
—SA
非Mfc表示您想要哪种格式?首先确定您要使用哪种语言来实现服务.这里有一些很好的链接,对您有很大帮助
http://www.devx.com/cplus/Article/9857 [ Windows服务应用程序 [ CNTService v1.06-NT服务框架 [
Non Mfc means in which format do you want ? First decide in which language you want to implelemt service. here are some good links which will help you lot
http://www.devx.com/cplus/Article/9857[^]
A Windows Service Application[^]
CNTService v1.06 - NT Service Framework[^]
自 ^ ]
这篇关于如何将此代码转换为NON-MFC格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文