Basically, I'm trying to create an application that features a bunch of colored rectangles with text written on them that you can click, making it doing stuff. It runs pretty well, except for the fact that the text on each of the buttons (Created using DrawText()) is constantly flickering. Is there anything I can do to potentially fix this problem?
From your comment above, you describe calling the draw procedure of your application object form your main message loop. This is almost certainly the source of your problem. Not only will it lead to flickering, it sounds like you are running your application at 100% CPU utilization which is not good.
What you should do is handle the WM_PAINT message and only paint in response to that message. That is how Windows GUI apps are meant to work. I recommend you read up in any introductory Windows GUI book. The canonical such book is Petzold's Programming Windows.
Related
I have task to create client (best if it will be possible to build it for Windows & Linux) for some tools and printing hexagonal map.
I chose wxWidgets to use for that. I downloaded WxFormBuilder, that perfectly helps to create forms and code for them.
But I have to paint hexagonal map somewhere in that form. And I didn't found what item from instrument panel I have to use for that. I can add something like wxPanel one by hands in sources that was automatically created for me, but that is bad idea, because after every change from wxFormBuilder I will need to parse result again by hands.
I'm new with painting and graphic, but believe there have to be solution for that in wxFormBuilder, isn't it?
That's the thing about computer programming: at some time you always have to settle down and write some code. All those applications that promise to write code for you have to be abandoned at some point and you actually have to do some work: you have reached that point. ( Here is a link to more about this )
Here is a brief introduction to writing code to paint the application window in wxWidgets, with a minimal sample code: http://wiki.wxwidgets.org/WxDC
I am writing a small c++ program that should react to the sc_screensaver and sc_monitorpower event.
this should run in background hence no gui is intended.
Since i have no experience with the windows api yet, i am struggling a lot with this.
A already googled a lot and found many approaches which either i dont understand or dont work.
Can anyone of you give me a hint?
I read its about catching the wm_syscommand but that seems to be difficult because i dont have a window.
The only way to get messages is by a message loop and a window procedure.
If your program does not have a visible gui, you have to create a message-only window for that purpose, and your main must have the code to create it and to listen windows messages (note: "windows" here, refers to the system, not the gui).
I have a strange issue I've been unable to diagnose and am hoping someone can at least point me in the right direction. I have a C++ MFC application that collects data from various sources and displays it on the screen. After a random interval (typically around 5-10 minutes), however, the display gets "corrupted" in a way I've never seen or have been able to track down as shown in the image below (left is normal, right is corrupt):
The basic symptoms are:
Up/down arrow images turn into "5"s and "6"s.
Opening a combo box list results in just the item text displayed (list border and scroll bar is not shown).
Background colours on some controls don't update or display correctly.
Z-order is broken and the app controls "leak" through other windows placed on top.
Pressing Print-Screen with the app in focus no longer captures the window to the clipboard.
Closing and reopening the window does nothing.
Restarting the application gets things back to normal.
Things I've tried to eliminate as a possible cause include:
Operating System & Computer: The same issue is present on a variety of systems from Windows 7-64 bit to Windows Xp-32 bit.
Multi-threading: I added a mutex to prevent the display updates from occurring at the same time but it had no effect (as expected).
Memory Corruption: This has been my assumption all along but there are no signs of memory corruption at all. The base display code has been used for years with no similar issue as well as the base networking message library.
Specific Code: I have narrowed down the issue to one specific dialog among a variety of others that show no issue. They all use the same base code which would seem to indicate the issue lies in the specific display code for the dialog. Exactly how or why the issue occurs has eluded me so far.
Any ideas on what the cause might be or how to narrow it down would be great.
Update 1:
Doing some more timing/repeatable tests and it looks like leaving this one dialog running for a short while causes the issue. The amount time is consistently between 300-400 seconds before the issue shows up.
It sounds like your application could be leaking GDI objects. To check if that is the case, open your task manager and enable the GDI Objects column. Observe the number for your process and see if it's increasing continuously.
If that is actually the case, you should read Detect and Plug GDI Leaks in Your Code with Two Powerful Tools for Windows XP. That MSDN article also offers a tool named GDILeaks.exe that should help you identify your GDI Leaks.
In the case where these symptoms surface within a short time, it should be something that is drawn repeatedly that isn't freeing GDI resources properly. Possibly in (or called within) the windows procedure (OnPaint for example).
If I'm not mistaken Windows' GUI uses a ttf(?) font for those little icons, and it looks like the font gets destroyed somehow (DeleteObject being called with font's handle?)
In linux and when installing packages etc. There are some installers that have a progress bar and a dos window which shows the files being extracted etc. How can i add this window to my C++ Win32 programs so that i can have it showing the tasks im doing? I cannot find any documentation on MSDN.
Question: How can i add a console window (if that's what its called, sure looks like one) in my program to show the details of the task at hand being done?
Here is a window with what i am asking.. (personal info so I erased the details. :]
You cannot embed a real console window inside another window (although a windowed process can have a separate console window). While it looks like a console window / command prompt, it is just a matter of appearances. What you want to do is create a sub-window/control with similar characteristics as a console window and then redirect the console output from the application(s) being run to append to that sub-window. For more information on how to do redirect the console output in Windows, see http://support.microsoft.com/kb/190351.
That "dos window" is a regular edit control: CreateWindow(ES_MULTILINE, EDIT, ...
However, it has the font set to a fixed-width one (Looks like courier). This is done by sending WM_SETFONT to the edit control.
#user995048 says "You cannot embed a real console window inside another window". But "cannot" is a strong word! I can run an entire virtualized computer in a window if I wish. :) So one can quite reasonably intuit that there are ways of doing what you say.
Sure, it is true that what you've seen are almost certainly cases of output redirection into a custom widget, designed to mimic the simple appearance of a terminal. However...if you want to embed one application's window inside another, there are things you can look into which might fit. Cooperative methods exist like GtkPlug, for instance:
http://developer.gnome.org/gtk/2.24/GtkPlug.html
To actually capture a not-designed-to-cooperate app's window and throw it in your app would be trickier. But possible, just as screen captures and virtual machines are possible. Probably best to avoid that sort of thing unless there's really a cause for it, though...
Try this
http://www.codeguru.com/cpp/misc/misc/article.php/c277/
link. I think the solution provided is what you need.
I tried it many years ago and it worked. I have not tried it in newer versions of windows though.
Im developing an application and use FlashWindowEx to flash the update window however it always manages to steal focus from full screen applications like games and such.
This is not what i want and is very annoying. Is there any way to work out whats causing it to steal focus (tried commenting out FlashWindowEx but it still did) or a way to tell it not to steal focus.
This happens on all versions of windows (including 7) and the game is launched seperatly to the application.
Check out the WS_EX_NOACTIVATE window style perhaps?