简体   繁体   中英

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 . There are a couple of things you need to do along with it. May be this MSDN tutorial can help.

WM_CREATE is an event fired when a window is created, typically using the above API.

Always read the documentation properly. As long as you are dealing with Win32 APIs, MSDN will be your bible.

Check your ShowWindow() function. 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. Also, you could check if RegisterClassEx(...) worked propely.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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