webForumDet fria alternativet

Visual C++ och gotoxy()...

1 svar · 413 visningar · startad av Engine^

Engine^Medlem sedan dec. 20003 887 inlägg
#1

Vet nån hur man kan använda sig utav conio.h:s gotoxy()-funktioner för att placera text i en dos-applikation? Det fungerar bra i Borland, men inte i Visual och det är Visual jag helst använder.

nielsMedlem sedan juli 2000212 inlägg
#2

Använd dig av följande följande header fil:

<font size="1" face="Verdana, Arial, Helvetica, sans-serif">Kod:<font size="1" face="Verdana, Arial, Helvetica, sans-serif" color="#666600">
#ifndef CONSOL_H
#define CONSOL_H

#include <windows.h>

#define SCROLL_POS 24

void Init_Consol(void);
inline void Set_Color(int fcolor, int bcolor);
inline void DrawString(int x, int y, char* string);
inline void Clear_Screen(void);

CONSOLE_SCREEN_BUFFER_INFO con_info;
HANDLE hconsole;

void Init_Graphics(void)
{
COORD console_size = {80,25};
srand((unsigned)time(NULL));
hconsole=CreateFile("CONOUT$",GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0L, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0L);
SetConsoleScreenBufferSize(hconsole,console_size);
GetConsoleScreenBufferInfo(hconsole,&con_info);
}

inline void Set_Color(int fcolor, int bcolor=0)
{
SetConsoleTextAttribute(hconsole,(WORD)((bcolor << 4) | fcolor));
}

inline void Draw_String(int x, int y, char* string)
{
COORD cursor_pos;
cursor_pos.X = x;
cursor_pos.Y = y;
SetConsoleCursorPosition(hconsole,cursor_pos);
printf("%s",string);
}

inline void Clear_Screen(void)
{
Set_Color(15,0);
for(int index=0; index<=25; index++)
{
Draw_String(0, SCROLL_POS, "\n");
}
}

#endif

Innehåller functioner som man kan använda vid utveckling av consol program.

/Nisse

------------------
www.phpfunctions.com

124 ms totalt · 3 externa anrop · v20260731065814-full.0e50b1ef
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
121 ms — hämta tråd, inlägg och bilagor (db)