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. General Programming
  3. C / C++ / MFC
  4. using bitmap as logo in diaglog-based app

using bitmap as logo in diaglog-based app

Scheduled Pinned Locked Moved C / C++ / MFC
helpgraphics
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.
  • S Offline
    S Offline
    swatgodjr
    wrote on last edited by
    #1

    i can get the code to compile just fine but when i go to launch my application i get an assertion error, i narrowed down the block of code that might be causing it but i also think i am not correctly writing the code to display the bitmap. this block of code in my OnInitDialog function is where i get the problem from i think. m_st1.GetClientRect( &rectStaticClient ); rectStaticClient.NormalizeRect(); m_size.cx=rectStaticClient.Size().cx; m_size.cy=rectStaticClient.Size().cy; m_size.cx = rectStaticClient.Width(); m_size.cy = rectStaticClient.Height(); m_st1.ClientToScreen( &rectStaticClient ); ScreenToClient( &rectStaticClient); m_pt.x = rectStaticClient.left; m_pt.y = rectStaticClient.top; GetObject( m_hBmpNew , sizeof(BITMAP), &m_bmInfo ); VERIFY(m_hBmpOld = (HBITMAP)SelectObject(m_dcMem, m_hBmpNew ) ); offsetx= m_pt.x; offsety=m_pt.y; InvalidateRect(&rectStaticClient); not really messed with graphics coding much before, if soemone could help me out with whats possibly going on i would really appreciate it.

    M 1 Reply Last reply
    0
    • S swatgodjr

      i can get the code to compile just fine but when i go to launch my application i get an assertion error, i narrowed down the block of code that might be causing it but i also think i am not correctly writing the code to display the bitmap. this block of code in my OnInitDialog function is where i get the problem from i think. m_st1.GetClientRect( &rectStaticClient ); rectStaticClient.NormalizeRect(); m_size.cx=rectStaticClient.Size().cx; m_size.cy=rectStaticClient.Size().cy; m_size.cx = rectStaticClient.Width(); m_size.cy = rectStaticClient.Height(); m_st1.ClientToScreen( &rectStaticClient ); ScreenToClient( &rectStaticClient); m_pt.x = rectStaticClient.left; m_pt.y = rectStaticClient.top; GetObject( m_hBmpNew , sizeof(BITMAP), &m_bmInfo ); VERIFY(m_hBmpOld = (HBITMAP)SelectObject(m_dcMem, m_hBmpNew ) ); offsetx= m_pt.x; offsety=m_pt.y; InvalidateRect(&rectStaticClient); not really messed with graphics coding much before, if soemone could help me out with whats possibly going on i would really appreciate it.

      M Offline
      M Offline
      mbue
      wrote on last edited by
      #2

      The assert comes from the previous selected bitmap in your memory DC - 'm_hBmpOld' is null. To display a bitmap you have to paint it OnPaint() not to select it to an DC (DisplayContext). HDC mdc; HGDIOBJ obmp; BITMAP bmi; if(m_hbmp && GetObject(m_hbmp,sizeof(bmi),&bmi)) { mdc = CreateCompatibleDC(hdc); obmp = SelectObject(mdc,m_hbmp); BitBlt(hdc,offsetx,offsety,bmi.biWidth,bmi.biHeight,mdc,0,0,SRCCOPY); SelectObject(mdc,obmp); DeleteDC(mdc); }

      S 1 Reply Last reply
      0
      • M mbue

        The assert comes from the previous selected bitmap in your memory DC - 'm_hBmpOld' is null. To display a bitmap you have to paint it OnPaint() not to select it to an DC (DisplayContext). HDC mdc; HGDIOBJ obmp; BITMAP bmi; if(m_hbmp && GetObject(m_hbmp,sizeof(bmi),&bmi)) { mdc = CreateCompatibleDC(hdc); obmp = SelectObject(mdc,m_hbmp); BitBlt(hdc,offsetx,offsety,bmi.biWidth,bmi.biHeight,mdc,0,0,SRCCOPY); SelectObject(mdc,obmp); DeleteDC(mdc); }

        S Offline
        S Offline
        swatgodjr
        wrote on last edited by
        #3

        tried using the code and sayign hdc is undeclared and when i make it a hdc variable it says oen fo them was used without being initialized. how i set up my dialog was i made a picture control and from there not quite sure exactly what to do, the code you gave by its self wont just display my image as i am sure more code is needed but i get multiple assertions when i load my app and if i ignore them it loads but no image loaded. this is my code so far(most commented out though) that would do the image loading, but i get multiple assertions. afx_msg BOOL CPLoader::OnInitDialog() { /*CClientDC dc(this); m_dcMem.CreateCompatibleDC(&dc); m_hbmp = (HBITMAP) LoadImage( AfxGetInstanceHandle(), "plogo.bmp", IMAGE_BITMAP, 300, 65, LR_LOADFROMFILE); m_st1.SetBitmap(m_hbmp); if( m_hBmpNew == NULL ) { AfxMessageBox("Failed to Load Image"); } else { m_st1.GetClientRect( &rectStaticClient ); rectStaticClient.NormalizeRect(); m_size.cx=rectStaticClient.Size().cx; m_size.cy=rectStaticClient.Size().cy; m_size.cx = rectStaticClient.Width(); m_size.cy = rectStaticClient.Height(); m_st1.ClientToScreen( &rectStaticClient ); ScreenToClient( &rectStaticClient); m_pt.x = rectStaticClient.left; m_pt.y = rectStaticClient.top; GetObject( m_hBmpNew , sizeof(BITMAP), &m_bmInfo ); //VERIFY(m_hBmpOld = (HBITMAP)SelectObject(m_dcMem, m_hBmpNew ) ); offsetx= m_pt.x; offsety=m_pt.y; InvalidateRect(&rectStaticClient); }*/ return true; } afx_msg void CPLoader::OnPaint() { HDC mdc, hdc; HGDIOBJ obmp; BITMAP bmi; if(m_hbmp && GetObject(m_hbmp,sizeof(bmi),&bmi)) { mdc = CreateCompatibleDC(hdc); obmp = SelectObject(mdc,m_hbmp); BitBlt(hdc,offsetx,offsety,bmi.bmWidth,bmi.bmHeight,mdc,0,0,SRCCOPY); SelectObject(mdc,obmp); DeleteDC(mdc); } /*if(IsIconic()) { CPaintDC dc(this); SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1)/2; int y = (rect.Height() - cyIcon +1)/2; dc.DrawIcon(x, y, m_hIcon); } else { CPaintDC dc(this); dc.BitBlt(offsetx, offsety, m_size.cx, m_size.cy, &m_dcMem, sourcex, sourcey, SRCCOPY); CDialog::OnPaint(); }*/ } this is based off of an article i re

        M 1 Reply Last reply
        0
        • S swatgodjr

          tried using the code and sayign hdc is undeclared and when i make it a hdc variable it says oen fo them was used without being initialized. how i set up my dialog was i made a picture control and from there not quite sure exactly what to do, the code you gave by its self wont just display my image as i am sure more code is needed but i get multiple assertions when i load my app and if i ignore them it loads but no image loaded. this is my code so far(most commented out though) that would do the image loading, but i get multiple assertions. afx_msg BOOL CPLoader::OnInitDialog() { /*CClientDC dc(this); m_dcMem.CreateCompatibleDC(&dc); m_hbmp = (HBITMAP) LoadImage( AfxGetInstanceHandle(), "plogo.bmp", IMAGE_BITMAP, 300, 65, LR_LOADFROMFILE); m_st1.SetBitmap(m_hbmp); if( m_hBmpNew == NULL ) { AfxMessageBox("Failed to Load Image"); } else { m_st1.GetClientRect( &rectStaticClient ); rectStaticClient.NormalizeRect(); m_size.cx=rectStaticClient.Size().cx; m_size.cy=rectStaticClient.Size().cy; m_size.cx = rectStaticClient.Width(); m_size.cy = rectStaticClient.Height(); m_st1.ClientToScreen( &rectStaticClient ); ScreenToClient( &rectStaticClient); m_pt.x = rectStaticClient.left; m_pt.y = rectStaticClient.top; GetObject( m_hBmpNew , sizeof(BITMAP), &m_bmInfo ); //VERIFY(m_hBmpOld = (HBITMAP)SelectObject(m_dcMem, m_hBmpNew ) ); offsetx= m_pt.x; offsety=m_pt.y; InvalidateRect(&rectStaticClient); }*/ return true; } afx_msg void CPLoader::OnPaint() { HDC mdc, hdc; HGDIOBJ obmp; BITMAP bmi; if(m_hbmp && GetObject(m_hbmp,sizeof(bmi),&bmi)) { mdc = CreateCompatibleDC(hdc); obmp = SelectObject(mdc,m_hbmp); BitBlt(hdc,offsetx,offsety,bmi.bmWidth,bmi.bmHeight,mdc,0,0,SRCCOPY); SelectObject(mdc,obmp); DeleteDC(mdc); } /*if(IsIconic()) { CPaintDC dc(this); SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1)/2; int y = (rect.Height() - cyIcon +1)/2; dc.DrawIcon(x, y, m_hIcon); } else { CPaintDC dc(this); dc.BitBlt(offsetx, offsety, m_size.cx, m_size.cy, &m_dcMem, sourcex, sourcey, SRCCOPY); CDialog::OnPaint(); }*/ } this is based off of an article i re

          M Offline
          M Offline
          mbue
          wrote on last edited by
          #4

          you have to modify your code for using MFC: CPaintDC dc(this); HDC mdc; HGDIOBJ obmp; BITMAP bmi; if((HBITMAP)m_hbmp && ::GetObject(m_hbmp,sizeof(bmi),&bmi)) { mdc = ::CreateCompatibleDC(dc.m_hDC); obmp = ::SelectObject(mdc,m_hbmp); ::BitBlt(dc.m_hDC,offsetx,offsety,bmi.bmWidth,bmi.bmHeight,mdc,0,0,SRCCOPY); ::SelectObject(mdc,obmp); ::DeleteDC(mdc); } Please mark your code as 'code'.

          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