Win32 API窗口不会打开 [英] Win32 API window won't open

查看:267
本文介绍了Win32 API窗口不会打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我花了时间去学习一个,但是Win32 API与打开窗口,我提出的代码,我想到的最终我认为会工作,但不是。我注册了窗口类,做了我所有的东西,但是当我运行它,没有什么发生...这将是一个伟大的帮助,如果有人可以指出我做错了/失踪。

okay, so I have taken out the time to learn a but of the Win32 API to do with opening windows, and the code I came up with in the end I would think would work, but doesn't. I registered the window class, made all the things I have to, but when I run it, nothing happens... It would be a great help if someone could point out what I am doing wrong/missing.

#include <stdlib.h>
#include <iostream>
#include <Windows.h>
#pragma comment (lib, "wsock32.lib")
#define WNDCLASSNAME "wndclass"

bool quit = false;

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
            break;

        case WM_DESTROY:
            PostQuitMessage(0);
            break;

        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int nshowcmd)
{
    WNDCLASSEX WCE;
    WCE.cbSize = sizeof(WNDCLASSEX);
    WCE.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC|CS_DBLCLKS;
    WCE.lpfnWndProc = WndProc;
    WCE.cbClsExtra = 0;
    WCE.cbWndExtra = 0;
    WCE.hInstance = hinstance;
    WCE.hIcon = NULL;//LoadImage()
    WCE.hCursor = NULL;//LoadCursor(NULL, IDC_CROSS);
    WCE.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    WCE.lpszMenuName = NULL;
    WCE.lpszClassName = "KyleWindow";
    WCE.hIconSm = NULL;

    RegisterClassEx(&WCE);

    HWND WindowHandle;

    WindowHandle = CreateWindowEx(WS_OVERLAPPEDWINDOW, "KyleWindow", "Xerus", WS_OVERLAPPEDWINDOW, 0, 0, 500, 500, NULL, NULL, hinstance, NULL);

    ShowWindow(WindowHandle, SW_SHOWNORMAL);
    UpdateWindow(WindowHandle);

    std::cout<<"'Opened' Window"<<std::endl;

    MSG msg;

    while(!quit)
    {
        if(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
        {
            if(msg.message == WM_QUIT)
                quit = true;
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    return msg.lParam;
}


推荐答案

使用 WS_EX_OVERLAPPEDWINDOW 作为 CreateWindowEx 函数的第一个参数(而不是 WS_OVERLAPPEDWINDOW 不是有效的扩展窗口样式)。

Use WS_EX_OVERLAPPEDWINDOW as the first parameter of your CreateWindowEx function (instead of WS_OVERLAPPEDWINDOW, which is not a valid extended window style).

这篇关于Win32 API窗口不会打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆