【问题标题】:What's wrong with this C declaration Code?这个 C 声明代码有什么问题?
【发布时间】:2012-05-23 07:42:18
【问题描述】:
#include <stdlib.h>
#include <Windows.h>
#include <Tchar.h>

HANDLE wHnd;    // Handle to write to the console.
HANDLE rHnd;    // Handle to read from the console.

int _tmain(int argc, _TCHAR* argv[]) {

    // Set up the handles for reading/writing:
    wHnd = GetStdHandle(STD_OUTPUT_HANDLE);
    rHnd = GetStdHandle(STD_INPUT_HANDLE);

    // Change the window title:
    SetConsoleTitle(TEXT("Win32 Console Control Demo"));

    // Set up the required window size:
    SMALL_RECT windowSize = {0, 0, 79, 49};

    // Change the console window size:
    SetConsoleWindowInfo(wHnd, TRUE, &windowSize);

}

报告了一些这样的错误:

'SMALL_RECT' : illegal use of this type as an expression  
missing ';' before identifier 'windowSize'

【问题讨论】:

  • 您的意思是包括Windows.hTchar.h,而不是windows.htchar.h
  • 在 CodeBlocks 10.05 上运行良好。
  • @AlexanderBakulin 没关系,因为 Windows 文件系统不区分大小写。
  • @DavidHeffernan:是的,这让我眼前一亮。我仍然看不出这种滥用不区分大小写的原因。

标签: c windows console tui


【解决方案1】:

您正在使用仅支持现在古老的 C90 标准的 MS C 编译器。所有变量都必须在函数体的顶部声明。

int _tmain(int argc, _TCHAR* argv[])
{    
    // Set up the required window size:
    SMALL_RECT windowSize = {0, 0, 79, 49};

    // Set up the handles for reading/writing:
    wHnd = GetStdHandle(STD_OUTPUT_HANDLE);
    rHnd = GetStdHandle(STD_INPUT_HANDLE);

    // Change the window title:
    SetConsoleTitle(TEXT("Win32 Console Control Demo"));

    // Change the console window size:
    SetConsoleWindowInfo(wHnd, TRUE, &windowSize);
}

很痛苦,不是吗?!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-16
    • 2015-02-16
    相关资源
    最近更新 更多