Recently I took back an old drawing app created in VB6 some years () ago to add a few mods, just for my entertainment. I'm pretty satisfied with the result: now I have a rich set of primitives to draw and, this is the best, I can now fill every geometry with a scaled image.
There is only a SMALL problem that I can not fix, surely for my ignorance about GDI: when I rotate a geometry by an arbitrary angle (let say a square by 30 degrees), the included picture should rotate itself too still filling then inside.
I found some usefull articles on image rotation using XFORM, SetGraphicsMode and SetWorldTransform.
Everything is fine: in a test program I got the images rotated as I want...but the positioning of the image is not correct.

I assume that a short explanation of my procedures could help in identify the problem:
I have a PictureBox (called 'pic) as a screen where to draw (autoredraw=false)
A custom structure is filled with the 'object(s)' parameters (geometry, size, positiong, colors...).
Among these there are the 2 important info: the picture filename,if exists, and an empty DIB (cDIBclass) where, when needed, I store the sampled image. In this way the screen redraw is really fast since I just have to BitBlt from the DIB to screen; no reload or resample needed.
Every object has a number of PointAPIs to describe the geometry.
In the Redraw I create a Region on the screen (CreatePolygonRgn), draw the frame with FrameRgn and fill the interior with a solid color (FillRgn) OR Clip the region and then BitBlt the image IF the shape is not rotated, otherwise I call this Rotate procedure.
Code:
   If .objRot Then
      Call Rotate(pic, ob, .objRot)
   Else
      BitBlt pic.hDC, objX, objY, objW, objH, .objDIB.hDC, 0, 0, vbSrcCopy
   End If
This is the main part of the routine:
Code:
Public Sub Rotate(dst As PictureBox, obIndex As Long, degrees As Long)
   objX = .objRect.Left 'shape position
   objY = .objRect.Top
   objW = .objRect.Right - .objRect.Left  'shape size
   objH = .objRect.Bottom - .objRect.Top
   dx = objW / 2
   dy = objH /2
   ...
    nGraphicsMode = SetGraphicsMode(dst.hDC, GM_ADVANCED)
    mtx.eM11 = cosAng
    mtx.eM12 = -sinAng
    mtx.eM21 = sinAng
    mtx.eM22 = cosAng
    mtx.eDx = dX       'translate the rotation point
    mtx.eDy = dY       'to the middle of our destination
    SetWorldTransform dst.hDC, mtx
    BitBlt dst.hDC, objX, objY, objW, objH, .objDIB.hDC, 0, 0, vbSrcCopy
   ...
   cleanup
Where 'dst' is pic, the screen PictureBox.

This routine does its job, but the rotated image does not center and fill the shape.
I tried different combinations for dX and dY (0,0 ; object Top-Left; ...) and for the destination parameter in the BitBlt (objW, objH ; 0,0; center of shape...); no success.
I'm sure I'm doing wrong with the highlited setting; please help me.

Here is an example of what I get (the best result):
Name:  starting.jpg
Views: 96
Size:  14.9 KB
Name:  rotated.jpg
Views: 81
Size:  15.9 KB