Click here to Skip to main content
15,444,353 members
Articles / Desktop Programming / Win32
Posted 29 Jan 2009

Tagged as


56 bookmarked

Scrollable Dialog in Pure Win32 API

Rate me:
Please Sign up or sign in to vote.
4.66/5 (40 votes)
29 Jan 2009CPOL2 min read
Minimalistic example of scrollable dialog implemented in pure Win32 API


Image 1. Fully opened dialog window.


Image 2. Scrolled dialog window.


A popup dialog window is one of the most common GUI elements in the Windows world. Everybody knows how to create a dialog with DialogBox function call. Also, everybody knows that popup dialogs are neither resizable nor scrollable by default. Unfortunately there is no good example of simple resizable and scrollable dialog box implemented in pure Win32 API without MFC, ATL, WTL, etc. Most of examples require MFC or some other GUI framework. This article demonstrates how to implement scrollable dialog window in pure Win32 API with Windows Platform SDK.


The idea behind scrollable dialog is extremely simple. All that one needs to do in order to get a scrollable dialog is summarized in the following steps:

  1. Specify resizable border for a dialog in resource editor or add WS_THICKFRAME style to dialog template by hand.
  2. Enable scroll bars for a dialog window or add WS_VSCROLL | WS_HSCROLL style(s) to dialog window.
  3. Handle WM_RESIZE, WM_HSCROLL and WM_VSCROLL messages.

Note: The dialog is resizable, however the current sample does not reposition dialog controls according to dialog size. If you need to stretch or shrink dialog contents according to window size, then you will need to do it by yourself.

Using the Code

The sample project for the article is created with Microsoft Visual C++ 2008. However, the code does not use MFC, ATL or any other VC++ specific framework or library. The code can be compiled with any decent C/C++ compiler and requires Windows Platform SDK only.

In order to better organize the source code, the project uses so-called message crackers. Windows message crackers are simple macros defined in WindowsX.h header file, which can be found in PSDK's include directory. Here is the excellent description of Windows message crackers: Message Cracker Wizard for Win32 SDK Developers.

Basically, the algorithm for scrollable dialog is as follows:

  1. In WM_INITDIALOG handler, set initial range (maximum and minimum values) and page size for a scrollbar. Make page size the same as the range, so scrollbars are hidden by default.
  2. In WM_SIZE handler, set new page size for scrollbars, so scrollbars will recalculate thumb size and redraw it accordingly. New page size equals client area width/height. Scroll window client area into a view if necessary.
  3. In WM_HSCROLL and WM_VSCROLL message handlers, scroll window client area by requested amount with ScrollWindow[Ex] call. Update current scrolling position.

The Windows will do the rest.


  • 29th January, 2009: Initial post


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

Written By
Software Developer
Australia Australia
More than ten years of C++ native development, and counting.

Smile | :)

Comments and Discussions

QuestionVote 5 Pin
Schehaider_Aymen19-May-17 7:47
MemberSchehaider_Aymen19-May-17 7:47 
QuestionWhat is the GetScrollInfo function called on lines 110 and 174? Pin
SMD11130-May-14 9:47
MemberSMD11130-May-14 9:47 
GeneralMy vote of 5 Pin
gayantcc19-Apr-13 5:02
Membergayantcc19-Apr-13 5:02 
GeneralRe: My vote of 5 Pin
Alex Blekhman19-Apr-13 12:13
MemberAlex Blekhman19-Apr-13 12:13 
SuggestionA great article Pin
LupinTaiwan10-Apr-13 17:53
MemberLupinTaiwan10-Apr-13 17:53 
GeneralRe: A great article Pin
Alex Blekhman12-Apr-13 14:08
MemberAlex Blekhman12-Apr-13 14:08 
Questionadding scroll bars initially Pin
Mike Dorl31-Jan-12 5:24
MemberMike Dorl31-Jan-12 5:24 
AnswerRe: adding scroll bars initially Pin
Alex Blekhman31-Jan-12 15:57
MemberAlex Blekhman31-Jan-12 15:57 
GeneralRe: adding scroll bars initially Pin
Mike Dorl1-Feb-12 7:39
MemberMike Dorl1-Feb-12 7:39 
Questionmaximize Pin
Mike Dorl30-Jan-12 8:28
MemberMike Dorl30-Jan-12 8:28 
AnswerRe: maximize Pin
Alex Blekhman30-Jan-12 11:24
MemberAlex Blekhman30-Jan-12 11:24 
GeneralRe: maximize Pin
Mike Dorl1-Feb-12 11:51
MemberMike Dorl1-Feb-12 11:51 
Bugstatic variables in SD_ScrollClient() Pin
evgeniy.ukhanov3-Nov-11 14:43
Memberevgeniy.ukhanov3-Nov-11 14:43 
GeneralRe: static variables in SD_ScrollClient() Pin
Alex Blekhman3-Nov-11 16:37
MemberAlex Blekhman3-Nov-11 16:37 
Generalport to WinCE Pin
evgeniy.ukhanov2-Nov-11 14:23
Memberevgeniy.ukhanov2-Nov-11 14:23 
GeneralRe: port to WinCE Pin
Alex Blekhman2-Nov-11 16:09
MemberAlex Blekhman2-Nov-11 16:09 
GeneralMy vote of 5 Pin
ViSlav16-Jul-10 10:45
MemberViSlav16-Jul-10 10:45 
Generalit's useful code to me. thx! Pin
Nice Gom25-May-10 15:02
MemberNice Gom25-May-10 15:02 
GeneralWorks great with win32++ Pin
mayo200022-Jun-09 3:50
Membermayo200022-Jun-09 3:50 
GeneralRe: Works great with win32++ Pin
Alex Blekhman22-Jun-09 3:58
MemberAlex Blekhman22-Jun-09 3:58 
Generalthere is a bug ... if I resize the dialog smaller and then maximize it, i can only see the same section like bevore, not the complete dialog... Pin
m.moestl28-May-09 5:22
Memberm.moestl28-May-09 5:22 
please help, I don't know how to fix it...

but cool work ! thanks.
GeneralRe: there is a bug ... if I resize the dialog smaller and then maximize it, i can only see the same section like bevore, not the complete dialog... Pin
Alex Blekhman28-May-09 6:56
MemberAlex Blekhman28-May-09 6:56 
GeneralMy vote of 1 Pin
raspopov2-Feb-09 16:55
Memberraspopov2-Feb-09 16:55 
GeneralRe: My vote of 1 Pin
maplewang17-Feb-09 16:11
Membermaplewang17-Feb-09 16:11 
General.h file Pin
MayIsONe1-Feb-09 3:30
MemberMayIsONe1-Feb-09 3:30 

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.