GDI handle types - winapi

I'm currently trying to track down a GDI handle leak. I am currently using GDIView to track it down. The tool divides the GDI objects into categories Pen, ExtPen, Bitmap, Font, Palette, Region, DC, Metafile DC, Enhanced Metafile DC, and Other GDI. These categories are summed in a column called GDI Total. Ontop of that, there's a column called All GDI. It is in this column I am detecting the leak.
As I don't have the source code for the tool, I can't see what's really going on. Did the author of the tool miss a handle type? It looks like it. I do know there is a leak, because some users report that they are shown the infamous dialog A required resource was (end of text). It may take weeks for the dialog to show up, so I'm pretty sure it isn't a DC.
Any ideas on how to track this down would be much appreciated! As I have a limited budget, thousand dollar tools are out of the question. Debugging hooks into GDI would suffice, as I don't mind doing detective work.

I found the problem. Apparently, GDIView thinks that icons fall under the unknown category. The problem was an icon being loaded and attached to an object. The object was not setup to auto delete the icon upon destruction. E-mailing the author of said tool...

Once I had a similar problem and I used Task Manager - asked it to show GDI handles count for each process and stepped over the program code to see where the handles count unexpectedly increases and fails to decrease back. It took some time, but finally using divide-and-conquer I found the error.

Related

Blurred text in the TStatusBar control

I have for a very long time experienced a hugely annoying problem with the TStatusBar VCL control, a thin wrapper around the Win32 status bar control.
Since this appears to me as a very common and frustrating issue, I am very surprised Google (and StackOverflow) doesn't seem to know much about it.
The problem is that the status bar text becomes very blurred when it hasn't changed for a while; the precise conditions are still unknown to me. But I see this every day:
If one of the panels has its text updated, the new text is rendered correctly (see last panel):
Is this something that only happens when I am in the vicinity of running Delphi processes, or is it indeed a known issue? More importantly, is there a known cure? (And, academically, why does this happen? It wouldn't surprise me if it is related to transparent drawing of anti-aliased text by code originally designed for unthemed Win9x.)
I have tried to enable double-buffering, but I am not sure if that completely resolves the issue. (I have seen even worse behaviour in non-double-buffered list view controls, which is resolved by making them double-buffered.)
I made all status bars in my applications double-buffered a week ago, and I haven't seen any blurred text in any of them since then. Previously, I saw severely blurred text daily. Hence, it seems like this issue - whatever is causing it - can be fixed by making the status bars double buffered.

Does win32 TextOut() complete asynchronously?

This should be a simple google or MSDN answer - but I have come up short in searching. I have a small win32 application that uses GDI for a lot of drawing. I have observed that when I place a "label" with TextOut() on my memory Device Context, then BitBlt immediately after the TextOut() call, the text shows up intermittently, flickering in and out. The BitBlt() is in another thread, but I have a critical section to guard from copying the graphic under work. When I put the TextOut() earlier in the flow, i.e. not close to the BitBlt(), it always shows up. All I can figure is that TextOut() returns before completion.. can anyone point me to documentation or suggest another theory?
FYI - I have already checked out:
http://msdn.microsoft.com/en-us/library/dd145133(v=vs.85).aspx
Thanks!
Yes it does. GdiFlush() is the call to force all GDI updates to the video adapter.
Lots of other ways to shoot your foot. GDI is not thread-safe at all so don't expect miracles, I guess.

Weird Memory Problem of Cocoa Application

I am writing a Cocoa program for Mac, and it includes a picture viewer.
What the picture viewer's job is to download a picture from web and show it. It would do this every time I click a button who would give it a picture URL. So this would be frequent.
My design goal is, every time after I change to another picture or close it temporarily (it is not the main window), it will release the memory it takes. For example, before I open the picture viewer for a picture, my application takes 1M memory. After I open a picture, it takes about, say, 2M memory. And after I close it, it will decrease the memory usage to the original 1M.
The problem is, sometimes after I viewed a picture, especially a big one, the viewer won't give all the memory it took, for example, opening it cost about 20M memory, but after I close it, just 10 of the 20 released, the another 10 is still there and never be freed. It looks like memory leak, but I checked my code and analyzed it many times, I couldn't find any memory leak, and also, some other pictures won't behave like this.
this is weird, is this possibly certain Cocoa internal memory cache policy? Any suggestions would be appreciated. Thanks in advance!
Update: Today after I added a scrollView as a wrapper of the imageView, this weird memory problem seems almost fixed.
Thanks for your advice, edc1591, I will continue to figure out what happened.
Without seeing the code it's hard to tell quite what the problem is. But until I see the code, I'll give you a few pointers for dealing with this:
Enable Garbage Collection. If you already have it enabled, try forcing a garbage collection after releasing the image file like this:
[[NSGarbageCollector defaultCollector] collectIfNeeded];
Try heapshot analysis. Here's a good tutorial on that.
I'll update this answer once the code has been posted.

Get the word under the mouse cursor in Windows

Greetings everyone,
A friend and I are discussing the possibility of a new project: A translation program that will pop up a translation whenever you hover over any word in any control, even static, non-editable ones. I know there are many browser plugins to do this sort of thing on webpages; we're thinking about how we would do it system-wide (on Windows).
Of course, the key difficulty is figuring out the word the user is hovering over. I'm aware of MSAA and Automation, but as far as I can tell, those things only allow you to get the entire contents of a control, not the specific word the mouse is over.
I stumbled upon this (proprietary) application that does pretty much exactly what we want to do: http://www.gettranslateit.com/
Somehow they are able to get the exact word the user is hovering over in almost any application (It seems to have trouble in a few apps, notably Windows Explorer). It even grabs text out of obviously custom-drawn controls, somehow. At first I thought it must be using OCR. But even when I shrink the font so far down that the text becomes a completely unreadable blob, it can still recognize words perfectly. (And yet, it doesn't recognize anything if I change the font to Wingdings. But maybe that's by design?)
Any ideas as to how it's achieving this seemingly impossible task?
EDIT: It doesn't work with Wingdings, but it does work with some other nonsense fonts, so I've confirmed it can't be OCR.
You could capture the GDI calls that output text to the display, and then figure out which word's bounding box the cursor falls in.
Well, for GDI controls you can get the position and size of the control, and you can usually get the font info. For example, with static text controls you'd use WM_GETFONT. Then once you have that you can get the position of the mouse relative to the position of the control and use one of the font functions, perhaps something like GetTextExtentPoint32 to figure out what is under the cursor. I'm pretty sure the answer lies in that direction...
You can run dumpbin /imports on the other application and see what APIs they are calling.

Most useful animation in web or desktop application

Many animation effects are simply gratuitous eye candy -- however, there are situations where animations effectively communicate to the user what's going on.
What are some of your favorite uses for animations, and what specific animation type would you use?
E.g.: Animate items downwards when a new item is inserted into a list
I really like Google Chrome's use when a file is being downloaded. It's hard to describe, but, it's a circle that fills like a pie chart as the download progresses, and the circle is overlaid with the icon for the file you're downloading. Very slick.
One example I can think of is the animation used by operating systems when you minimize a window.
Both Microsoft Windows and Apple OS X animate the window going down to the taskbar (or the Dock in OS X) to show the user where the window went. Otherwise novice users that hit minimize by accident might have trouble getting the window back.
I don't use linux, but I'm pretty sure it does the same. I'm not being discriminative =)
From enjoy3d.com
enjoy3d.com http://worldsware.com/images/mouse.gif
Press your mouse button
and move to look around.
There is a very nice paper by Ben Bederson and Angela Boltman in which they evaluate the impact of animation on user’s ability to build a mental map of the information in the space:
Does Animation Help Users Build Mental Maps
of Spatial Information?
I believe that all visual changes should not be swift. Be it status notification, window maximized/minimized, or data deleted/added. I cannot find a reference, but usually it is recommended that all animations should not be around 1-2 seconds, matching human's response time.
My favorite uses of animation is not in a commercial software (though Apple is good at this) but a research paper called Phosphor which I consider one of the great UI ideas that have not yet implemented into major operating systems.
AJAX loading gifs - you've got to have an indicator that you definitely registered an event and you're doing something about it
Progress bars are nice for things that take more than a moment or two, but only when they are accurate. An inaccurate progress bar is worse than none, in my opinion.

Resources