如何将光标定位在屏幕上? [英] how to position the cursor on the screen?

查看:177
本文介绍了如何将光标定位在屏幕上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程方面的新手,目前正在学习C中的数组。我正在制作一个拼图,其中包含15个编号方块,安装在一个框架上,一个是空的。它允许用户点击任何箭头键(向上,向下,向左,向右)。用户将继续按箭头键,直到数字没有按升序排列。这些部分可以水平和垂直移动。
我的问题是我不知道如何定位光标。我知道库函数 gotoxy()但我认为它在Turbo C / C ++中使用。我正在使用Code Blocks.I在Google上搜索了这个但是无法得到结果。是的,我正在谈论键盘光标并使用窗口OS.Please help! :)

I'm new in programming and currently learning about arrays in C. I'm making a puzzle that contains 15 numbered square pieces mounted on a frame and one piece is empty.It allow the user to hit any of the arrow keys(up,down,left,right).The user will continue hitting the arrow keys till the numbers aren't arranged in ascending order.These pieces can be move horizontally and vertically. My problem is that i don't know how to position the cursor.I know a library function gotoxy() but i think it was used in Turbo C/C++.I'm using Code Blocks.I searched this on Google but couldn't get the result.And yes i'm talking about the keyboard cursor and using window OS.Please help! :)

推荐答案

在过去,MS / DOS使用特殊的驱动程序ANSI.SYS来模拟ANSI命令代码。看起来这个好的旧驱动程序在Windows XP下可以使用(但你需要在config.sys中配置它),但我发现一些文章说它不再适用于Windows 7及更高版本。

In the old days, MS/DOS used a special driver ANSI.SYS to emulate ANSI command codes. It looks like this good old driver is usable under Windows XP (but you need do configure it in config.sys), but I found some articles saying it no longer works on Windows 7 and above.

所以ANSI(或vt100或vt220)代码在Linux或Unix终端中很有用,但在Windows下,我的建议是直接使用Wincon.h中声明的Windows API控制台函数 - 但是你应该总是包括使用Windows API函数时的Windows.h。

So ANSI (or vt100 or vt220) codes are useful in Linux or Unix terminals, but under Windows, my advice would be to directly use the Windows API Console functions declared in Wincon.h - but you should alway include Windows.h when using Windows API functions.

您需要使用Windows SDK作为参考,但这是一个小程序编写 foo_bar 位置15,5:

You will need to use the Windows SDK as a reference, but here is a small program writing foo_bar in position 15,5 :

#include <windows.h>
#include <tchar.h> // compatibility 8/16 bits characters

int _tmain(int argc, const LPSTR *argv) {
    HANDLE hStdOut = ::GetStdHandle(STD_OUTPUT_HANDLE); // console output handle
    COORD dwCursorPosition;
    DWORD nb;
    dwCursorPosition.X = 15;
    dwCursorPosition.Y = 5;
    ::WriteConsoleOutputCharacter(hStdOut, _T("foo_bar"), 7, dwCursorPosition, &nb);

    return 0;
}

参考文献:控制台参考

这篇关于如何将光标定位在屏幕上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆