简体   繁体   English

简单的窗口c ++不可见

[英]simple windows c++ not visible

case WM_CREATE:
    {
    int randomsize=0;
    //std::string lineofquote;
    char lineofquote[255];
    std::ifstream infile;
    infile.open("quotes.txt",std::ios::in);
    if (infile)
    {
        MessageBox(NULL,"infile failed","Error reading file", MB_OK);
        return 0;
    }
    newhandler = CreateWindow(TEXT("static"),TEXT("Quote here") ,WS_CHILD | WS_VISIBLE , 0,0,550,150,hWnd,NULL,NULL,NULL);

    while(!infile.eof())//get file size
    {
        infile.getline(lineofquote,255,'\n');
        SetWindowText(newhandler,lineofquote);
        randomsize++;
    }
    infile.close();
    //std::cout<<randomsize;

    break;
    }

When i run this program, i dont seem to see my windows at all. 当我运行这个程序时,我似乎根本看不到我的窗户。 What might be the problem here? 这可能是什么问题?

That is not the way you create a window. 这不是你创建窗口的方式。 You create a window using CreateWindow API . 您可以使用CreateWindow API创建一个窗口。 There are a couple of things you need to do along with it. 你需要做几件事。 May be this MSDN tutorial can help. 可能是这个MSDN教程可以提供帮助。

WM_CREATE is an event fired when a window is created, typically using the above API. WM_CREATE是在创建窗口时触发的事件,通常使用上述API。

Always read the documentation properly. 务必正确阅读文档。 As long as you are dealing with Win32 APIs, MSDN will be your bible. 只要您处理Win32 API,MSDN就是您的圣经。

Check your ShowWindow() function. 检查ShowWindow()函数。 You could set CmdShow parameter to 0 which means that your window will not be visible, or just simply you forgot to call this function. 您可以将CmdShow parameter to 0设置CmdShow parameter to 0 ,这意味着您的窗口将不可见,或者只是您忘记调用此函数。 Also, you could check if RegisterClassEx(...) worked propely. 此外,您可以检查RegisterClassEx(...)工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM