Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C
Hi,
I'm using a timer to print a pre buffered bitmap on the hdc. (i hope this is the right way to say this)
Now I want to see a static control on top of all of this. I try to create it when the WM_Create event is called and then to move it to the top after the bitmap has been printed. But it just doesn't show up on top.
I've tried SetWindowPos with the HWND_TOPMOST parameter, BringWindowToTop, and SetForegroundWindow. All of them don't return NULL as if the function succeeds.
What I've thought of might be the problem is that the Bitmap already gets reprinted before the static control has been set into the foreground as I call the timer every 25 Milliseconds.

I hope someone has an idea how I could fix this.
 
I'm really no expert in Win32 programming, so please explain what I've done wrong here.
Posted 17-Aug-12 11:57am
roym899123
Comments
Kenneth Haugland at 17-Aug-12 18:00pm
   
In C? Do you mean C++/CLI or something like that?
Member 9365207 at 18-Aug-12 4:19am
   
I use the Win32 API and right now i only use C-Syntax as I'm more used to it. Although it's a c++ project. So i can also use Classes.
Richard MacCutchan at 18-Aug-12 4:55am
   
Assuming the data in your static control is some text that you want to display over the bitmap, you could do it by merely writing the text in the correct position after the bitmap has been drawn.
Member 9365207 at 18-Aug-12 5:51am
   
But then I would need to call CreateWindow every time the timer is called right? And also destroy the old one before I create a new one. Another problem of this is that the Static Control (yes it's just some text) will flicker when I recreate it every 25 milliseconds or so.
Richard MacCutchan at 18-Aug-12 6:42am
   
See below.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If all you want is drawing a background picture on your window (without animation and any movement) behind the controls on your window then you should draw from the message WM_PAINT handler of your main window. Inside your WM_PAINT you should use the BeginPaint()[^] and EndPaint()[^] functions. You can find a code example for the WM_PAINT handler in the documentation of the BeginPaint() function I linked. BeginPaint() returns a HDC for you to draw on. To avoid overdrawing the child controls of your window you should create your main window with WS_CLIPCHILDREN style. When this style is set your BeginPaint() returns a HDC on which the validatable region excludes the area occupied by child controls so your drawing should not overdraw them.
  Permalink  
Comments
Member 9365207 at 18-Aug-12 8:06am
   
Thanks. The WS_CLIPCHILDREN style was exactly what I searched for.
pasztorpisti at 18-Aug-12 8:34am
   
You are welcome!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I'm afraid you are going about this in the wrong way. You call CreatWindow() only once, at the beginning of your program. You then update the content of the window within your handler for the WM_PAINT message, at which time you would (re-)draw the bitmap and write the text. I am not sure what you are trying to do with the timer. If you want a good simple tutorial that explains how to build a Windows program then take a look at http://www.winprog.org/tutorial/[^].
  Permalink  
Comments
pasztorpisti at 18-Aug-12 7:09am
   
+5, You are right, knowing the basics is very important before putting together applications in practice. If the OP likes reading books more than watching the monitor then my recommendation on win32 programming is: http://www.charlespetzold.com/pw5/
Richard MacCutchan at 18-Aug-12 7:43am
   
Tthanks, totally agree, Petzold's books are all excellent.
Member 9365207 at 18-Aug-12 8:17am
   
Thanks for the recommendation. Gonna look at it :)
Member 9365207 at 18-Aug-12 8:17am
   
I actually readed through this tutorial already and also done everything like explained in it. I also fixed my problem with WS_CLIPCHILDREN like pasztorpisti suggested. I have one last question: Probably a little bit off topic, but when I create this Static window in a function. And call this function once with the WM_TIMER event and once with the WM_PAINT event. Why do I don't see this window, when I'm not moving the window. If I do, I can see it flickering but atleast it is there. When I add the function only in the timer I see it always. (i've fixed it another way already, but still wonder why this occurs, because it just doesn't make sense to me)
Richard MacCutchan at 18-Aug-12 8:24am
   
I suspect that is because you draw the bitmap on the window, then draw the static control, which invalidates the bitmap and raises a WM_PAINT message. This then causes you to re-draw the bitmap and then re-write the static control which again invalidates ... and you are in a paint loop which will either not show some control or show it flickering.
pasztorpisti at 18-Aug-12 8:31am
   
You might see flickering because the client are of the window is drawn by 2 events: one WM_ERASEBKGND and one WM_PAINT event in this order. The idea is that WM_ERASEBKGND is supposed to be very fast, while WM_PAINT can last a bit longer. The reason for using two functions comes from older times, I dont think this is an issue today with 3D accelerated desktops. The point is that first WM_ERASEBKGND fills the client are with the brush you set up in the WNDCLASSEX when the window class was registered. You can prevent WM_ERASEBKGND from filling your window before drawing the bitmap from WM_PAINT by handling the WM_ERASEBKGND and returning TRUE (1) from it without doing anything. But in this case you have to make sure that you draw the whole client area from your WM_PAINT otherwise the undrawn are might behave unexpectedly. I often do that with owner drawn controls. Another note is that you should force a WM_PAINT event by calling either InvalidateRect() or RedrawWindow(), and not by directly sending the message.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 840
1 OriginalGriff 508
2 Abhinav S 278
3 thatraja 225
4 Emre Ataseven 200
0 Sergey Alexandrovich Kryukov 8,142
1 OriginalGriff 4,665
2 Peter Leow 3,774
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 18 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid