zoukankan      html  css  js  c++  java
  • c++运行程序 改变字和背景的颜色与窗口大小和位置 (c++)(windows)

    关于改变字体的颜色和背景颜色:

    在#include <windows.h> 库里

    0=黑色
    1=蓝色
    2=绿色
    3=湖蓝色
    4=红色
    5=紫色
    6=黄色
    7=白色
    8=灰色
    9=淡蓝色
    A=淡绿色
    B=淡浅绿色
    C=淡红色
    D=淡紫色
    E=淡黄色
    F=亮白色
     
    方法一:
    常用cmd上 color 函数 (注意!!!是改变全部)
    1 #include<bits/stdc++.h>
    2 #include<windows.h>
    3 using namespace std;
    4 
    5 int main() {
    6     system("color 46");//第一个是背景,第二个是字体
    7      //这是红底黄字
    8     return 0;
    9 }

    方法二:

    运用SetConsoleTextAttribute (百度翻译:集合控制台文本属性)

     
     1 #include<bits/stdc++.h>
     2 #include<windows.h>
     3 using namespace std;
     4 
     5 int main() {
     6     for (int i=0;i<8192;i++)
     7     {
     8         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),i);
     9         printf("%x
    ",i);
    10     }
    11     return 0;
    12 }
     
    据以上实验知:16进制下:
    第一位:字体
    第二位:背景
    第三位:0~3 无
        4~7 上划线(与字体同色)
        8~b 左竖线  (与字体同色)
        c~f  左上线  (与字体同色)
        10~13 右竖线  (与字体同色)
        14~17 右上线  (与字体同色)
        18~1b 左右线  (与字体同色)
        1c~1f 左右上线  (与字体同色)
     
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
     关于改变窗口的大小与位置
    同样在#include <windows.h>
    方法一:
    使用cmd中:mode con cols=x lines=y (x是长,y是宽)
     
    1 #include <Windows.h>
    2  
    3 int main() {
    4     system("mode con cols=100 lines=20");
    5     return 0;
    6 }

    方法二:

    函数:SetWindowPos(翻译:设置窗口位置)

    1 #include <Windows.h>
    2  
    3 int main() {
    4     HWND hWnd = GetConsoleWindow(); //获得cmd窗口句柄
    5     SetWindowPos(hWnd,NULL,1,2,100,20,NULL);
    6     return 0;
    7 }

    (1,0):窗口左上角的位置

    (100,200) 窗口大小

     
  • 相关阅读:
    刷题238. Product of Array Except Self
    刷题236. Lowest Common Ancestor of a Binary Tree
    刷题208. Implement Trie (Prefix Tree)
    A1070
    A1048
    A1050
    A1041
    A1092
    A1084
    n进制转十进制
  • 原文地址:https://www.cnblogs.com/Srand-X/p/12122045.html
Copyright © 2011-2022 走看看