Click here to Skip to main content
Licence 
First Posted 15 Nov 2005
Views 29,915
Bookmarked 15 times

Color gradient in fullscreen window

By | 15 Nov 2005 | Article
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

About the Author

Emmanuel Arun Vinod

Web Developer

India India

Member



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

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionFullscreen app PinmemberSir.Costy1:39 9 Jan '07  
AnswerRe: Fullscreen app PinmemberMember 436520919:20 26 Aug '09  
GeneralRe: Fullscreen app PinmemberEmmanuel Arun Vinod20:17 18 Jul '10  
GeneralA voice of warning PinmemberNGS 5496725:46 15 Nov '05  
GeneralRe: A voice of warning PinmemberMauro Leggieri12:48 15 Nov '05  

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

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 15 Nov 2005
Article Copyright 2005 by Emmanuel Arun Vinod
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid