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. visual studio 2003 MFC/SDI help drawing

visual studio 2003 MFC/SDI help drawing

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++visual-studiographics
3 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.
  • A Offline
    A Offline
    ALTF4
    wrote on last edited by
    #1

    ok I have made a program that simulates a petrol station (comming of cars etc..) it is a single MFC /SDI app in witch I made 2 functions first one delets the screen and the second one draws someting on the screen. I call this functions whit a timer (every 100ms) but there is a problem sometimes my program crashes and this is all that I get as help why it crashed Unhandled exception at 0x7c28af6a (mfc71d.dll) in seminarska.exe: 0xC0000005: Access violation reading location 0x00000004. So I'm sure that the problem is in this 2 functions : becouse if I run the program whit no drawing the program never crashes: ok here is the code for deleteing the screen: void CseminarskaView::brisi_ekran(void) { CDC*tabla=GetDC(); RECT Okno; GetClientRect(&Okno); CBrush copic(0xffffff); tabla->FillRect(&Okno,&copic); } and the code for drawing : void CseminarskaView::risi(Bencinska postaja[]) { //tukaj moram risati sproti CDC* tabla=GetDC(); RECT ena; ena.top=20; ena.left=20; ena.right=60; ena.bottom=60; int x1=0; int x2=0; int x3=255; int y=25; CString nizi; int i ; for (i=0;i<5;i++) { CString out; out.Format("%i",i+1); tabla->TextOut(10,y,out); CBrush pisalo(RGB(x1,x2,x3)); tabla->FillRect(&ena,&pisalo); ena.top=ena.top+60; ena.bottom=ena.bottom+60; x1=x1+60; x2=x2+60; x3=x3-60; y=y+60; //delete pisalo; } CString uu; y=25;int y1=500; for( i=0;i<5;i++) { for(int j=0;j { nizi=nizi+" I "; } tabla->TextOut(80,y,nizi); y=y+60; nizi=" "; uu.Format("postaja %i: %f",i,postaja[i].rezervar); tabla->TextOut(10,y1,uu); y1=y1+20; } } can someone please help me ? I think that the problem is CBrush but I'm not sure becouse sometimes the program finishes Ok sometimes not ///---there is no hope for you---\\\

    T 1 Reply Last reply
    0
    • A ALTF4

      ok I have made a program that simulates a petrol station (comming of cars etc..) it is a single MFC /SDI app in witch I made 2 functions first one delets the screen and the second one draws someting on the screen. I call this functions whit a timer (every 100ms) but there is a problem sometimes my program crashes and this is all that I get as help why it crashed Unhandled exception at 0x7c28af6a (mfc71d.dll) in seminarska.exe: 0xC0000005: Access violation reading location 0x00000004. So I'm sure that the problem is in this 2 functions : becouse if I run the program whit no drawing the program never crashes: ok here is the code for deleteing the screen: void CseminarskaView::brisi_ekran(void) { CDC*tabla=GetDC(); RECT Okno; GetClientRect(&Okno); CBrush copic(0xffffff); tabla->FillRect(&Okno,&copic); } and the code for drawing : void CseminarskaView::risi(Bencinska postaja[]) { //tukaj moram risati sproti CDC* tabla=GetDC(); RECT ena; ena.top=20; ena.left=20; ena.right=60; ena.bottom=60; int x1=0; int x2=0; int x3=255; int y=25; CString nizi; int i ; for (i=0;i<5;i++) { CString out; out.Format("%i",i+1); tabla->TextOut(10,y,out); CBrush pisalo(RGB(x1,x2,x3)); tabla->FillRect(&ena,&pisalo); ena.top=ena.top+60; ena.bottom=ena.bottom+60; x1=x1+60; x2=x2+60; x3=x3-60; y=y+60; //delete pisalo; } CString uu; y=25;int y1=500; for( i=0;i<5;i++) { for(int j=0;j { nizi=nizi+" I "; } tabla->TextOut(80,y,nizi); y=y+60; nizi=" "; uu.Format("postaja %i: %f",i,postaja[i].rezervar); tabla->TextOut(10,y1,uu); y1=y1+20; } } can someone please help me ? I think that the problem is CBrush but I'm not sure becouse sometimes the program finishes Ok sometimes not ///---there is no hope for you---\\\

      T Offline
      T Offline
      try88
      wrote on last edited by
      #2

      when access the NULL pointer ,the ERROR would appeal .

      ALTF4 wrote:

      Unhandled exception at 0x7c28af6a (mfc71d.dll) in seminarska.exe: 0xC0000005: Access violation reading location 0x00000004.

      the variable CBrush pisalo in the funtion risi() is abuse when for-loop run . so you should define a ptr outside for-loop like this ... CBrush* pBrush ; ... for(..) { pBrush= new CBrush(...) tabla->FillRect(..); delete pBrush; } 路漫漫其修远兮,吾将上下而求索。

      A 1 Reply Last reply
      0
      • T try88

        when access the NULL pointer ,the ERROR would appeal .

        ALTF4 wrote:

        Unhandled exception at 0x7c28af6a (mfc71d.dll) in seminarska.exe: 0xC0000005: Access violation reading location 0x00000004.

        the variable CBrush pisalo in the funtion risi() is abuse when for-loop run . so you should define a ptr outside for-loop like this ... CBrush* pBrush ; ... for(..) { pBrush= new CBrush(...) tabla->FillRect(..); delete pBrush; } 路漫漫其修远兮,吾将上下而求索。

        A Offline
        A Offline
        ALTF4
        wrote on last edited by
        #3

        ok I have make the code like you told me but it still does the same thing :( ///---there is no hope for you---\\\

        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