Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Comments
Kenneth Haugland 17-Aug-12 18:00pm    
In C? Do you mean C++/CLI or something like that?
Member 9365207 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 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 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 18-Aug-12 6:42am    
See below.

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/[^].
 
Share this answer
 
Comments
pasztorpisti 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 18-Aug-12 7:43am    
Tthanks, totally agree, Petzold's books are all excellent.
Member 9365207 18-Aug-12 8:17am    
Thanks for the recommendation. Gonna look at it :)
Member 9365207 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 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.
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.
 
Share this answer
 
Comments
Member 9365207 18-Aug-12 8:06am    
Thanks. The WS_CLIPCHILDREN style was exactly what I searched for.
pasztorpisti 18-Aug-12 8:34am    
You are welcome!

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900