void Consola::setTextSizeXP(int x, int y){ // Configura acesso às funções "secretas" do Windows SetConsoleFont_ SetConsoleFont = reinterpret_cast<SetConsoleFont_>(GetProcAddress(GetModuleHandle(L"kernel32.dll"), "SetConsoleFont")); GetConsoleFontInfo_ GetConsoleFontInfo = reinterpret_cast<GetConsoleFontInfo_>(GetProcAddress(GetModuleHandle(L"kernel32.dll"), "GetConsoleFontInfo")); GetNumberOfConsoleFonts_ GetNumberOfConsoleFonts = reinterpret_cast<GetNumberOfConsoleFonts_>(GetProcAddress(GetModuleHandle(L"kernel32.dll"), "GetNumberOfConsoleFonts")); // Num de fontes DWORD NumFonts = GetNumberOfConsoleFonts(); // alloca matriz de cont infos CONSOLE_FONT_INFO* ConsoleInfo = new CONSOLE_FONT_INFO[sizeof(CONSOLE_FONT_INFO) * NumFonts]; // obtem info das fontes todas GetConsoleFontInfo(hconsola, FALSE, NumFonts, ConsoleInfo); // percorre-as todas. O melhor é não chamar isto muitas vezes for (size_t i = 0; i < NumFonts; ++i) { // Indaga o tamanho (suportado) da fonte. Pode não haver nenhuma para esse tamanho ConsoleInfo[i].dwFontSize = GetConsoleFontSize(GetStdHandle(STD_OUTPUT_HANDLE), ConsoleInfo[i].nFont); // Encontrou uma. muda para essa e já está (mesmo que haja outras) if (ConsoleInfo[i].dwFontSize.X == x && ConsoleInfo[i].dwFontSize.Y == y) { // x,y = tamanho desejado (se houver) // muda para essa fonte e sai SetConsoleFont(GetStdHandle(STD_OUTPUT_HANDLE), ConsoleInfo[i].nFont); break; } } // devolve a matriz de INFO delete [] ConsoleInfo; }
// gets the y coordinate of the cell the mouse is in int Console::GetMouseCellY() { GetCursorPos(&cur_point); windowpoint.x = 0; windowpoint.y = 0; ClientToScreen(hWindow,&windowpoint); GetCurrentConsoleFont(hScreen, false, &font); fontSize = GetConsoleFontSize(hScreen, font.nFont); if (fontSize.Y != 0) mouse.y = (cur_point.y - windowpoint.y)/fontSize.Y; else { // else it is in fullscreen GetConsoleScreenBufferInfo(hScreen,&ScrBufInfo); // get the window handle to the whole screen fullscr_h = GetDesktopWindow(); // get the size of the whole screen GetClientRect(fullscr_h, &fullscr_size); mouse.y = cur_point.y/((fullscr_size.bottom/ScrBufInfo.dwSize.Y)-3); } return mouse.y; }
int main (int argc, char *argv[]) { //Get a console handle HWND ConsoleWindow = GetConsoleWindow(); //Get a STD handle HWND StdHandle = GetStdHandle (STD_OUTPUT_HANDLE); //Set cursor invisible CONSOLE_CURSOR_INFO CURSOR; CURSOR.dwSize = 1; CURSOR.bVisible = FALSE; SetConsoleCursorInfo (StdHandle, &CURSOR); //Get Current Font for (;;) { CONSOLE_FONT_INFO GETFONT; GetCurrentConsoleFont (StdHandle, FALSE, &GETFONT); COORD Fontsize = GetConsoleFontSize (StdHandle, GETFONT.nFont); SHORT Font_X = Fontsize.X; SHORT Font_Y = Fontsize.Y; if (Font_X != 8 || Font_Y != 12) { system ("chcp 437 > NUL"); MessageBox (ConsoleWindow, "Please change Console Font to Raster Font ( 8 x 12 ).", "Notice", MB_TOPMOST | MB_OK | MB_ICONINFORMATION); Envir_Error (); printf ("\rPress any key to continue..."); system ("pause>nul"); } else break; } //Change Settings //SetWindowLong (ConsoleWindow, GWL_STYLE, WS_THICKFRAME); //SetWindowLong (ConsoleWindow, GWL_STYLE, WS_CAPTION); //SetWindowPos (ConsoleWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_SHOWWINDOW); SetWindowPos (ConsoleWindow, HWND_TOP, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_SHOWWINDOW); //Get a handle to device context HDC DeviceContext = GetDC (ConsoleWindow); //Color COLORREF Color_White = RGB (255,255,255); COLORREF Color_Black = RGB ( 0 , 0 , 0 ); //Title and Resize system ("mode con cols=75 lines=50"); system ("title Console Snake [ Developer: KVD 2013 ]"); system ("color 0A"); //Multi-Thread pthread_t Key_Stroke_Func; pthread_create (&Key_Stroke_Func, NULL, (void*)Get_Key_Stroke, NULL); //Initialization Initialize:; Initialization (DeviceContext, argv[1]); //Main for (;;) { //Terminate / PlayAgain if (Flag_Terminate == True) { return 0; } else if (Flag_PlayAgain == True) { Flag_PlayAgain = False; Clear_Screen (DeviceContext); goto Initialize; } //Draw if (Move.Condition == UnRead) { Move.Condition = Read; Change_Str (DeviceContext, ConsoleWindow); Draw_Square (Draw.X, Draw.Y, Draw.Direction, Color_White, Erase.X, Erase.Y, Erase.Direction, Color_Black, User_Def_Delay, DeviceContext); } else { Predict_Func (Draw.Direction); Change_Str (DeviceContext, ConsoleWindow); Draw_Square (Draw.X, Draw.Y, Draw.Direction, Color_White, Erase.X, Erase.Y, Erase.Direction, Color_Black, User_Def_Delay, DeviceContext); } //End if (Is_Snake (Draw.X, Draw.Y) == True || Is_Block (Draw.X, Draw.Y) == True) { MessageBox (ConsoleWindow, "GAME OVER", "Notice", MB_TOPMOST | MB_OK | MB_ICONSTOP); Clear_String (); Clear_Screen (DeviceContext); goto Initialize; } } //End system ("pause>nul"); return 0; }
co_rc_t console_widget_NT_t::set_window(console_window_t * W) { CONSOLE_CURSOR_INFO cci; CONSOLE_FONT_INFO cfi; COORD fs; HWND hwnd; RECT r; window = W; input = GetStdHandle(STD_INPUT_HANDLE); SetConsoleMode(input, 0); output = GetStdHandle(STD_OUTPUT_HANDLE); GetCurrentConsoleFont(output, 0, &cfi); fs = GetConsoleFontSize(output, cfi.nFont); r.top = 0; r.left = 0; r.bottom = fs.Y * 25; r.right = fs.X * 80; AdjustWindowRect(&r, WS_CAPTION|WS_SYSMENU|WS_THICKFRAME |WS_MINIMIZEBOX|WS_MAXIMIZEBOX, 0); hwnd = GetConsoleWindow(); SetWindowPos(hwnd, HWND_TOP, 0, 0, r.right - r.left, r.bottom - r.top, SWP_NOMOVE|SWP_SHOWWINDOW); GetConsoleCursorInfo(output, &cursor); cci = cursor; cci.bVisible = 0; SetConsoleCursorInfo(output, &cci); size.X = 80 ; size.Y = 25 ; region.Top = 0; region.Left = 0; region.Right = 79; region.Bottom = 24; if( ! SetConsoleWindowInfo( output , TRUE , ®ion ) ) co_debug("SetConsoleWindowInfo() error code %d\n", GetLastError()); screen = (CHAR_INFO *) co_os_malloc(sizeof (CHAR_INFO) * size.X * size.Y); buffer = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, 0, CONSOLE_TEXTMODE_BUFFER, 0); if( ! SetConsoleScreenBufferSize( buffer , size ) ) co_debug("SetConsoleScreenBufferSize() error %d\n", GetLastError()); SetConsoleMode(buffer, 0); cci.bVisible = true; cci.dwSize = 10; SetConsoleCursorInfo(buffer, &cci); SetConsoleActiveScreenBuffer(buffer); return CO_RC(OK); }
int OptH(char *Opt) { int optLen = 2; boolean State; optCount++; switch (Opt[1]) { case 'b': fSetBorder = TRUE; strdel(Opt, 0, 2); Border.W = decVal(Opt); if (Opt[0] != ',') Stop(2, Opt); strdel(Opt, 0, 1); Border.H = decVal(Opt); optLen = 0; break; case 'f': fFontSet = TRUE; fResizeWindowToMax = TRUE; strdel(Opt, 0, 2); if (isdigit(Opt[0])) { Font.H = decVal(Opt); if (Opt[0] != ',') Stop(2, Opt); strdel(Opt, 0, 1); Font.W = decVal(Opt); } else { int fw,fh; if (GetConsoleFontSize(&fh, &fw)) { Font.H = fh; Font.W = fw; } } optLen = 0; break; case 'o': optLen += OptState(Opt[3], &State) + 1; switch (Opt[2]) { case 'a': ANSI = State; break; case 'd': fDelay = State; break; case 'r': fResizeWindowToMax = State; break; case 'f': if (State) { fFlashWindow = TRUE; fSetFlash = TRUE; } else { fFlashWindow = FALSE; fSetFlash = TRUE; } break; case 'b': if (State) { sd.FgBg = SSF_FGBG_BACK; fForegroundConsole = FALSE; } else { sd.FgBg = SSF_FGBG_FORE; fForegroundConsole = TRUE; } break; case 'c': if (State) sd.PgmControl &= ~SSF_CONTROL_NOAUTOCLOSE; else sd.PgmControl |= SSF_CONTROL_NOAUTOCLOSE; break; case 'v': if (State) { sd.PgmControl &= ~SSF_CONTROL_INVISIBLE; fHideConsole = FALSE; fShowConsole = TRUE; } else { sd.PgmControl |= SSF_CONTROL_INVISIBLE; fHideConsole = TRUE; fShowConsole = FALSE; } break; case 'x': if (State) { sd.PgmControl |= SSF_CONTROL_MAXIMIZE; sd.PgmControl &= ~SSF_CONTROL_MINIMIZE; fAutoSize = FALSE; fMaximizeConsole = TRUE; fRestoreConsole = FALSE; } else { sd.PgmControl &= ~SSF_CONTROL_MAXIMIZE; fMaximizeConsole = FALSE; fRestoreConsole = TRUE; } break; case 'm': if (State) { sd.PgmControl |= SSF_CONTROL_MINIMIZE; sd.PgmControl &= ~SSF_CONTROL_MAXIMIZE; fMinimizeConsole = TRUE; fRestoreConsole = FALSE; } else { sd.PgmControl &= ~SSF_CONTROL_MINIMIZE; fMinimizeConsole = FALSE; fRestoreConsole = TRUE; } break; case 'n': fNewSession = State; break; case 's': fAutoSize = State; break; default: Stop(2, Opt); } break; case 'p': strdel(Opt, 0, 2); if (isdigit(Opt[0])) { ConsolePos.X = decVal(Opt); fExplicitPos = TRUE; } else if (Opt[0] != ',') GetPixelConsoleSize(&ConsolePos.X, &ConsolePos.Y, &ConsolePos.W, &ConsolePos.H); if (Opt[0] == ',') { strdel(Opt, 0, 1); if (isdigit(Opt[0])) { ConsolePos.Y = decVal(Opt); fExplicitPos = TRUE; } if (Opt[0] == ',') { strdel(Opt, 0, 1); if (isdigit(Opt[0])) { ConsolePos.W = decVal(Opt); fExplicitSize = TRUE; } if (Opt[0] == ',') { strdel(Opt, 0, 1); if (isdigit(Opt[0])) { ConsolePos.H = decVal(Opt); fExplicitSize = TRUE; } } } } optLen = 0; break; case 's': fConsoleSize = TRUE; fResizeWindowToMax = TRUE; strdel(Opt, 0, 2); Console.W = decVal(Opt); if (Opt[0] != ',') Stop(2, Opt); strdel(Opt, 0, 1); Console.H = decVal(Opt); optLen = 0; break; case 't': { int i = 3; int l = strlen(Opt); if (Opt[2] != '"') Stop(2, Opt); while (i < l && Opt[i] != '"') i++; if (Opt[i] != '"') Stop(2, Opt); progtitle = malloc(i - 2); strncpy(progtitle, &Opt[3], i - 3); progtitle[i - 2] = 0; optLen = i + 1; break; } case 'q': fQueryCommand = TRUE; break; case 'w': switch (Opt[2]) { case 'a': sd.SessionType = SSF_TYPE_DEFAULT; break; case 'd': sd.SessionType = SSF_TYPE_WINDOWEDVDM; break; case 'o': sd.SessionType = SSF_TYPE_WINDOWABLEVIO; break; default: Stop(2, Opt); } optLen++; break; case '?': case 'h': Stop(1, NULL); default: Stop(2, Opt); } if ((Opt[optLen] != 0) && (Opt[optLen] != SPACE) && (Opt[optLen] != TAB)) Stop(2, Opt); return optLen; }