Those who have done programming, of course, remember that the console program we learned about programming is always a black window. We try our best to provide standard output in it, but whether or not we have thought about the secrets that the Console does not know. In my previous blog post, I wrote the console program, which is actually the same as our interface program design. Here I want to show you and prove my point of view! (* ^__ ^ *) ......) I hope you will like it. In Windows, I think everyone knows that we have created a window, the operating system will naturally give our windows an identifier in the system kernel-that is, the HWND window handle we usually call ). First, let's guess if there is a window for our console program! Haha ..., Of course, it does. Otherwise, what is my black box! It is a real window. Does our console program have a window handle? I would like to start with a bit of hesitation for this issue, because we have never seen or told us that our console program has a handle Hwnd ). As mentioned above, a handle is provided for each window operating system in the operating system. Of course, the operating system will not treat the console specially, and it also has an Hwnd. All right, we all know that the console program has a window handle. But where is he? How can we get it? Don't worry, I will tell you that. The following is a simple example of obtaining the console window handle. # Include <stdio. h> # include <windows. h> typedef HWND (WINAPI * PROCGETCONSOLEWINDOW) (); PROCGETCONSOLEWINDOW GetConsoleWindow; Int main () {HMODULE hKernel32 = kernel ("kernel32"); GetConsoleWindow = (PROCGETCONSOLEWINDOW) kernel (hKernel32, "GetConsoleWindow"); HWND cmd = GetConsoleWindow ();} first, we need the system API in Kernel32. Then we can export the GetConsoleWindow function to get the window handle! What can we do if we get the window handle? Here I am very excited to tell you that we have obtained a window handle. We can do everything on the image interface now! If you don't believe it, draw a circle in the window and you will know that I didn't lie to you, but remember to change the color of the paint brush !). Below is the code for displaying a bitmap in the console. You can try it. It is absolutely feasible! (Copy the map to the project directory and change it to 1.bmp) # include <stdio. h> # include <windows. h> typedef HWND (WINAPI * PROCGETCONSOLEWINDOW) (); PROCGETCONSOLEWINDOW GetConsoleWindow; Int main () {HMODULE hKernel32 = kernel ("kernel32"); GetConsoleWindow = (PROCGETCONSOLEWINDOW) kernel (hKernel32, "GetConsoleWindow"); HWND cmd = GetConsoleWindow (); HDC dc = GetDC (cmd); HBITMAP hBitmap; hBitmap = (HBITMAP) LoadImage (N ULL, "1.bmp", IMAGE_BITMAP, 100,100,300,300, LR_LOADFROMFILE | LR_CREATEDIBSECTION); HDC running mem = CreateCompatibleDC (dc); SelectObject (memory MEM, hBitmap); BitBlt (dc, memory MEM, 0, 0, SRCCOPY); Return 1;} What do you think! Do you agree with my previous blog post! Haha ...) Now we can do everything you want on the console! Do it Now! The following describes some practical console functions. I will not introduce them much here. If you are interested, you can check MSDN or Google! Getincluenmenu items get the system menu EnableMenuItem items in the console ReadConsoleOutputCharacter --------------------- read the text from the Console Buffer and save it to the variable GetStdHandle parameters to get the standard input and output, incorrect handle SetConsoleCursorPosition ----------------------- set the console cursor position ScrollConsoleScreenBuffer ---------------------- set the Buffer size for console rollback SetConsoleDisplayMode ------------------ ------- Set whether the console display mode is full screen) mouse_event ------------------------------------- simulate the mouse operation ReadConsoleInput ---------------------------- control output of the command line, getConsoleMode enables the console to support the FillConsoleOutputAttribute --------------------- color console to set the output color SetConsoleTextAttribute ------------------------ to set the text color. If you have friends who have different understandings about the console, I hope that I can communicate with me in my blog, so that we can have a deeper understanding.
This article is from the "HelloWorld" blog, please be sure to keep this source http://vanshell.blog.51cto.com/890307/428651