• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            我住包子山

            this->blog.MoveTo("blog.baozishan.in")

            Win32 Console Applications - Part 3 of 6 form adrianxw.dk

            Win32 Console Applications - Part 3.

            I recommend you compile and run this program. It will display the printable characters available to your console. If your console is a different size from mine, you may need to adjust the values for x and y, but this should be trivial. The rest of the tutorial assumes your character map is the same as mine - it should be, but it is possible if you have a different language set loaded into your system the positions of some of these characters may be different, run this, check them and modify the values used later accordingly, (frankly, I've worked with several language settings and never seen the character map to be different, but I'm told it is possible!).

            #include <windows.h>
            #include <iostream>
            using namespace std;
            
            int main()
            {
                HANDLE hOut;
                int i;
                int x = 0;
                int y = 0;
                COORD Position;
            
                hOut = GetStdHandle(STD_OUTPUT_HANDLE);
            
                for (i=32; i<=255; i++)
                {
                    Position.X = x;
                    Position.Y = y;
                    SetConsoleCursorPosition(hOut,
                                             Position);
            
                    cout.width(3);
                    cout << i << " " << (unsigned char)i << flush;
            
                    ++y;
                    if(y > 20)
                    {
                        y = 0;
                        x += 6;
                    }
                }
            
                Position.X = 0;
                Position.Y = 22;
                SetConsoleCursorPosition(hOut,
                                         Position);
                return 0;
            }
            

            Of particular interest to this part of the tutorial are the values between 179 and 218. Shown below is the relevent part of the output from the program.

            Char Map

            If you remember part 1 of this tutorial, I said the "normal" characters in the console font filled a 7x11 grid in a larger 8x12 character cell which had the top and row and right column blank to allow for spacing. As you can see from the picture above, these are not normal characters, some have already merged with those above and below them to give some strange glyphs that look like a cross between sanskrit and klingon! Here is the same character range more spread out and easier to see.

            Char Map2

            Unlike the normal alpha-numerics, (0-9, A-Z, a-z), and puntuation characters, where space between the individual characters is important for clarity, these characters do not have space above and to the right, they run all the way to the edge of their character cell and are designed to be merged. With these characters one can draw lines, boxes and grids. Have a look at this program output for some idea of what you can do.

            Boxes

            The figures look a little stupid when drawn this size, but I have done this to keep the size of the image files down, so they load faster, you can make them any size, and if you inspect the character map, you will see that these are not the only possibilities.

            To draw these examples, I wrote a very crude function which draws a character at a specified location on the screen, it is shown here.

            void At(int x, int y, unsigned char What)
            {
                static HANDLE hOut;
                static bool First = TRUE;
                COORD Position;
            
                if(First)
                {
                    hOut = GetStdHandle(STD_OUTPUT_HANDLE);
                    First = FALSE;
                }
            
                Position.X = x;
                Position.Y = y;
                
                SetConsoleCursorPosition(hOut,
                                         Position);
                
                cout << What << flush;
            
                return;
            }
            

            As you can see, there is no error or range checking, it simply assumes you know what you are doing. The function retrieves the standard output handle and stores it statically the first time the it is invoked.

            This code snippet shows the calls necessary to draw the first box.

                At(9, 0, (unsigned char) 218);
                At(10, 0, (unsigned char) 196);
                At(11, 0, (unsigned char) 191);
                At(9, 1, (unsigned char) 179);
                At(10, 1, (unsigned char) 32);
                At(11, 1, (unsigned char) 179);
                At(9, 2, (unsigned char) 192);
                At(10, 2, (unsigned char) 196);
                At(11, 2, (unsigned char) 217);
            

            Given the character table above and this simple example, (32 is the space character by the way), you should have enough information to create all kinds of boxes, grids, mazes, forms etc. The very playable adventure game "Caverns of Moria" known to many VAX/VMS and UNIX users had a user interface that could easily be copied using these simple graphics.

            ----------

            Whilst drawing boxes or at any time it becomes appropriate, you may want to hide or modify the appearance of the cursor. You can do this with another API routine, SetConsoleCursorInfo(). This takes 2 parameters, the standard output handle, and a pointer to a CONSOLE_CURSOR_INFO structure. This is another relatively simple Windows defined structure. It is looks like this.

            typedef struct _CONSOLE_CURSOR_INFO {
                DWORD  dwSize; 
                BOOL   bVisible; 
            } CONSOLE_CURSOR_INFO, *PCONSOLE_CURSOR_INFO; 
            

            The first value is a simple integer in the range 1-100, it specifies how much of the character cell the cursor occupies is filled. The program here sets the cursor size to 50. The 3 pictures below show the sizes 1, 50 and 100, you can, of course, use any integer in the range. Note the use of the "&" in front of the ConCurInf, remember, the routine expects a pointer to the structure you have declared.

            #include <windows.h>
            
            int main()
            {
                HANDLE hOut;
                CONSOLE_CURSOR_INFO ConCurInf;
            
                hOut = GetStdHandle(STD_OUTPUT_HANDLE);
            
                SetConsoleTitle("Size 50");
            
                ConCurInf.dwSize = 50;
                ConCurInf.bVisible = TRUE;
            
                SetConsoleCursorInfo(hOut,
                                     &ConCurInf);
            
                return 0;
            }
            
            Cursor1

            Cursor50

            Cursor100

            The other value is a boolean field and indicates whether the cursor is visible or not. A value of TRUE, (the default), means the cursor is visible, FALSE and it is invisible. The followng program turns the cursor off.

            #include <windows.h>
            
            int main()
            {
                HANDLE hOut;
                CONSOLE_CURSOR_INFO ConCurInf;
            
                hOut = GetStdHandle(STD_OUTPUT_HANDLE);
            
                SetConsoleTitle("No Cursor");
            
                ConCurInf.dwSize = 10;
                ConCurInf.bVisible = FALSE;
            
                SetConsoleCursorInfo(hOut,
                                     &ConCurInf);
            
                return 0;
            }
            
            CursorOff

            To turn the cursor back on, call the function again with the bVisible member set TRUE.

            It is a good idea to set up both values, especially the first time you call the function. If you set up bVisible but leave dwSize uninitialised, the unspecified value may be zeroed, or contain a random value, in either case, it could be out of the range 1-100, and the routine will fail. Similaly, if you want to change the size of the cursor, and don't set bVisible to be TRUE, your compiler may have zeroed the uninitialised field and the cursor will disappear instead of changing size. As always, if you check the return value of the call, you will see if any errors have happened along the way.

            Remember, the cursor is there to show where the character insertion point is. Setting the cursor to invisible does not change that. Remember also, the cursor is very useful, it shows your user "where they are" on your screen, if you take it away, you must be sure you have other means available that enable your user to navigate the screen.

            In the next part of this tutorial, we'll explore the colour issues.

            posted on 2006-07-20 22:49 Gohan 閱讀(392) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C++

            午夜精品久久久久久久久| 狠狠精品久久久无码中文字幕| 亚洲午夜久久久精品影院| 久久99国产亚洲高清观看首页 | 国产精品久久久香蕉| 亚洲伊人久久成综合人影院| 国産精品久久久久久久| 理论片午午伦夜理片久久| 亚洲国产另类久久久精品黑人| 久久水蜜桃亚洲av无码精品麻豆| 久久99国产精品久久99| 久久人人爽人人澡人人高潮AV | 亚洲国产精品热久久| 欧美久久久久久精选9999| 精品国产99久久久久久麻豆| 久久久久se色偷偷亚洲精品av| 中文字幕久久波多野结衣av| 人妻无码αv中文字幕久久琪琪布| 九九久久自然熟的香蕉图片| 久久国产精品久久| 久久久久久精品免费看SSS| 久久精品国产69国产精品亚洲| 久久伊人中文无码| 国产成人99久久亚洲综合精品| 亚洲精品高清一二区久久| 浪潮AV色综合久久天堂| 久久精品国产一区二区| 人妻无码αv中文字幕久久琪琪布| 久久精品国产一区二区电影| 久久人妻无码中文字幕| 精品综合久久久久久88小说| 麻豆精品久久久久久久99蜜桃| 久久亚洲国产中v天仙www| 久久久无码精品亚洲日韩京东传媒| 国产精品成人无码久久久久久| 99热成人精品热久久669| 亚洲AV乱码久久精品蜜桃| 亚洲国产成人久久一区久久| 久久99精品国产麻豆宅宅| 久久精品中文字幕无码绿巨人| 亚洲天堂久久久|