Thread: More than 1 object on same Device Context (DC)

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    610

    More than 1 object on same Device Context (DC)

    Is it possible to draw on a bitmap using a pen tool.. I would presume both BMP object and pen object would need to be on the same DC if that make sense...

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The bitmap needs to be on the same DC as the pen, yes.

    The DC has multiple types of objects that it uses for different purposes, such as Pen is used fro LineTo, DrawText for example, whilst a Brush is used for Fill functions, and the Bitmap is the "destination surface" that you draw onto.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by matsp View Post
    The bitmap needs to be on the same DC as the pen, yes.

    The DC has multiple types of objects that it uses for different purposes, such as Pen is used fro LineTo, DrawText for example, whilst a Brush is used for Fill functions, and the Bitmap is the "destination surface" that you draw onto.

    --
    Mats
    Am thinking how do i select two objects on the same DC, does this mean i need to call SelectObject() twice?

    i.e...
    Code:
    oldPen = (HPEN)SelectObject(hMemDC, pen);	
    hOldBmp = SelectObject(hMemDC, hBmp);
    Is this code correct?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, the SelectObject would "know" what type of object you are selecting and "do the right thing".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by matsp View Post
    Yes, the SelectObject would "know" what type of object you are selecting and "do the right thing".

    --
    Mats
    here's my code... nothing works!

    Code:
    HPEN pen, oldPen;
    
    pen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));	
    hMemDC = CreateCompatibleDC(0);
    
    hOldBmp = SelectObject(hMemDC, hBmp);	
    oldPen = (HPEN)SelectObject(hMemDC, pen);				
    		
    MoveToEx(hMemDC, centre.x,centre.y, NULL);		
    LineTo(hMemDC, coord.x, coord.y.y);					
    
    SelectObject(hMemDC, oldPen); 
    SelectObject (hMemDC, hOldBmp);					
    
    //DeleteObject(pen);
    DeleteDC(hMemDC);									
    
    RadarBgrnd.Repaint ();
    anything wrong?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    "nothing works" is a pretty poor description of a problem.

    Check that CreatePen and SelectObject are not returning NULL.

    Edit: Also check that LineTo() and MoveToEx returns non-zero.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by matsp View Post
    "nothing works" is a pretty poor description of a problem.

    Check that CreatePen and SelectObject are not returning NULL.

    Edit: Also check that LineTo() and MoveToEx returns non-zero.

    --
    Mats
    Was rather asking if the code is correct (logic & syntax) without even compiling it.. I still have issues with the tool i'm using (QUEST)... If the code is correct then i will know that QUEST is really not the tool for what am trying to do..

    Thanks

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Looks OK to me, aside from what I perceive as a typo:
    Code:
    LineTo(hMemDC, coord.x, coord.y.y);
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by matsp View Post
    Looks OK to me, aside from what I perceive as a typo:
    Code:
    LineTo(hMemDC, coord.x, coord.y.y);
    --
    Mats
    Thanx Mat

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Telling a shared_ptr not to delete object?
    By TriKri in forum C++ Programming
    Replies: 5
    Last Post: 08-16-2008, 04:26 AM
  2. [code] Win32 Thread Object
    By Codeplug in forum Windows Programming
    Replies: 0
    Last Post: 06-03-2005, 03:55 PM
  3. Writing data to a Printer Device Context
    By leojose in forum Windows Programming
    Replies: 2
    Last Post: 05-12-2005, 10:08 PM
  4. Device context woes
    By samGwilliam in forum Windows Programming
    Replies: 13
    Last Post: 04-16-2005, 10:01 PM