如何在MASM中获取当前光标位置 [英] how to get current cursor position in MASM
问题描述
我正在编写一个IQ测试生成程序,在该程序中,我必须随机生成包含口头非口头问题的问题.为了产生非语言问题,我想显示字母和字母以圆形或三角形出现的问题.
I am writing an IQ test generation program in which i have to randomly generate questions that will include verbal non verbal questions. For generating non verbal questions i want to display questions in which alphabets and letters will appear in circular or triangular shape.
但是我不确定如何放置它们.例如,在一个非语言问题中,我想通过编写以下代码将字母和数字定位为三角形:
But i am not sure how to position them. E.g in a non verbal question i want to position alphabets and numbers in triangular shape by writing this code:
mov al, alpha
call writechar
add dl, 4
call gotoxy
mov al, num
call writedec
sub dl, 2
add dh, 1
call gotoxy
mov al, alpha
call writechar
这是我已经知道的
dh =行
dl =列
致电gotoxy
Gotoxy将光标相对于控制台的起始位置而不是相对于当前位置定位.这就是我要解决的问题.
Gotoxy positions cursor relative to starting position of console, not relative to current position.This is the problem that i'm getting.
我认为应该有一种获取当前光标位置的方法,这样我就可以通过在 dh 和 dl 的当前值之间加减来来回定位光标连续生成形状.
I assume there should be a way of getting current cursors position so that i can position cursor back and forth by adding and subtracting from current value of dh and dl while generating shapes in series.
推荐答案
您可以在线获取Irvine32帮助: GetConsoleScreenBufferInfo .不幸的是,结构 CONSOLE_SCREEN_BUFFER_INFO
的描述不正确.适当的COORD结构的名称为 dwCursorPosition
.
You can get the Irvine32 help online: http://programming.msjc.edu/asm/help/. There is a WinAPI function specified for getting the cursor position: GetConsoleScreenBufferInfo. Unfortunately the description of the structure CONSOLE_SCREEN_BUFFER_INFO
is not correct. The name of the appropriate COORD structure is dwCursorPosition
.
以下是使用方法的示例:
Here's an example how to use it:
INCLUDE Irvine32.inc
INCLUDELIB Irvine32.lib
.DATA
txt1 db "Current Cursor Position is X=",0
txt2 db " Y=",0
BufferInfo CONSOLE_SCREEN_BUFFER_INFO <>
.CODE
main PROC
lea edx, txt1
call WriteString
invoke GetStdHandle, STD_OUTPUT_HANDLE
invoke GetConsoleScreenBufferInfo, eax, ADDR BufferInfo
movzx eax, BufferInfo.dwCursorPosition.X
call WriteInt
lea edx, txt2
call WriteString
movzx eax, BufferInfo.dwCursorPosition.Y
call WriteInt
exit
main ENDP
END main
这篇关于如何在MASM中获取当前光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!