Basic SetDIBitsToDevice question

I want to display a rectangle area from my bitmap on a screen. The area in bitmap is defined by its upper-left pixel coordinate (xBmp, yBmp), and size (wBmp, hBmp). The screen area is defined similarly with (xDest, yDest), and size (wDest, hDest). Since no bitmap stretching is done, wBmp=wDest, and hBmp=hDest. I am using the following code for display:
ret = SetDIBitsToDevice(
      hDC,                 // handle to DC
      xDest,               // x-coord of destination
      yDest,               // y-coord of destination
      wDest,           // source rectangle width
      hDest,          // source rectangle height
      xBmp,                // x-coord of source
      yBmp,                // y-coord of source
      0,         // first scan line in array
      hBmp,         // number of scan lines
      pix,     // array of DIB bits
      bInfo, // bitmap information
      DIB_RGB_COLORS          // RGB or palette indexes
and yet it shows my bitmap shifted vertically. What am I doing wrong?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ret = SetDIBitsToDevice(
     -hDest, // Make this negative

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
olegspAuthor Commented:
Now it fails to display anything at all, and returns GDI error.

It worked with positive hDest. I looked thru a lot of online examples, but they all use the simplest scenario of xDest=yDest=xBmp=yBmp=0. In my case, these aro not zeros. In particular, in my general case, where should I start my scan line, and how many scan lines should I use?
Based on your variable naming conventions, you may be setting the wrong values into:
    wDest,           // source rectangle width
    hDest,          // source rectangle height

These need to match values for the DIB (which is the source, not the Dest).

If that is not correct, then please decribe more specifically what you mean when your say "shifted vertically".  Thanks.

-- Dan
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.