Click here to Skip to main content
12,505,592 members (54,059 online)
Click here to Skip to main content
Add your own
alternative version


105 bookmarked

Draw Skin Window Using Pure Win32 API

, 14 Sep 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
An article to show how to draw a skin window
Screenshot - drawwindow1.gif


How can you make an application's own skin window without MFC extension UI libraries like BGCControlBar, Xtreme Toolkit and so on? This article uses pure Win32 API to find the answer.


Windows Messages

For the beginner, I want to explain the window messages that should be processed. Anybody who wants to draw a window should process the window messages as below:

WM_NCPAINTThe message is sent to a window when its frame must be painted. We should paint the window here.
WM_NCCALCSIZEThe message is sent when the size and position of a window's client area must be calculated. By processing this message, an application can control the content of the window's client area when the size or position of the window changes.
WM_NCACTIVATEThe message is sent to a window when its non-client area needs to be changed to indicate an active or inactive state.
WM_NCHITTESTThe message is sent to a window when the cursor moves or when a mouse button is pressed or released. If the mouse is not captured, the message is sent to the window beneath the cursor. Otherwise, the message is sent to the window that has captured the mouse.
The message is posted when the user releases the left mouse button while the cursor is within the non-client area of the window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted.
WM_GETMINMAXINFOThe message is sent to a window when the size or position of the window is about to change. An application can use this message to override the window's default maximized size and position, or its default minimum or maximum tracking size.
WM_ACTIVATEThe message is sent to both the window being activated and the window being deactivated. If the windows use the same input queue, the message is sent synchronously. First it is sent to the window procedure of the top-level window being deactivated and then it is sent to the window procedure of the top-level window being activated. If the windows use different input queues, the message is sent asynchronously, so the window is activated immediately.

Class SkinWindow

We should create a class named SkinWindow that takes responsibility for painting the window. The class SkinWindow defines some functions to process the special window's message.

OnNcPaintProcess message WM_NCPAINT
OnNcActiveProcess message WM_NCACTIVATE
OnNcCalcSizeProcess message WM_NCCALCSIZE
OnNcHitTestProcess message WM_NCHITTEST
OnNcLButtonUpProcess message WM_NCLBUTTONUP
OnNcLButtonDownProcess message WM_NCLBUTTONDOWN
OnNcLButtonDblClkProcess message WM_NCLBUTTONDBLCLK
OnNcMouseMoveProcess message WM_NCMOUSEMOVE
OnNcRButtonUpProcess message WM_NCRBUTTONUP
OnNcRButtonDownProcess message WM_NCRBUTTONDOWN
OnSizeProcess message WM_SIZE
OnSizingProcess message WM_SIZING
OnActiveProcess message WM_ACTIVE
OnWindowPosChangingProcess message WM_WINDOWPOSCHANGING
OnGetMinMaxInfoProcess message WM_GETMINMAXINFO
OnSetTextProcess message WM_SETTEXT
OnSysCommandProcess message WM_SYSCOMMAND


Firstly, we create a new Win32 application that includes SkinWindow in its project.

#include <span class="code-string">"skinwindow.h"</span>

Secondly, we should define a global variant in the main CPP file.

CSkinWindow SkinWin;

Thirdly, we load the skin from resource at the function InitInstance.

SkinWin.Load(hInstance, hWnd);

Last, we should add some code in the function WndProc to process the special window's messages.

// handle some special window's message here
if( SkinWin.IsHandledMessage( message ) )
    return SkinWin.WndProc( hWnd, message, wParam, lParam );


When you size or drag and move a window as fast as you can, the monitor will flash and the window will take up more CPU percent. I've tried many approaches, but the problem persists. Is there anyone who can resolve it? The problem's picture is like below.

Screenshot - drawwindow2.gif

Additional Notes

This is by no means a finished product! This is my first attempt at writing a terribly complicated Win32 application library. I want to tell a beginner how to skin a window using pure Win32 API without MFC and give the beginner some hints to comprehensive window messages. I wanted something similar to SkinWindow in functionality, but without the overhead of MFC. There will be bugs and errors! I hope that you find this code useful. If you have any improvements/suggestions, comments/flames or questions please post them here.


  • 14 September, 2007 -- Original version posted


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


About the Author

Software Developer none
China China
To be, or not to be, this is question. That's are all depend on your decision. What do you think?

You may also be interested in...


Comments and Discussions

QuestionThanks! The one working and simple example Pin
KevinSW19-Mar-14 16:58
memberKevinSW19-Mar-14 16:58 
AnswerRe: Thanks! The one working and simple example Pin
jacky_zz20-Mar-14 20:40
memberjacky_zz20-Mar-14 20:40 
AnswerRe: Thanks! The one working and simple example Pin
jacky_zz20-Mar-14 20:45
memberjacky_zz20-Mar-14 20:45 
GeneralRe: Thanks! The one working and simple example Pin
KevinSW13-Jul-14 18:14
memberKevinSW13-Jul-14 18:14 
QuestionWow, Was a nice try. Pin
xox_c0bra_xox6-Dec-11 5:16
memberxox_c0bra_xox6-Dec-11 5:16 

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.

AnswerRe: Wow, Was a nice try. Pin
KevinSW19-Mar-14 15:55
memberKevinSW19-Mar-14 15:55 
QuestionProblem with title bar Pin
Member 445058125-May-08 9:33
memberMember 445058125-May-08 9:33 
AnswerRe: Problem with title bar [modified] Pin
jacky_zz26-May-08 14:38
memberjacky_zz26-May-08 14:38 
Questioni want to ask,what developtool r u do u use? Pin
macroideal29-Apr-08 15:28
membermacroideal29-Apr-08 15:28 
AnswerRe: i want to ask,what developtool r u do u use? Pin
jacky_zz29-Apr-08 21:15
memberjacky_zz29-Apr-08 21:15 
GeneralScrollBar Pin
salah_nrg9-Apr-08 18:14
membersalah_nrg9-Apr-08 18:14 
GeneralVery good, but..... Pin
markin.alves29-Nov-07 6:30
membermarkin.alves29-Nov-07 6:30 
GeneralRe: Very good, but..... Pin
jacky_zz1-Dec-07 14:46
memberjacky_zz1-Dec-07 14:46 
Generalgood work Pin
braindamage1029-Oct-07 7:47
memberbraindamage1029-Oct-07 7:47 
GeneralI noticed the lag when resizing, Pin
code_discuss18-Oct-07 22:30
membercode_discuss18-Oct-07 22:30 
GeneralRe: I noticed the lag when resizing, Pin
conan.ks29-Oct-07 4:19
memberconan.ks29-Oct-07 4:19 
GeneralImpressive even Pin
John R. Shaw20-Sep-07 19:23
memberJohn R. Shaw20-Sep-07 19:23 
GeneralRe: Impressive even Pin
jacky_zz22-Sep-07 18:40
memberjacky_zz22-Sep-07 18:40 
QuestionWhat about WS_SYSMENU style? Pin
Dandy Cheung17-Sep-07 3:54
memberDandy Cheung17-Sep-07 3:54 
AnswerRe: What about WS_SYSMENU style? Pin
Dandy Cheung17-Sep-07 4:02
memberDandy Cheung17-Sep-07 4:02 
QuestionCould you check the menu painting ? Pin
Kochise14-Sep-07 21:13
memberKochise14-Sep-07 21:13 
GeneralInteresting Pin
David Nash14-Sep-07 18:17
memberDavid Nash14-Sep-07 18:17 
GeneralRe: Interesting Pin
yctsai1-Nov-07 21:31
memberyctsai1-Nov-07 21:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160927.1 | Last Updated 14 Sep 2007
Article Copyright 2007 by jackyxinli
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid