Prev: Argh! Some MS manager needs to be rolled in tar and feathersand put on public display.
Next: Network Port Algorithms
From: B.S on 11 Jan 2010 08:13 at first hy all. I am creating a steak man program, for animating i am using rgn. problem begins after some movments here is project link: http://www.datafilehost.com/download-579f6730.html i thing my problem is some where here: void BmpToRgn( HBITMAP bmp, HWND hwnd, BITMAP bi) { HRGN ResRgn; HRGN rgn; BYTE bpp; DWORD TransPixel; DWORD pixel; int startx; int i, j; ResRgn = CreateRectRgn(0, 0, 0, 0); GetObject(bmp, sizeof( BITMAP ), &bi); bpp = bi.bmBitsPixel >> 3; BYTE *pBits = new BYTE[ bi.bmWidth * bi.bmHeight * bpp ]; int p = GetBitmapBits( bmp, bi.bmWidth * bi.bmHeight * bpp, pBits ); TransPixel = RGB(255,0,255); for (i = 0; i < bi.bmHeight; i++) { startx=-1; for (j = 0; j < bi.bmWidth; j++) { pixel = *(DWORD*)(pBits + (i * bi.bmWidth +j) * bpp) << (32 - bi.bmBitsPixel); if (pixel != TransPixel) { if (startx<0) { startx = j; } else if (j == (bi.bmWidth - 1)) { rgn = CreateRectRgn( startx, i, j, i + 1 ); CombineRgn( ResRgn, ResRgn, rgn, RGN_OR); startx=-1; } } else if (startx>=0) { rgn = CreateRectRgn(startx, i, j, i + 1); CombineRgn(ResRgn, ResRgn, rgn, RGN_OR); startx=-1; } } } SetWindowRgn(hwnd, ResRgn, TRUE); delete[] pBits; DeleteObject(rgn); DeleteObject(ResRgn); }
From: Seetharam on 11 Jan 2010 12:07 Add this check: void BmpToRgn( HBITMAP bmp, HWND hwnd, BITMAP bi) { BOOL res = GetObject(bmp, sizeof( BITMAP ), &bi); if(!res) return; ..... } -Seetharam
From: Random on 11 Jan 2010 12:34 On Jan 11, 5:13 am, "B.S" <giobs...(a)gmail.com> wrote: > SetWindowRgn(hwnd, ResRgn, TRUE); > delete[] pBits; > DeleteObject(rgn); > DeleteObject(ResRgn); The system owns the region you pass in SetWindowRgn, don't delete it (or do anything else to it, for that matter, after the call to SetwindowRgn). Btw, you look into layered windows ( http://msdn.microsoft.com/en-us/library/ms997507.aspx ), they're more effecient for animation compared to constantly changing window regions.
From: B.S on 11 Jan 2010 13:54 program is showing that problem is her but i coudn't anderstend wat is problem i am deleting that pBits after all done BYTE *pBits = new BYTE[ bi.bmWidth * bi.bmHeight * bpp ];
From: Seetharam on 11 Jan 2010 17:22
On Jan 11, 1:54 pm, "B.S" <giobs...(a)gmail.com> wrote: > program is showing that problem is her but i coudn't anderstend wat is > problem i am deleting that pBits after all done > > BYTE *pBits = new BYTE[ bi.bmWidth * bi.bmHeight * bpp ]; Hi BS, When it fails, your bitmap is NULL. If you check the "bi.bmHeight" , it has some invalid large ints. Thats the reason I asked you to add a check in my earlier reply. HTH -Seetharam |