problem with drawnin a user-defined line

This is a discussion on problem with drawnin a user-defined line within the Windows Programming forums, part of the Platform Specific Boards category; Hey, I have yet another problem(I bet you guys have written more of this program then me :-D .) This ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    202

    problem with drawnin a user-defined line

    Hey, I have yet another problem(I bet you guys have written more of this program then me :-D .) This problem is really bothering me though. I have been trying to fix it for several weeks but it just wont draw the line.
    This is the code that is exicuted when the user presses Ok on a dialog box. It's not throwing me errors when running so the infomation from the dialog box is good.
    Code:
    EndDialog (hDlg, 0) ;
    			drawinghdc = GetDC(hwnd) ;
    			rise = GetDlgItemInt(hDlg, 102, &risecheck, TRUE) ; //collect infomation
    			run = GetDlgItemInt(hDlg, 103, &runcheck, TRUE) ;
    			yintercept = GetDlgItemInt(hDlg, 104, &yinterceptcheck, TRUE) ;
    
    			if(risecheck == FALSE){ //check for completed infomation collection
    				MessageBox(hwnd, "Rise was not collected correctly", "Error on collection of data", MB_OK) ;
    			}
    			if(runcheck == FALSE){
    				MessageBox(hwnd, "Run was not collected correctly", "Error on collection of data", MB_OK) ;
    			}
    			if(yinterceptcheck  == FALSE){
    				MessageBox(hwnd, "yintercept was not collected correctly", "Error on collection of data", MB_OK) ;
    			}
    
    			rise = rise * yspace ;             //to set to scale
    			yintercept = yintercept * yspace ;
    			run = run * xspace ;
    
    			ystart =  ( rise / run) + yintercept ;     //to figure points of line
    			yend = ( rise / run) * 440 + yintercept ;
    			xstart =  ( rise / run) + yintercept ;
    			xend = ( rise / run) * 360 + yintercept ;
    
    			SelectObject (drawinghdc, GetStockObject (BLACK_PEN)) ; //select pen for line
    			movecheck = MoveToEx(drawinghdc, xstart, ystart, NULL) ; //draw move to starting point
    			if ( movecheck == 0){
    				MessageBox(hwnd, "Move was not completed correctly. Please report this", "MoveToEx was not completed correctly", MB_OK) ;
    			}
    
    			linecheck = LineTo(drawinghdc, xend, yend) ; //draw line to end point
    			if ( linecheck == 0){
    				MessageBox (hwnd, "LineTo was not completed correctly. Please report this", "LineTp was not completed correctly", MB_OK) ;
    			}
    			BitBlt(memhdc, 0, 0, clientWidth, clientHeight, drawinghdc, 0, 0, SRCCOPY) ;
    			SendMessage(hwnd, WM_PAINT, 0, 0) ;
    			ReleaseDC(hwnd, drawinghdc) ;
    This is my WM_PAINT response:
    Code:
    		GetUpdateRect(hwnd, &theRect, 0);
    		if (IsRectEmpty(&theRect))
    		{
    			GetClientRect(hwnd,&theRect);
    		}
    
    		hdc = BeginPaint (hwnd, &ps) ;
    		BitBlt(undohdc, 0, 0, clientWidth, clientHeight, hdc, 0, 0, SRCCOPY) ;
    		MarksDrawing(memhdc) ;
    		AxisDrawing(memhdc) ;
    		BitBlt(hdc, 0, 0, clientWidth, clientHeight, memhdc, 0, 0, SRCCOPY) ;
    
    		EndPaint (hwnd, &ps) ;
    		break ;
    The MarksDrawing and Axis drawings work fine so you dont need to see them. I can draw other shapes with out problem.
    The code to draw a user defined circle is below to compare:
    Code:
    EndDialog (hDlg, 0) ;
    			drawinghdc = GetDC(hwnd) ;
    			YPointCheck = GetDlgItemText(hDlg,104, ycentst, 10) ;  //collect infomation
    			ycent = atoi(ycentst) ;
    			XPointCheck = GetDlgItemText(hDlg, 103, xcentst , 10) ;
    			xcent = atoi(xcentst) ;
    			rad = GetDlgItemInt(hDlg, 102, &RadCheck, FALSE) ;
    
    			if(YPointCheck == 0){ //check for completion
    				MessageBox(hwnd, "PointY was not collected correctly", "Error on collection of data", MB_OK) ;
    			}
    			if(XPointCheck == 0){
    				MessageBox(hwnd, "PointX was not collected correctly", "Error on collection of data", MB_OK) ;
    			}
    			if(RadCheck == FALSE){
    				MessageBox(hwnd, "Radius was not collected correctly", "Error on collection of data", MB_OK) ;
    			}
    
    
    			ycenter = ycent * yspace ;
    			xcenter = xcent * xspace ;
    			xrad = rad * xspace ;
    			yrad = rad * yspace ;
    
    			if (xcenter > 0){               //to sepates quadrants correctly
    				xcenter = xcenter + (cxClient/2)  ;
    			}
    			if (xcenter < 0){
    				xcenter = xcenter + (cxClient/2) ;
    			}
    			if (ycenter > 0){
    				ycenter = -ycenter + (cyClient/2) ;
    			}
    			if (ycenter < 0){
    				ycenter = -(2 * ycenter) + ycenter + (cyClient/2) ;
    			}
    			SelectObject (drawinghdc, GetStockObject (NULL_BRUSH)) ;
    			SelectObject (drawinghdc, GetStockObject (BLACK_PEN)) ;
    			Ellipse(drawinghdc, xcenter - xrad, ycenter + yrad, xcenter + xrad, ycenter - yrad) ;    // draw point with radius of what you add or sumbtract
    			BitBlt(memhdc, 0, 0, clientWidth, clientHeight, drawinghdc, 0, 0, SRCCOPY) ;
    			SendMessage(hwnd, WM_PAINT, 0, 0) ;
    			ReleaseDC(hwnd, drawinghdc) ;
    			return TRUE ;
    Im sorry I posted so much code but everytime I post people ask for more code so I figured I would give you all the code that could possibly be the problem. I have tried for weeks to get this and have failed. And yes, CyClient, CxClient, xspace, all the HDC s, and yspace are all initilized and set correctly. The Circle code works fine but the line code doesnt draw anything.
    "Christ died for our sins. Dare we make his martyrdom meaningless by not committing them?"

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    Does the
    MarksDrawing(memhdc) ;
    AxisDrawing(memhdc) ;

    overwrite the DC?
    Try sending an InvalidateRect() or UpdateWindow() rather than a SendMessage() for the paint.

    No bitmap is selected/created into the drawinghdc.
    You use hwnd to get the DC in a function where the HWND is hDlg.

    Check for nulls or OOB variables as the cose runs.

    Try creating a thick pen as you may be compressing the image and the line may be scaled out.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    Originally posted by novacain
    Does the
    MarksDrawing(memhdc) ;
    AxisDrawing(memhdc) ;
    overwrite the DC?

    No they don't and if they do nothing woud draw

    Try sending an InvalidateRect() or UpdateWindow() rather than a SendMessage() for the paint.

    Again if this was the problem it would be on everything but its just on this.

    No bitmap is selected/created into the drawinghdc.

    Yeah it is. Thats in the WM_Create message its compatible with hdc.

    You use hwnd to get the DC in a function where the HWND is hDlg.

    I meant to do that otherwise it would draw on the dialog which I dont want it to do.

    Check for nulls or OOB variables as the cose runs.

    I dont understand this. What are OOB variables?


    Try creating a thick pen as you may be compressing the image and the line may be scaled out.

    This one did draw a line but this could be only on of the problems becuase the scale is all off, the first time you do it it just draws a small solid black box at alittle to the left of -7, 7 , and it only draws anything if the rise is more then run(you can't have a negative slope.)

    Any more ideas?
    "Christ died for our sins. Dare we make his martyrdom meaningless by not committing them?"

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    OOB = Out of bounds, outside the possible values. eg negitive numbers in a BitBlt() (as have to be positive eg [0 to width, 0 to height])

    Try supplying the values to the variables to draw a line you know will show up. eg a straight line from corner to corner.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking problems in Visual Studio
    By h3ro in forum C++ Programming
    Replies: 5
    Last Post: 03-04-2008, 01:39 PM
  2. space problem with user input
    By codebrawler in forum C++ Programming
    Replies: 5
    Last Post: 01-08-2006, 01:01 PM
  3. class template user defined obj
    By terracota in forum C++ Programming
    Replies: 4
    Last Post: 06-01-2004, 08:14 AM
  4. Command Line Argument problem
    By dredre in forum C Programming
    Replies: 2
    Last Post: 04-29-2004, 01:26 AM
  5. read to end of line problem
    By one1082 in forum C++ Programming
    Replies: 3
    Last Post: 11-07-2003, 03:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21