Click here to Skip to main content
Click here to Skip to main content

Draw Skin Window Using Pure Win32 API

By , 14 Sep 2007
 
Screenshot - drawwindow1.gif

Introduction

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.

Contents

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:

Message Description
WM_NCPAINT The message is sent to a window when its frame must be painted. We should paint the window here.
WM_NCCALCSIZE The 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_NCACTIVATE The message is sent to a window when its non-client area needs to be changed to indicate an active or inactive state.
WM_NCHITTEST The 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.
WM_NCLBUTTONUP<br />WM_NCLBUTTONDOWN<br />WM_NCLBUTTONDBLCLK<br />WM_NCRBUTTONUP<br />WM_NCRBUTTONDOWN<br />WM_NCMOUSEMOVE 
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_GETMINMAXINFO The 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_ACTIVATE The 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.

Function Description
OnNcPaint Process message WM_NCPAINT
OnNcActive Process message WM_NCACTIVATE
OnNcCalcSize Process message WM_NCCALCSIZE
OnNcHitTest Process message WM_NCHITTEST
OnNcLButtonUp Process message WM_NCLBUTTONUP
OnNcLButtonDown Process message WM_NCLBUTTONDOWN
OnNcLButtonDblClk Process message WM_NCLBUTTONDBLCLK
OnNcMouseMove Process message WM_NCMOUSEMOVE
OnNcRButtonUp Process message WM_NCRBUTTONUP
OnNcRButtonDown Process message WM_NCRBUTTONDOWN
OnSize Process message WM_SIZE
OnSizing Process message WM_SIZING
OnActive Process message WM_ACTIVE
OnWindowPosChanging Process message WM_WINDOWPOSCHANGING
OnGetMinMaxInfo Process message WM_GETMINMAXINFO
OnSetText Process message WM_SETTEXT
OnSysCommand Process message WM_SYSCOMMAND

Example

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

#include "skinwindow.h"

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 );

Problems/Bugs

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.

History

  • 14 September, 2007 -- Original version posted

License

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

About the Author

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionWow, Was a nice try. [modified]memberxox_c0bra_xox6 Dec '11 - 5:16 
QuestionProblem with title barmemberMember 445058125 May '08 - 9:33 
AnswerRe: Problem with title bar [modified]memberjacky_zz26 May '08 - 14:38 
Questioni want to ask,what developtool r u do u use?membermacroideal29 Apr '08 - 15:28 
AnswerRe: i want to ask,what developtool r u do u use?memberjacky_zz29 Apr '08 - 21:15 
GeneralScrollBarmembersalah_nrg9 Apr '08 - 18:14 
GeneralVery good, but.....membermarkin.alves29 Nov '07 - 6:30 
GeneralRe: Very good, but.....memberjacky_zz1 Dec '07 - 14:46 
Generalgood workmemberbraindamage1029 Oct '07 - 7:47 
GeneralI noticed the lag when resizing,membercode_discuss18 Oct '07 - 22:30 
GeneralRe: I noticed the lag when resizing,memberconan.ks29 Oct '07 - 4:19 
GeneralImpressive evenmemberJohn R. Shaw20 Sep '07 - 19:23 
GeneralRe: Impressive evenmemberjacky_zz22 Sep '07 - 18:40 
QuestionWhat about WS_SYSMENU style?memberDandy Cheung17 Sep '07 - 3:54 
AnswerRe: What about WS_SYSMENU style?memberDandy Cheung17 Sep '07 - 4:02 
QuestionCould you check the menu painting ?memberKochise14 Sep '07 - 21:13 
GeneralInterestingmemberDavid Nash14 Sep '07 - 18:17 
GeneralRe: Interestingmemberyctsai1 Nov '07 - 21:31 

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 14 Sep 2007
Article Copyright 2007 by jacky_zz
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid