Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Mobile
  4. Displaying bitmap and SetDIBitsToDevice.....

Displaying bitmap and SetDIBitsToDevice.....

Scheduled Pinned Locked Moved Mobile
c++graphicshelplearning
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Episodio1
    wrote on last edited by
    #1

    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!

    S 1 Reply Last reply
    0
    • E Episodio1

      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!

      S Offline
      S Offline
      slumberparty
      wrote on last edited by
      #2

      maybe you have a memory leak! Change this line to free up the whole array!

      delete [] pBitData

      E 1 Reply Last reply
      0
      • S slumberparty

        maybe you have a memory leak! Change this line to free up the whole array!

        delete [] pBitData

        E Offline
        E Offline
        Episodio1
        wrote on last edited by
        #3

        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...

        E 1 Reply Last reply
        0
        • E Episodio1

          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...

          E Offline
          E Offline
          Episodio1
          wrote on last edited by
          #4

          I made a "dot.bmp" in resources and I'm showing it with "LoadBitmap". ^^ Maybe there's something I have to call after SetDIBToDevice?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups