|
Here it is 2014 as I write this but I remember downloading this years ago and finally getting around to using it.
Out of the all the web searching back then and still now it's one of the, if not the, best working examples around.
Like the title says "Win32 API", any other examples I could find were using MFC, or some other bloated GUI framework.
It's still a gem and really helped me as a launching point to get my own custom window frames going.
Now yes it has a few problems. It kind of looks like this was a working prototype, and, or some rough cut and paste from some larger project. Might have a memory leak and bug or two, parts of it are not being used, etc.
But then it just works, simple, elegant..shows you a Windows XP looking window frame on what ever Windows OS you run it on, regardless of your theme or performance settings.
On a side note I came here to give thanks and appreciation..and sure enough the "entitled" ones amongst us world of programmers has to make flaming derogatory post(s). You know like that annoying "know it all" type that you probably forced to work with (that you would rather punch in the face if you had more of a choice). The guy that thinks he knows it all, just looks at things from the surface, thinks he makes him self look smart by pointing out problems in other peoples code (just hope you don't have to look at his).
And come on, really?, this is the first time you got an access violation building someone else's code?
It should go with out saying, are you using the same compiler and dev setup, the same exact libs, and did you think of using a debug build?
You've taken the phrase: "Don't look a gift horse in the mouth" down another level. Let's see your "teeth", I mean code, first.
It was easy enough to walk though to refactor and work it into my own style and preferences.
I took the included resource frame graphics and turned the saturation all the way down and played with the brightness to get a neat dark gray look I wanted for starters.
Now I'm in the process of adding my own little button class/object to easily add more buttons to the title bar (like the way Photoshop does their detailed custom title bar et al), and now I'm taking out most of the bitmaps instead using direct rectangle and line fill blits to give my frame a more Windows 8 style square look, etc.
Again thanks for out of all the bloated, overly complicated, expensive pay skin toolkits, etc., making a good working example that anyone can build off of.
modified 19-Mar-14 23:05pm.
|
|
|
|
|
First, it is my first program in Windows GUI and "borrow" some ideas from my friend, and the basic owner draw was tested from MSDN. This is a test program simply for FUN, not mature and robust. It has some buges like memory leak that you just point out.
Second, thank you for your long and honest comments to my article, it really helpful. I hope it can give hints and helpness for beginners.
PS: if your GUI framework was finished, could you tell me?
|
|
|
|
|
Do you try DirectUI? it is popular now.
|
|
|
|
|
Sorry for the late reply. I went off to another project for a while, now back on it again..
Thanks. You know I did look DirectUI a little. The problem is that it's not well documented, not even officially supported (wasn't Microsoft supposed to document all of these internal APIs as part of it's antitrust settlement?). Although that alone wouldn't stop me as there appears to be enough to use it at least, but it appears that it's Vista and greater.
Also the same issue with using the newer DWM stuff, it's also Vista or better.
It dawned on me, the biggest problem I have with doing total title bar customization stuff is that we pretty much have
to do all of our own drawing for buttons and such. Heaven forbid you want to add a combo box or something there, as you'ed probably have to make the control from scratch (or use some already made sources for it) as the standard controls won't work there (AFAIK) as they are not aware of "WM_NCxxx" messages et al.
SO? why not just remove the title bar altogether and just draw it your self?
This is probably what most people now of days do it.
So using your code as a basis I just setup through a WM_NCCALCSIZE to have a minimal boarder of '0' at the top, thus no OS maintained title bar at all.
Like the "DwmExtendFrameIntoClientArea()" function but works with XP to Windows 8.1 too.
With this setup the mouse will turn to resize mode when you hover over the top edge still. Then I emulate the title (watching mouse drags to move the window, drawing the icon and text, etc.) with what ever standard controls I want added on it.
I only really need to handle WM_NCPAINT now to just draw the side and bottom boarders.
|
|
|
|
|
Hello,
It still is very ammusing how some people try and program but yet most dont even understand the concept of how Microsoft does stuff and how windows works.
This source will never make it to any real application because the programmer is NOT using alot of the Windows API in the correct way. Oh dont believe it well for one compile the project in debug mode and you will instantly see one major flaw and that is Access Violation User 32 DLL, Really dude you mean you dont check this out but just build it in release mode and yes it does run in release mode cause its not checking to see that your using the API correctly as debug mode does.
Next comment is on the CopyImage function, Duh dude oviously you did not look up the commands flags and settings cause calling it a horrible function is just retarded. Using this function makes a new copy evertime you call it thats not a GDI Leak cause your suppose to either delete the object when your done with it or you can set the flags so that when it makes a copy of a resource it deletes the original for you but oh well I guess you dont know that.
If you were determined to use this function setting this flag would only maintain one copy however
it is still recomended you as the programmer delete the object when done with it.
LR_COPYDELETEORG 0x00000008 Deletes the original image after creating the copy.
Now as far as the flashing when drag it arround fast dont get that problem here you must have some sort of sh*tty video card, monitor or computer, however a major flaw is your not handling all the windows messages for instance let the screen save start and then come back having this window in view well you never handle the message and repaint it after the screen saver resulting in it looking all messed up so dude goback to school and learn some more.
In the MyRegisterClass function or any function using a structure if you do not set all the members you must assure the members have valid settings like 0 so to fix the crash on debug mode simply set all the members of any structure you can try the method mentioned
wcex = {0};
thats kinda cheesy way and doesnt assure all members get set the recomended way is
memset(&wcex, 0, sizeof(WNDCLASSEX));
Liquid Snake
modified 6-Dec-11 11:52am.
|
|
|
|
|
Where is you supper better all the correct way version source code?
|
|
|
|
|
I`m trying to make an application wich have a very narrow GUI.
But When trying to size in the borders the title seems to get overlapped by the bitmap filling the title bar. I`m sure the solution is simple but I think the code is very complex and hard to understand so could you help me with a solution?
|
|
|
|
|
hi, this problem was existed when use default system font. the solution is use a right font and draw it into titlebar.
and change the code in function CSkinWindow::OnNcPaint, code like below:
//draw text
if(!WindowText) WindowText = (char*)malloc(sizeof(char)*255);
int len = GetWindowText(m_hWnd, WindowText, 255);
RECT textRect;
textRect.left = 30;
textRect.top = 0;
textRect.right = width - bmpTop.bmWidth + 80 /* - 40*/;
modified on Monday, May 26, 2008 8:48 PM
|
|
|
|
|
|
i use Visual studio 2003 and 2005 to compile it.
|
|
|
|
|
Dear Author,
Thanks for this great job, I just have one question on how to get the built-in scrollbar with the window ??
|
|
|
|
|
I dont working this class with CreateDialog!!! Why???
|
|
|
|
|
Hmm, i'm only test it in a normal window, not in dialog. sorry! i'll test it in future.
|
|
|
|
|
Keep up the good work, Win32 is cool!
|
|
|
|
|
I noticed the lag when resizing, and then I run a profiler to find some clue, the function of CreateRegionFromBitmap used too much cpu time
|
|
|
|
|
U may use UpdateLayeredWindow if the application is only run at NT
|
|
|
|
|
Interesting article! Your code is clean, impressive even, and I enjoyed examining it, but
I had to change “WNDCLASSEX wces;” to “WNDCLASSEX wces = {0};” in order to keep it from crashing, after compiling. Since it is C++ code, instead of C, I would have used “sizeof(HANDLED_MESSAGE)/sizeof(UINT)” instead of MESSAGE_COUNT (one less value to keep track of), but to each their own.
I could not recreate the problem you mentioned, but you could try invalidating the previous rectangle and calling ‘UpdateWindow’ after, for immediate results. I experimented with a couple of versions of that idea, but since the problem is not occurring on my machine, I saw no change in behavior. I believe it usually happens when the CPU is running at 100% and is handling a higher priority thread, so it may not work.
I wish I had more time to spend studying your work, but that is life.
Keep up the good work.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
maybe this is a problem what low configuration of my computer with integrated display card, 8MB display memory.
my computer's confinguration:
IBM X60 series
CPU: Intel duo 2 processes
Memory: 1GB
display card: integrated, 8MB display memory
|
|
|
|
|
If you create your window with WS_SYSMENU style, there will be many strange behaviors.
Look ahead, all is dark.
|
|
|
|
|
Indeed, you must deal with many other things too, such as menu bar, WS_EX_CONTEXTHELP, WM_SETICON, WM_STYLECHANGING/WM_STYLECHANGED, WM_SETCURSOR, WM_SYSKEY*, etc.
Look ahead, all is dark.
|
|
|
|
|
Even with MFC, I always had trouble getting the menus correctly painted, could you check this using your framework ?
Kochise
In Code we trust !
|
|
|
|
|
I like to see articles like this. It attempts to address a question that many programmers new to programming directly with the Win32 API would wonder about.
Just a few observations:
* At first glance the skinned window looks just like an unskinned window. That’s likely to confuse anyone that runs the code looking for the difference that skinning can make (well it confused me until I looked deeper).
* You have a minor bug in MyRegisterClass. Not all members of the WNDCKASSEX structure are assigned. The fix is trivial, simply replace
WNDCLASSEX wcex; with
WNDCLASSEX wcex = {0};
* While handling messages plays an important part, there is more to skinning than just handling messages.
In regard the Problem/Bugs you mentioned...
I didn’t actually observe the problem you described, although resizing did look a little tardy. An increase in CPU utilisation is normal during a resize, but the code you have here does quite a bit during resizing, which will tend to exaggerate this effect. If you observe the monitor “flashing” during resizing (I didn’t), your code might be doing an InvalidateRect on NULL, which would force a redraw of the desktop.
You have chosen a very ambitious project here. Good luck with it.
|
|
|
|
|
David, you are skilled and very good yo~
|
|
|
|
|