Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 10th, 2003, 01:23 PM
Authorized User
 
Join Date: Jun 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default gotoxy() in visual C++ 1.5

I am writing a DOS program that needs the gotoxy() function. Borland C++ has it in conio.h but VC++ does not have it. Since this is someone else's code, I can't change compiler.

Does someone have code sample to implement a gotoxy() function for cursor positioning?

Thanks
Carl
Reply With Quote
  #2 (permalink)  
Old June 21st, 2003, 11:44 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Ammiel Send a message via AIM to Ammiel Send a message via MSN to Ammiel
Default

Cursor positioning in text mode?

I believe you'll need to do some assembly work... plus Borland has an inline assembler.... I have a clue on how to do it in NASM, but not with C++ and inline ASM... sorry
Reply With Quote
  #3 (permalink)  
Old June 23rd, 2003, 07:21 AM
Registered User
 
Join Date: Jun 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It's very simple to build a function like gotoxy() using a software interruption. The following code do this and it works fine in any compile running on DOS (like Turbo C and Visual C)

#include <stdio.h>
#include <conio.h>
#include <dos.h>

void gotoxy (int x, int y)
{ union REGS regs;
  regs.h.ah = 2; /* cursor position */
  regs.h.dh = y;
  regs.h.dl = x;
  regs.h.bh = 0; /* vídeo page #0 */
  int86(0x10, &regs, &regs);
}

int main (void)
{ clrscr();
   movetoxy(35,10);
   printf("Hello\n");
   return 0;
}



Willians Santos
Software Engineer
Brazil
Reply With Quote
  #4 (permalink)  
Old July 15th, 2003, 12:36 AM
Registered User
 
Join Date: Jul 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to pselva
Default

#include <windows.h>

void gotoxy(int xpos, int ypos)
{
  COORD scrn;

  HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);

  scrn.X = xpos; scrn.Y = ypos;

  SetConsoleCursorPosition(hOuput,scrn);
}


Reply With Quote
  #5 (permalink)  
Old September 8th, 2004, 08:48 PM
Registered User
 
Join Date: Sep 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey guys... I tried the gotoxy(x, y) code you put out there and it doesnt work. I have Microsoft Visual Studio .NET 2003 (Just in case that helps) and I am trying to make a program using gotoxy.

Thanx in advance for any new code.
Blaze!



Reply With Quote
  #6 (permalink)  
Old March 22nd, 2006, 01:40 PM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Parabéns pela sua definição. Foi a mais objetiva e funcional que encontrei! Funcionou perfeitamente com o VC++ 6.0. Muitíssimo obrigado!!

Quote:
quote:Originally posted by pselva
 #include <windows.h>

void gotoxy(int xpos, int ypos)
{
COORD scrn;

HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);

scrn.X = xpos; scrn.Y = ypos;

SetConsoleCursorPosition(hOuput,scrn);
}


Reply With Quote
  #7 (permalink)  
Old March 22nd, 2006, 01:47 PM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Parabéns pela sua definição. Foi a mais objetiva e funcional entre as que eu encontrei. Funcionou perfeitamente com o VC++ 6.0. Muitíssimo obrigado!

Quote:
quote:Originally posted by pselva
 #include <windows.h>

void gotoxy(int xpos, int ypos)
{
COORD scrn;

HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);

scrn.X = xpos; scrn.Y = ypos;

SetConsoleCursorPosition(hOuput,scrn);
}


Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Studio VS. Visual Web Developer expr Astrocloud BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 2 November 23rd, 2008 03:10 PM
diffrece between Visual C# & Visual C++ vinu123 C# 2005 3 December 18th, 2006 08:07 AM
FTP in Visual Studio 2005 Pro (Visual Basic) shoopes VB How-To 1 June 29th, 2006 02:08 PM
Crystal Reports in Visual St 2002 vs Visual St2003 Tatanka Crystal Reports 0 August 23rd, 2004 10:23 AM
How do I use Visual studio for Visual C++ kevin777 Visual C++ 1 October 24th, 2003 09:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.