c - Getting character attributes -


using winapi attribute of character located in y line , x column of screen console. trying after call getconsolescreenbufferinfo(getstdhandle(std_output_handle), &nativedata); console cursor set specified location. won't work. return last used attribute change instead.

how obtain attributes used on characters on locations?


edit: code used test readconsoleoutput() : http://hastebin.com/atohetisin.pl throws garbage values.

i see several problems off top of head:

  • no error checking. must check return value readconsoleoutput , other functions, documented. if function fails, must call getlasterror() error code. if don't check errors, you're flying blind.

  • you don't allocate buffer receive data in. (granted, documentation confusingly implies allocates buffer you, that's wrong since there's no way return pointer it. also, sample code shows have allocate buffer yourself. i've added note.)

  • it looks if had intended read characters had written, writing (10,5) , reading (0,0).

  • you're passing newpos, set (10,5), dwbuffercoord when call readconsoleoutput, specified buffer size of (2,1). doesn't make sense target coordinates outside buffer.

taking last 2 points think perhaps have dwbuffercoord , lpreadregion confused, though i'm not sure meant coordinates (200,50) do.

  • you're interpreting char_info integer in final printf statement. first element of char_info character itself, not attribute. wanted chibuffer[0].attributes rather chibuffer[0]. (of course, moot @ moment, since chibuffer points random memory address.)

if want retrieve character, you'll first need work out whether console in unicode or ascii mode, , retrieve unicodechar or asciichar accordingly.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -