Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Win32 bitmaps

samibe29samibe29 Member Posts: 1
Hi am new to using MFC or doig GUI all together but i am writing this program and i don't understand why i can't get a map to display to the window i have generated.

I am using a TSIMapLib.lib that you may not be familiar with but that isn't the problem. It is just a table of contents for a bitmap files. I am tryint to display a bit map and here is the code i have. please help.

void OnDraw(HWND hWnd, HDC hDC)
{
RECT rt;
//HWND hWnd = AfxGetMainWnd()->m_hWnd;
// CTrakPointView* pView;
//pView = CTrakPointView::GetView();
HDC hdcMemory, memdc;
HBITMAP hbmp1, TerrainDC_BM;
BOOL BltRet;
HGDIOBJ SelObj, poldbmp, pOldBrush;

GetClientRect(hWnd, &rt);

// * * * Hide the Zoom in Zoom out buttons.
/* if (pView->m_ActiveScreen == MAP)
{
pView->m_CWndZoomIn = pView->GetDlgItem(IDC_BUTT_ZOOM_IN);
pView->m_CWndZoomOut = pView->GetDlgItem(IDC_BUTT_ZOOM_OUT);
pView->m_CWndZoomIn->ShowWindow(SW_SHOW);
pView->m_CWndZoomOut->ShowWindow(SW_SHOW);
}*/

// get the terrain bitmap
HBITMAP bm = gTDM.GetTerrainBitmap();
// ... and an HDC compatible with the display
HDC dc = gTDM.GetTerrainHDC();

// select the bitmap into the HDC
//* * * CHANGED this to debug slugishness anfetr 60-minute DEMO.
//bm = (HBITMAP) SelectObject(dc, bm);
TerrainDC_BM = (HBITMAP) SelectObject(dc, bm);
//* * * CHANGED this to debug slugishness anfetr 60-minute DEMO.

//* * * CAMSDB - Added here
hdcMemory = CreateCompatibleDC(dc);
//hbmp1 = CreateCompatibleBitmap(dc,640,480);
//* * * CHANGED this to debug slugishness anfetr 60-minute DEMO.
hbmp1 = CreateCompatibleBitmap(dc,320,240);
//* * * CHANGED this to debug slugishness anfetr 60-minute DEMO.
SelObj = SelectObject(hdcMemory, hbmp1);

BltRet = BitBlt(hdcMemory, rt.left, rt.top+24, rt.right, rt.bottom-40, dc, 0, 0, SRCCOPY);
//FillRect(hdcMemory, rt, m_Brush);
//SelectObject(hDC, GetSysColorBrush(COLOR_INFOBK));
//Ellipse(hDC, rt.left+5, rt.top+5, rt.right-3, rt.bottom-5);
BitBlt(hDC, rt.left, rt.top, rt.right, rt.bottom, hdcMemory, 0, 0, SRCCOPY);


}

Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : Hi am new to using MFC or doig GUI all together but i am writing
    : this program and i don't understand why i can't get a map to display
    : to the window i have generated.
    :
    : I am using a TSIMapLib.lib that you may not be familiar with but
    : that isn't the problem. It is just a table of contents for a bitmap
    : files. I am tryint to display a bit map and here is the code i
    : have. please help.
    :
    : void OnDraw(HWND hWnd, HDC hDC)
    : {
    : RECT rt;
    : //HWND hWnd = AfxGetMainWnd()->m_hWnd;
    : // CTrakPointView* pView;
    : //pView = CTrakPointView::GetView();
    : HDC hdcMemory, memdc;
    : HBITMAP hbmp1, TerrainDC_BM;
    : BOOL BltRet;
    : HGDIOBJ SelObj, poldbmp, pOldBrush;
    :
    : GetClientRect(hWnd, &rt);
    :
    : // * * * Hide the Zoom in Zoom out buttons.
    : /* if (pView->m_ActiveScreen == MAP)
    : {
    : pView->m_CWndZoomIn = pView->GetDlgItem(IDC_BUTT_ZOOM_IN);
    : pView->m_CWndZoomOut = pView->GetDlgItem(IDC_BUTT_ZOOM_OUT);
    : pView->m_CWndZoomIn->ShowWindow(SW_SHOW);
    : pView->m_CWndZoomOut->ShowWindow(SW_SHOW);
    : }*/
    :
    : // get the terrain bitmap
    : HBITMAP bm = gTDM.GetTerrainBitmap();
    : // ... and an HDC compatible with the display
    : HDC dc = gTDM.GetTerrainHDC();
    :
    : // select the bitmap into the HDC
    : //* * * CHANGED this to debug slugishness anfetr 60-minute DEMO.
    : //bm = (HBITMAP) SelectObject(dc, bm);
    : TerrainDC_BM = (HBITMAP) SelectObject(dc, bm);
    : //* * * CHANGED this to debug slugishness anfetr 60-minute DEMO.
    :
    : //* * * CAMSDB - Added here
    : hdcMemory = CreateCompatibleDC(dc);
    : //hbmp1 = CreateCompatibleBitmap(dc,640,480);
    : //* * * CHANGED this to debug slugishness anfetr 60-minute DEMO.
    : hbmp1 = CreateCompatibleBitmap(dc,320,240);
    : //* * * CHANGED this to debug slugishness anfetr 60-minute DEMO.
    : SelObj = SelectObject(hdcMemory, hbmp1);
    :
    : BltRet = BitBlt(hdcMemory, rt.left, rt.top+24, rt.right,
    : rt.bottom-40, dc, 0, 0, SRCCOPY);
    : //FillRect(hdcMemory, rt, m_Brush);
    : //SelectObject(hDC, GetSysColorBrush(COLOR_INFOBK));
    : //Ellipse(hDC, rt.left+5, rt.top+5, rt.right-3, rt.bottom-5);
    : BitBlt(hDC, rt.left, rt.top, rt.right, rt.bottom, hdcMemory, 0, 0,
    : SRCCOPY);
    :
    :
    : }
    :
    [color=Blue]Not sure what do you need to do, but here is some information:

    1. To simply draw a bitmap into HDC you need to follow these steps:
    - create compatible DC with the given DC
    - select given bitmap into created DC
    - perform BitBlt() from created DC into given DC
    - de-select back given bitmap
    - delete compatible (memory) DC

    I am not sure why you you need two calls to BitBlt().

    2. Your code does not de-select anything back from any of the DCs AND your code also does not delete any of bitmaps you create or any of DCs you create, so it baldy leak resources and these resources (DC and bitmaps) may be big. Few hundred calls to this OnDraw() function and you are out of memory.
    [/color]
  • LundinLundin Member Posts: 3,711
    Subject line changed to "Win32 bitmaps" rather than "HELP HELP HELP", since we have a posting policy against non-descriptive subjects.

    Please read the [link=http://www.programmersheaven.com/mb/mfc_coding/BoardInfo.aspx?S=B20000]posting policies [/link] before posting.

Sign In or Register to comment.