Thread: HELP - Thread can't use any paint functions

  1. #1
    Registered User
    Join Date
    Mar 2004

    Question HELP - Thread can't use any paint functions

    I am making a thread for my Ray-Casting engine that paints one column of the screen. However for some reason, the thread cannot execute any paint commands.


    long WINAPI Thread(long lParam) {
    //This part is just doing some calculations for the engine.
    y = -30 + (DegreeChange * lParam);
    long info = lParam;
    distance1 = Distance(PlayerAngle + y, PlayerX, PlayerY, &BitmapColumn, &MidPoint);
    distance1 = distance1 * cos(y*PI/180);
    degrees = atan(64.0/distance1) / PI * 180;
    height = tan(degrees*PI/180) * DistanceToProjection;
    // These are the paint commands
    SelectObject(bufferDC, GrayPen);
    MoveToEx(bufferDC, info, 0, NULL);
    LineTo(bufferDC, info, MidPoint - height);
    SelectObject(Image, Texture);
    StretchBlt(bufferDC, info, MidPoint - height, 1, height * 2, Image, BitmapColumn - 1, 0, 1, 64, SRCCOPY);
    SelectObject(bufferDC, BluePen);
    MoveToEx(bufferDC, info, MidPoint + height, NULL);
    LineTo(bufferDC, info, (200 * SizeMult));

    BufferDC is a MemDC, it is global.
    Image is the same.
    SizeMult is a constant. (Global)

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Are you breaking this rule?
    Note that the handle to the DC can only be used by a single thread at any one time.
    Or this one?
    Windows 2000 and later: If hdc is NULL, the thread that calls CreateCompatibleDC owns the HDC that is created. When this thread is destroyed, the HDC is no longer valid. Thus, if you create the HDC andpass it to another thread, then exit the first thread, the second thread will not be able to use the HDC.
    You forgot the [/code] end tag.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An array of macro functions?
    By someprogr in forum C Programming
    Replies: 6
    Last Post: 01-28-2009, 07:05 PM
  2. Replies: 7
    Last Post: 11-17-2008, 01:00 PM
  3. C thread functions?
    By audinue in forum C Programming
    Replies: 3
    Last Post: 07-08-2008, 07:47 AM
  4. [code] Win32 Thread Object
    By Codeplug in forum Windows Programming
    Replies: 0
    Last Post: 06-03-2005, 03:55 PM
  5. Replies: 12
    Last Post: 05-17-2003, 05:58 AM