Tabbas. Ga hanyar da za mu bi ta wannan:
A matsayinka na mai haɓakawa, sau da yawa za ka iya fuskantar yanayi inda kake buƙatar tsara mu'amalar mai amfani da hoto. Ɗayan irin wannan yanayin zai iya haɗawa da ɓoye siginan kwamfuta. Duk da yake yana iya zama kamar mai ban tsoro, kada ku damu. C++ yana ba da hanya mai sauƙi don cimma wannan.
Ta amfani da takamaiman aikin API na Windows, za mu iya sarrafa siginan kwamfuta cikin sauƙi. A cikin Windows, ana iya jujjuya ganin siginan kwamfuta ta amfani da aikin `ShowConsoleCursor()`, wanda aka ayyana a cikin fayil ɗin taken windows.h. Bari mu ga mafita daki-daki.
#include
Void ShowConsoleCursor (bool showFlag){
HANDLE fita = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO bayanin siginan kwamfuta;
GetConsoleCursorInfo(fita, &cursorInfo);
cursorInfo.bVisible = showFlag;
SetConsoleCursorInfo(fita, &CursorInfo);
}
A cikin aikin 'ShowConsoleCursor', mun wuce ƙimar Boolean da ke wakiltar yanayin ganin siginan kwamfuta. 'gaskiya' na nuna ganuwa, 'ƙarya' na nuna ya kamata a ɓoye.
Game da Windows.h Header
- Fayil ɗin Windows.h takamaiman fayil ne na Windows don harsunan shirye-shiryen C da C++ waɗanda ke ƙunshe da sanarwar duk ayyukan da ke cikin Windows API.
- Ya zama dole a haɗa ɗakin karatu na windows.h don samun dama ga ayyuka da yawa da suka haɗa da sarrafa kayan wasan bidiyo.
Aikin GetStdHandle
SamunStdHandle aikin Windows API ne da ake amfani da shi don dawo da hannu zuwa ƙayyadaddun na'urar da aka ƙayyade (shigar da daidaitattun bayanai, daidaitaccen fitarwa, ko daidaitaccen kuskure). Yana maido da hannu zuwa madaidaicin allo mai aiki, yana ba mu damar aiwatar da ayyuka daban-daban kamar saita siginan kwamfuta, launuka, da ƙari.
SetConsoleCursorInfo Aiki
Bayan samun bayanin siginan kwamfuta tare da GetConsoleCursorInfo, Mun saita kayan `bVisible' zuwa ƙimar da ake so. A ƙarshe, muna kira SetConsoleCursorInfo don amfani da canje-canjenmu, yadda ya kamata ɓoye ko nuna siginan wasan bidiyo.
A ƙarshe, sarrafa abubuwan GUI kamar siginan kwamfuta ta amfani da C++ da Windows API tsari ne mai sauƙi. Da zarar kun fahimci ainihin ayyuka da ayyukansu, yana buɗe kofofin zuwa sauran damammaki masu yawa. Don haka kada ku ji tsoron gwaji kuma ku ƙara waɗannan dabaru masu amfani a cikin kayan aikin haɓakawa.