Click here to Skip to main content
15,881,248 members
Articles / Multimedia / GDI
Article

Color gradient in fullscreen window

Rate me:
Please Sign up or sign in to vote.
1.26/5 (10 votes)
15 Nov 20052 min read 42.4K   1K   16   5
Creates a full screen window and shows a color gradient on it
Download source files - 22.4 Kb
Download demo project - 69.2 Kb

Gradient

Introduction

This program displays a color gradient in a full screen window. Uses win32 visual c++ style of programming. I have also covered compilation using Visual C++ 6 and Borland free C++ compiler 5.5 in this article.

Background

I am new to windows programming and wanted to learn how to use graphics in a full screen window - this program is a result.

Working

Calls GetSystemMetrics() with argument SM_CXSCREEN for getting maximum x co-ordinate and with argument SM_CYSCREEN for getting maximum y co-ordinate and uses them to give window size to CreateWindowEx(). WS_POPUP window style is used because it does not have a title bar with maximize and other buttons – it is ideal for our purpose.

In the message processing routine, MainWndProc(), only WM_PAINT and WM_DESTROY messages are processed. In the WM_PAINT message handler, BeginPaint() is used to get the HDC and CreatePen() is used to set drawing color. MoveToEx() and LineTo() are used to move to position in window and draw a line respectively. The pens are destroyed after use to free memory using DeleteObject(). Finally, EndPaint() does the cleaning up. A code fragment is included below.

case WM_PAINT:
   mx=GetSystemMetrics(SM_CXSCREEN);
   my=GetSystemMetrics(SM_CYSCREEN);
   mx--;my--;
   h1 = BeginPaint(hwnd, &ps);
   for(i=63,rev=0;i>=0;i--,rev++)
     hpa[rev]=CreatePen( PS_SOLID, 1, RGB(0,i*4,0));
   for(i=0;i<=my;i++)
    {
      in=i*63/(my+1);
      SelectObject(h1, hpa[in]);
      MoveToEx(h1,0,i,NULL);
      LineTo(h1,mx,i);
      LineTo(h1,mx-1,i);
    }
   for(i=0;i<=63;i++)
     DeleteObject(hpa[i]);
   EndPaint(hwnd, &ps);
   return TRUE;

Compiling

Visual C++ 6:

   · Start Visual C++ 6

   · Access New option from File menu

   · Select “Win32 Application”

   · Give a project name

   · Click OK button

   · Select “An empty project” in the new window

   · Click Finish button

   · Click OK button in new window

   · Select “Project” menu, “Add To Project”, ”Files”

   · Select source file(gradr.c) in the dialog box

   · Select “Build” menu, “Build <proj name>.exe”

   · Executable will be in project folder in subdirectory
     Debug or Release depending on settings in IDE.

Borland free C++ Compiler 5.5:

   · Get freecommandLinetools.exe from
      http://www.borland.com/bcppbuilder/freecompiler/

   · Run it and extract to the default folder

   · Copy the three .cfg files in the source zip file provided in this
      page to the C:\Borland\BCC55\Bin directory

   · Copy the mkexe.bat file in the source zip file to the folder
      containing the gradr.c source file

   · Run the mkexe.bat file

   · The executable will be in the same folder

Running

Start the executable. Because the program does little other than showing the color gradient, all you can do is press Alt and F4 key combination to close the window.

Feedback

Please feel free to give any feedback.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionFullscreen app Pin
Sir.Costy9-Jan-07 1:39
Sir.Costy9-Jan-07 1:39 
AnswerRe: Fullscreen app Pin
jithinpg26-Aug-09 19:20
jithinpg26-Aug-09 19:20 
GeneralRe: Fullscreen app Pin
Emmanuel Arun Vinod18-Jul-10 20:17
Emmanuel Arun Vinod18-Jul-10 20:17 
GeneralA voice of warning Pin
NGS 54967215-Nov-05 5:46
NGS 54967215-Nov-05 5:46 
GeneralRe: A voice of warning Pin
Mauro Leggieri15-Nov-05 12:48
Mauro Leggieri15-Nov-05 12:48 

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.