Click here to Skip to main content
15,915,611 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Remove the file in use Pin
CPallini4-Jun-08 1:56
mveCPallini4-Jun-08 1:56 
AnswerRe: Remove the file in use Pin
Hamid_RT4-Jun-08 21:10
Hamid_RT4-Jun-08 21:10 
GeneralRe: Remove the file in use Pin
mihai1234-Jun-08 21:16
mihai1234-Jun-08 21:16 
GeneralRe: Remove the file in use Pin
Hamid_RT4-Jun-08 21:32
Hamid_RT4-Jun-08 21:32 
GeneralRe: Remove the file in use Pin
mihai1234-Jun-08 21:43
mihai1234-Jun-08 21:43 
QuestionBitBlt is failing Pin
subramanyeswari4-Jun-08 1:06
subramanyeswari4-Jun-08 1:06 
AnswerRe: BitBlt is failing Pin
CPallini4-Jun-08 1:46
mveCPallini4-Jun-08 1:46 
GeneralRe: BitBlt is failing Pin
subramanyeswari4-Jun-08 1:51
subramanyeswari4-Jun-08 1:51 
This is my code
RECT rc;
HDC hdcMem, hdcOld;
BYTE* m_pDrawingSurfaceBits=NULL;
BITMAPINFOHEADER bmpInfoHeader = {0};;
HBITMAP hbmDIBSection = NULL;
HWND hParent,hChild=NULL;
char* szAppName = "view.exe";
BOOL bRet = IsProcessRunning(szAppName);
if (!bRet)
{
::MessageBox(hWnd,"Application is not running",NULL,NULL);

}


hParent = FindWindow("WindowViewer", NULL);
if (!hParent)
{
::MessageBox(hWnd,"not able to find WindowViewer class",NULL,NULL);
}
if(hParent)
hChild = FindWindowEx(hParent,NULL,"ViewPU",NULL);
if (!hChild)
{
::MessageBox(hWnd,"not able to find ViewPU class",NULL,NULL);
}


::SendMessage(hChild, WM_SYSCOMMAND, SC_HOTKEY, (LPARAM) hChild);
::SendMessage(hChild, WM_SYSCOMMAND, SC_RESTORE, (LPARAM) hChild);


GetWindowRect(hChild, &rc);


hdcOld = ::GetDC(hParent);
if(hdcOld == NULL)
::MessageBox(hWnd,"hdcOld null",NULL,NULL);
// Create a compatible DC.
hdcMem = CreateCompatibleDC(hdcOld);
if(hdcMem == NULL)
::MessageBox(hWnd,"hdcMem null",NULL,NULL);

// Create a DIBSection big enough for our client rectangle.
long width = rc.right-rc.left;
long height = rc.bottom-rc.top;
if(hdcMem != NULL)
{

bmpInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfoHeader.biBitCount = 24;
bmpInfoHeader.biPlanes = 1;
bmpInfoHeader.biCompression = BI_RGB;
bmpInfoHeader.biWidth =width;
bmpInfoHeader.biHeight = height;
bmpInfoHeader.biSizeImage = ((((bmpInfoHeader.biWidth * bmpInfoHeader.biBitCount) + 31) & ~31) >> 3) * bmpInfoHeader.biHeight;
hbmDIBSection = CreateDIBSection(hdcMem, (CONST BITMAPINFO*)&bmpInfoHeader, DIB_RGB_COLORS, (void**)&m_pDrawingSurfaceBits, NULL, 0);
}


// Select the bitmap into the off-screen DC.
HBITMAP hbmOld = (HBITMAP) SelectObject(hdcMem, hbmDIBSection);



bRet = BitBlt(hdcMem,0,0,width,height,hdcOld,0,0,SRCCOPY);//here it saying invalid handle
if (bRet ==0)
{
DWORD d=::GetLastError();
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);

::MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );}



BITMAPFILEHEADER bfh = {0};
bfh.bfType = 0X4D42;
bfh.bfOffBits = sizeof(BITMAPINFOHEADER)+sizeof(BITMAPFILEHEADER);
bfh.bfSize = bfh.bfOffBits+bmpInfoHeader.biSizeImage;



bRet = SetCurrentDirectory("c:\\testBitmap");
DWORD ret = GetLastError();
char filename[200];
char *dir= "c:\\testBitmap\\";
int j;
j = sprintf(filename,"%s",dir);
j+= sprintf(filename+j,"%s",temp);

j+= sprintf(filename+j,"%d",counter);
j+= sprintf(filename+j,"%s",".bmp");


HANDLE hFile = CreateFile(filename,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if (!hFile)
{
return ;
}
DWORD dwWritten = 0;
bRet = WriteFile(hFile,&bfh,sizeof(bfh),&dwWritten,NULL);
bRet = WriteFile(hFile,&bmpInfoHeader,sizeof(bmpInfoHeader),&dwWritten,NULL);
bRet = WriteFile(hFile,m_pDrawingSurfaceBits,bmpInfoHeader.biSizeImage,&dwWritten,NULL);
bRet = CloseHandle(hFile);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);

Regards, Subramanyeswari
GeneralRe: BitBlt is failing Pin
CPallini4-Jun-08 1:58
mveCPallini4-Jun-08 1:58 
GeneralRe: BitBlt is failing Pin
subramanyeswari4-Jun-08 2:04
subramanyeswari4-Jun-08 2:04 
GeneralRe: BitBlt is failing Pin
CPallini4-Jun-08 2:08
mveCPallini4-Jun-08 2:08 
GeneralRe: BitBlt is failing Pin
subramanyeswari4-Jun-08 2:15
subramanyeswari4-Jun-08 2:15 
QuestionRe: BitBlt is failing Pin
CPallini4-Jun-08 2:29
mveCPallini4-Jun-08 2:29 
AnswerRe: BitBlt is failing Pin
subramanyeswari4-Jun-08 2:39
subramanyeswari4-Jun-08 2:39 
GeneralRe: BitBlt is failing Pin
CPallini4-Jun-08 2:59
mveCPallini4-Jun-08 2:59 
JokeRe: BitBlt is failing Pin
Nelek4-Jun-08 7:21
protectorNelek4-Jun-08 7:21 
GeneralRe: BitBlt is failing Pin
CPallini4-Jun-08 8:02
mveCPallini4-Jun-08 8:02 
QuestionSending Device Context Through Shared Memory? Pin
Llasus4-Jun-08 0:05
Llasus4-Jun-08 0:05 
AnswerRe: Sending Device Context Through Shared Memory? Pin
Cedric Moonen4-Jun-08 1:03
Cedric Moonen4-Jun-08 1:03 
GeneralRe: Sending Device Context Through Shared Memory? Pin
Llasus4-Jun-08 1:15
Llasus4-Jun-08 1:15 
Questionhow to calculate mean of histogram? Pin
traelektro3-Jun-08 23:38
traelektro3-Jun-08 23:38 
AnswerRe: how to calculate mean of histogram? Pin
Hamid_RT4-Jun-08 21:10
Hamid_RT4-Jun-08 21:10 
GeneralRe: how to calculate mean of histogram? Pin
traelektro5-Jun-08 21:21
traelektro5-Jun-08 21:21 
GeneralRe: how to calculate mean of histogram? Pin
Hamid_RT6-Jun-08 1:31
Hamid_RT6-Jun-08 1:31 
GeneralRe: how to calculate mean of histogram? Pin
traelektro12-Jun-08 21:08
traelektro12-Jun-08 21:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.