Displaying bitmap and SetDIBitsToDevice.....
-
Hi! I'm new into drawing with Visual C++ MFC. I've got an empty DIALOG where I load a floor layout (BMP resource) and I want to draw on it a dot indicating my position (using "SetDIBitsToDevice") I call "Invalidate()" in another function when I get new coordinates to print on screen. Problem is that my PocketPC freezes every 3rd-4th time I run this function. As I cannot borrow another PDA from anyone for now I would like to know if code is all right, or if there is any tricky command I'm using.
void CDisplayDlg::OnPaint()
{
CColoredDlg::OnPaint(); // My dialog is based on a superior class (ColoredDlg), so I run first its Paint.//Code to display layout HBITMAP hBmpL1=::LoadBitmap(AfxGetResourceHandle(), MAKEINTRESOURCE(IDB\_DISPLAY\_BITMAP)); CRect rc; this->GetClientRect(&rc); HDC hdc1 = ::GetDC(this->m\_hWnd); HDC hdcmem = ::CreateCompatibleDC(hdc1); ::SelectObject(hdcmem,hBmpL1); ::BitBlt(hdc1, rc.left, rc.top, rc.right, rc.bottom, hdcmem,0,0,SRCCOPY); BITMAPINFO BitmapInfo; BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
// GetDIBits for WinCE
CWinCEUnsupportedFunctions::GetDIBits(hdcmem, hBmpL1, 0, 0,
NULL, &BitmapInfo, DIB_PAL_COLORS);//Code for displaying the current location of the user
BYTE\* pBitData = new BYTE\[36\]; for(int i=0;i<36;i++) { pBitData\[i\]=8; } scale=3.3; if(numPositions==1) { ::SetDIBitsToDevice(hdc1, (int)(xcoord1\*scale), (int)(ycoord1\*scale), 6, 6, 0, 0, 0, 6, pBitData, &BitmapInfo, DIB\_PAL\_COLORS); } delete pBitData;
}
Thanks!
-
Hi! I'm new into drawing with Visual C++ MFC. I've got an empty DIALOG where I load a floor layout (BMP resource) and I want to draw on it a dot indicating my position (using "SetDIBitsToDevice") I call "Invalidate()" in another function when I get new coordinates to print on screen. Problem is that my PocketPC freezes every 3rd-4th time I run this function. As I cannot borrow another PDA from anyone for now I would like to know if code is all right, or if there is any tricky command I'm using.
void CDisplayDlg::OnPaint()
{
CColoredDlg::OnPaint(); // My dialog is based on a superior class (ColoredDlg), so I run first its Paint.//Code to display layout HBITMAP hBmpL1=::LoadBitmap(AfxGetResourceHandle(), MAKEINTRESOURCE(IDB\_DISPLAY\_BITMAP)); CRect rc; this->GetClientRect(&rc); HDC hdc1 = ::GetDC(this->m\_hWnd); HDC hdcmem = ::CreateCompatibleDC(hdc1); ::SelectObject(hdcmem,hBmpL1); ::BitBlt(hdc1, rc.left, rc.top, rc.right, rc.bottom, hdcmem,0,0,SRCCOPY); BITMAPINFO BitmapInfo; BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
// GetDIBits for WinCE
CWinCEUnsupportedFunctions::GetDIBits(hdcmem, hBmpL1, 0, 0,
NULL, &BitmapInfo, DIB_PAL_COLORS);//Code for displaying the current location of the user
BYTE\* pBitData = new BYTE\[36\]; for(int i=0;i<36;i++) { pBitData\[i\]=8; } scale=3.3; if(numPositions==1) { ::SetDIBitsToDevice(hdc1, (int)(xcoord1\*scale), (int)(ycoord1\*scale), 6, 6, 0, 0, 0, 6, pBitData, &BitmapInfo, DIB\_PAL\_COLORS); } delete pBitData;
}
Thanks!
maybe you have a memory leak! Change this line to free up the whole array!
delete [] pBitData
-
maybe you have a memory leak! Change this line to free up the whole array!
delete [] pBitData
It keep freezing. Should I use "deleteDC" or "restoreDC" ?? How would be the code? It might be my PocketPC. If anyone is willing to test it in their own PDA... http://telefonica.net/web/episodio1/Proyect_004.PocketPC2003.exe[^] (1'53 Mb) http://telefonica.net/web/episodio1/data.txt[^] (a few bytes. "data.txt" needs to be in "\My device\My Documents" ) It's peekpocket from this website and I've added a 3rd tab. You'd have to press MI POSICION (My position). Then go to 2nd tab and switch ALGORITHM. And go back to MI POSICION. 2 or 3 times...
-
It keep freezing. Should I use "deleteDC" or "restoreDC" ?? How would be the code? It might be my PocketPC. If anyone is willing to test it in their own PDA... http://telefonica.net/web/episodio1/Proyect_004.PocketPC2003.exe[^] (1'53 Mb) http://telefonica.net/web/episodio1/data.txt[^] (a few bytes. "data.txt" needs to be in "\My device\My Documents" ) It's peekpocket from this website and I've added a 3rd tab. You'd have to press MI POSICION (My position). Then go to 2nd tab and switch ALGORITHM. And go back to MI POSICION. 2 or 3 times...