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

Desktop Puzzle Game

, 12 Sep 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
A Desktop puzzle game.


This is a known but a different puzzle game. The images of puzzles are not included; in fact, the images are captured from your desktop! First of all, you can select the game difficulty: easy, medium, hard, and by pressing the Start button, the game will begin after the number of seconds you have specified (default is 2 seconds).

Game instructions

  • to move a rectangle, select the first and then a second one by clicking on the rectangles.
  • to rotate a rectangle by 180 degrees, right click on the rectangle.
  • to reveal the borders of each slice, you can click the middle button of the mouse.

Sample Image - Desktop_Puzzle_Game.jpg

Here are the main methods:

// - Saves the bitmap of display DC to a memory DC
void        CaptureDesktop();

// - Replaces two rects in memory device context
void        ReplaceRects(CRect rectSource, CRect rectDest);

// - Inverts selected rect
void        InvertRect(CRect rect);

// - Draws a frame around a rectangle
void        FrameRect(CRect rect, BOOL bClear=FALSE);

// - Draws a frame around all rectangles
void        DrawFrames();

// - Checks if user has been corrected all rectangles
int        CheckForWin();

// - Returns rect of selected square
CRect        GetSquareFromPoint(CPoint point);

// - Select a rectangle (source) or Replace first selected rectangle (source) 
//   with new selected rectangle (destination)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);

// - Draw all frames for help or clear them all
afx_msg void OnMButtonDown(UINT nFlags, CPoint point);

// - Invert selected rectangle
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);

// - Checks for number of wrong items
afx_msg void OnExit();

// - Draws wrong items
afx_msg void OnTimer(UINT nIDEvent);

This is not a new game, just an attempt to help others on how to write such programs and may be find some techniques from this. Any suggestions and refinements are welcome. Enjoy the game!


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


About the Author

Hadi Dayvary
Software Developer
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
Hadi Dayvary graduated from Azad University in spring 2003 in Apply Mathematics.
Started Visual C++ in 1999.
He likes to program all the time.
He lives in Iran.
Follow on   Google+

Comments and Discussions

Generalnice one i like it Pinmemberzzx_12345625-Jun-09 0:13 
Generalsend project Pinmemberfarzaneh13651-May-08 1:06 
GeneralRe: send project PinmemberH adi Dayvary2-May-08 19:50 
Generalnice Pinmemberbhage15-Sep-06 20:22 
GeneralNice Idea Pinmembernorm .net12-Sep-06 5:54 
GeneralGood idea & some suggestion. Pinmemberjcem16-Jul-06 23:04 
GeneralA great idea, and some challenges ahead... PinmemberJun Du31-May-06 4:14 
GeneralRe: A great idea, and some challenges ahead... PinmemberHadi Dayvary31-May-06 22:10 
GeneralRe: A great idea, and some challenges ahead... PinmemberJun Du1-Jun-06 14:20 
GeneralGreat Article PinmemberSBaghestani31-May-06 1:17 
GeneralRe: Rubbish Article but interesting project PinmemberMichael P Butler16-Jul-06 0:07 
GeneralI like it Pinmemberqiuqianren31-May-06 0:45 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141220.1 | Last Updated 12 Sep 2006
Article Copyright 2006 by Hadi Dayvary
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid