nhj@cs.bham.ac.uk (Nick Jurascheck) (06/15/91)
Has anyone had any experience of using NULL_BRUSH as a window background ? i.e. wcClassName.hbrBackground = GetStockObject(NULL_BRUSH); . . RegisterClass(&wcClassName); I've tried this and it seems to work... usually, but not in all cases. My program sometimes fails to redraw the background as transparent e.g. when you move any dialog box around, or when you cancel one particular dialog box. Any part of the box that was in the client area remains there. Others work fine on OK or Cancel, unless you move them first! Iconising and restoring the window clears the problem. The background is being invalidated correctly, and my paint proc is called, because other things _do_ get drawn in these cases. I've even called InvalidateRect (for the whole window) and UpdateWindow explicitly after closing the one odd dialog box which doesn't disappear at all, but with no change. Incidentally, the program is a hot-spot editor, so it needs to run on top of another app (graphics or video display package), hence the need for a transparent background. Any help on this would be greatly appreciated - please email if possible, Nick Jurascheck -- Nick JANET: JurascheckNH@uk.ac.bham.cs | UUCP: ...!mcvax!bhamcs!JurascheckNH BITNET: JurascheckNH%cs.bham.ac.uk@ukacrl.bitnet INTERNET: JurascheckNH%cs.bham.ac.uk@cunyvm.cuny.edu
bcw@rti.rti.org (Bruce Wright) (06/16/91)
In article <1991Jun14.205944.15227@cs.bham.ac.uk> nhj@cs.bham.ac.uk (Nick Jurascheck) writes: >Has anyone had any experience of using NULL_BRUSH as a window background ? > >i.e. wcClassName.hbrBackground = GetStockObject(NULL_BRUSH); > . > . > RegisterClass(&wcClassName); > >I've tried this and it seems to work... usually, but not in all cases. >My program sometimes fails to redraw the background as transparent >e.g. when you move any dialog box around, or when you cancel one >particular dialog box. Any part of the box that was in the client area >remains there. Others work fine on OK or Cancel, unless you move them >first! Iconising and restoring the window clears the problem. The documentation on NULL_BRUSH may not be very clear, but this is in fact the proper behavior. NULL_BRUSH is used when you aren't sure what the background "ought" to be when the window is created - then you can redraw the background when you get the WM_PAINT message, and the background doesn't get redrawn twice. This could be the case, for example, for a GIF viewer or some other kinds of graphics programs that might not want a solid or simple patterned background (the only options available if you use anything other than NULL_BRUSH for hbrBackground). It might also be the case if the user could choose the background for the window that differed from the Windows defaults. In other words, NULL_BRUSH simply causes no action to be taken - and in your case, if the obscured bitmap has not been saved and restored when the dialog box exits, then the contents of the dialog box remain on the screen and all of the newly unobscured windows receive a WM_PAINT message. Since the only thing displayed in your client area is your own background 8-), then your background is not repainted. If I understand what you are trying to do - that is, that you want the window to be transparent and be able to view the windows under your client area - then this can't be done cleanly using the normal Windows procedures. You could probably do it with a certain amount of trouble by invalidating the windows obscured by your client area (walking the list of windows), or (probably a better approach) getting hold of the entire screen as a DC by using a CreateDC ("DISPLAY", NULL, NULL, NULL) call. Look at the BLOWUP program given in Petzold's book "Programming Windows" for an example of the use of this to capture the screen. You'd have to get to your toolbox through some normal window, of course ... Good luck - Bruce C. Wright