SetSysColors(1, COLOR_WINDOW, nMyTransColor) , without redraw or block redraw
Author |
Message |
Filip Wtterwulgh #1 / 4
|
 SetSysColors(1, COLOR_WINDOW, nMyTransColor) , without redraw or block redraw
Hello, I want to read a bmp from a resource dll and make the background transparent . Therfore I use the code below . The problem is that the code below is integrated in a VB ActiveX Control , and for some reason it's pretty slow . Meaning that the user can see the screen flikker from the TempColor to the TransColor while the SetSysColor is done . Is there a possibility to change this behaviour ? Without the flikkering ? Or does somebody have a nice alternitive to put BMP's with transcolor in a Image List ? *** open library (hMyDLL) nLTempColor = GetSysColor(COLOR_WINDOW) Call SetSysColors(1, COLOR_WINDOW, nMyTransColor) *** all the active windows have a grey backcolor ' If hMyDLL <> 0 Then ' hLBmp = LoadImage(hMyDLL, sPName, IMAGE_BITMAP, nPX, nPY, LR_LOADTRANSPARENT) Call SetSysColors(1, COLOR_WINDOW, nLTempColor) *** all the active windows return to normal Set iPic = BmpToPicture(hLBmp) If Not (iPic Is Nothing) Then nMyIndexCount = nMyIndexCount + 1 Call myIl.ListImages.Add(nMyIndexCount, sPName, iPic) Hoping to hear from you . Filip W.
|
Sun, 03 Apr 2005 21:34:35 GMT |
|
 |
Jim Deut #2 / 4
|
 SetSysColors(1, COLOR_WINDOW, nMyTransColor) , without redraw or block redraw
This is a really bad way to do this! I don't think you can avoid the flicker, because it's all of windows doing it... The imageList has a method, I can't remember if it's called .Draw or Render (maybe it has both, but only one works properly? I forget, it's been awhile since I did this and I'm too lazy to look it up...) that'll draw the image with transparency. If that's not enough of a hint, repost your question in winapi.graphics and Mike S. will answer it for sure. Jim Deutch
Quote: >Hello, >I want to read a bmp from a resource dll and make the background transparent >. Therfore I use the code below . The problem is that the code below is >integrated in a VB ActiveX Control , and for some reason it's pretty slow . >Meaning that the user can see the screen flikker from the TempColor to the >TransColor while the SetSysColor is done . >Is there a possibility to change this behaviour ? Without the flikkering ? >Or does somebody have a nice alternitive to put BMP's with transcolor in a >Image List ? >*** open library (hMyDLL) >nLTempColor = GetSysColor(COLOR_WINDOW) > Call SetSysColors(1, COLOR_WINDOW, nMyTransColor) >*** all the active windows have a grey backcolor > ' > If hMyDLL <> 0 Then > ' > hLBmp = LoadImage(hMyDLL, sPName, IMAGE_BITMAP, nPX, nPY, >LR_LOADTRANSPARENT) > Call SetSysColors(1, COLOR_WINDOW, nLTempColor) >*** all the active windows return to normal > Set iPic = BmpToPicture(hLBmp) > If Not (iPic Is Nothing) Then > nMyIndexCount = nMyIndexCount + 1 > Call myIl.ListImages.Add(nMyIndexCount, sPName, iPic) >Hoping to hear from you . >Filip W.
|
Mon, 04 Apr 2005 00:04:20 GMT |
|
 |
Mike D Sutto #3 / 4
|
 SetSysColors(1, COLOR_WINDOW, nMyTransColor) , without redraw or block redraw
Quote: > This is a really bad way to do this! I don't think you can avoid the > flicker, because it's all of windows doing it... > The imageList has a method, I can't remember if it's called .Draw or > Render (maybe it has both, but only one works properly? I forget, > it's been awhile since I did this and I'm too lazy to look it up...) > that'll draw the image with transparency.
I'm by no means an expert on image list controls, but I believe the code you're looking for here is: ImageList1.ListImages(1).Draw Form1.hDC, 0, 0, imlTransparent However if possible draw everything to an off-screen buffer first then once everything's been drawn blit it all over to the render DC, this way you'll avoid the flicker cause by it's 2-stage blit. Have a look at the "Blitting with transparency" tutorial on my site for more information on this, also I'd imagine that this is most likely using TransparentBlt() behind the scenes which is known to have a resource leak which can cause problems when it's called recursively, for this I've written a replacement on my site in the ChromaBlt() library which does exactly the same thing. Quote: > If that's not enough of a hint, repost your question in > winapi.graphics and Mike S. will answer it for sure.
It's already here but I wasn't sure on the answer since I don't often work with the controls, guess now I have to answer though, huh? ;) Hope this helps, Mike -- EDais -- - Microsoft Visual Basic MVP - WWW: Http://EDais.earlsoft.co.uk/
|
Mon, 04 Apr 2005 01:13:51 GMT |
|
 |
Richard Maso #4 / 4
|
 SetSysColors(1, COLOR_WINDOW, nMyTransColor) , without redraw or block redraw
Quote: >I want to read a bmp from a resource dll and make the background transparent >. Therfore I use the code below . The problem is that the code below is >integrated in a VB ActiveX Control , and for some reason it's pretty slow . >Meaning that the user can see the screen flikker from the TempColor to the >TransColor while the SetSysColor is done . >Is there a possibility to change this behaviour ? Without the flikkering ? >Or does somebody have a nice alternitive to put BMP's with transcolor in a >Image List ?
Try this: Const ILD_TRANSPARENT = 1 Const IMAGE_BITMAP = 0 Const CLR_DEFAULT = &HFF000000 Const LR_CREATEDIBSECTION = &H2000 Private Declare Function ImageList_Draw Lib "comctl32.dll" _ (ByVal himl As Long, ByVal index As Long, ByVal hDCDest As Long, _ ByVal x As Long, ByVal y As Long, ByVal flags As Long) As Long Private Declare Function ImageList_SetOverlayImage Lib "comctl32.dll" _ (ByVal himl As Long, ByVal iImage As Long, ByVal iOverlay As Long) As Long Private Declare Function ImageList_Destroy Lib "comctl32.dll" _ (ByVal himl As Long) As Long Private Declare Function ImageList_LoadImage Lib "comctl32.dll" _ (ByVal hi As Long, ByVal lpBmp As String, ByVal cx As Long, _ ByVal cGrow As Long, ByVal crMask As Long, ByVal uType As Long, _ ByVal uFlags As Long) As Long 'Transparent color is topmost, leftmost pixel in image. himg = ImageList_LoadImage(hDLL, sPName, 0, 0, CLR_DEFAULT, IMAGE_BITMAP, LR_CREATEDIBSECTION) lret = ImageList_SetOverlayImage(himg, 0, 1) lret = ImageList_Draw(himg, 0, picDisplay.hdc, 0, 0, ILD_TRANSPARENT) picDisplay.Refresh lret = ImageList_Destroy(himg) -- Richard Mason
|
Mon, 04 Apr 2005 15:55:30 GMT |
|
|
|