2 Replies - 3645 Views - Last Post: 15 August 2011 - 09:52 PM Rate Topic: -----

#1 muffinman8641   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 121
  • Joined: 17-March 11

C++ DOS Window Highlighting/Arrow Key Navigation?

Posted 15 August 2011 - 07:52 PM

To date, the only way I made C++ menus and such is by listing the options and saying "Enter the number of your selection". This sucks.

I see in Windows boot screens and such where you can use the arrow keys to move highlighting to an option and hit enter. Is this hard to do?
Is This A Good Question/Topic? 0
  • +

Replies To: C++ DOS Window Highlighting/Arrow Key Navigation?

#2 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6643
  • View blog
  • Posts: 30,932
  • Joined: 10-May 07

Re: C++ DOS Window Highlighting/Arrow Key Navigation?

Posted 15 August 2011 - 07:56 PM

To accomplish this, you need to read in the arrow keys input value, change the background color to the output, & rewrite each space that 'high-lights' the users option as well as the previous 'high-lighted' option to the regular color.

I wouldn't say that it's difficult, but it's not practical since Microsoft has released GUI based operating systems since the mid nineties, nearly 20 years ago.
Was This Post Helpful? 0
  • +
  • -

#3 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: C++ DOS Window Highlighting/Arrow Key Navigation?

Posted 15 August 2011 - 09:52 PM

assuming the windows platform here:

Well to change the output colors and to print to specific places on the screen might I humbly suggest you utilize some of my snippets:

Windows Console Output several functions including:
ConPrintAt - lets you print to a certain x-y location
gotoXY -- also lets you print at a certian location but works with cout if you need.
ClearConsole -- clears the console
ClearConsoleToColors -- clears the console to a given forground and background color
SetColorAndBackground -- sets the colors for subsequent outputs.
SetColor -- sets just the forground color (you can also use this as a template to make a new function that only sets the background...)

Windows Console Formated Print -- a fancy printf kind of function that lets you print to a given x-y

Windows Console Get/Set Colors -- more fancy color functions for getting and setting colors.

Centered Printf -- does what it says. it centers the text.

Once you get a feel for how those work you can move on to other members of the console API:

Console API on MSDN

Particularly to make a function that hilights text like you might have on a menu you want to use: WriteConsoleOutputAttribute which will let you edit the color without affecting the text.

the GetAsyncKeyState Function usually works pretty good with the keyboard although you might actually look into just getting a message loop running and working with the console input functions.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1