我一直在使用Xcode和我的Macbook上使用SDL2,我很高兴.最近我试图收到一个焦点丢失的事件,但它没有工作.经过一些修补,我发现没有收到窗口事件,除了窗口事件的类型为512,每秒随机间隔显示2-5次.该WindowEventIDs为在枚举,而不是在十六进制格式,所以它不应该是一些十六进制数.我在SDL2框架中搜索了512并没有发现任何内容.其他活动,如SDL_QUIT与SDL_KEYDOWN工作就好了.谁知道发生了什么事?
这是我的事件循环:
SDL_Event event;
bool running = false;
while(running) {
while(SDL_PollEvent(&event)) {
if(event.type == SDL_QUIT)
running = false;
else if(event.type == SDL_KEYDOWN) {
cout << event.key.type << endl;
}
else if(event.type == SDL_WINDOWEVENT) {
cout << event.window.type << endl;
}
}
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用C++建立一个简单的窗口,但我的CreateWindowEx回调NULL.我使用的大部分代码都来自MSDN网站上的示例.我尝试过的任何东西都没有用,任何帮助都会受到赞赏.
这是代码:
//Include the windows header
#include <Windows.h>
//Forward declaration of the WndProc function
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
//Main entry point
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
//Window class name
const wchar_t windowName[] = L"Window Class";
//Set up window class
WNDCLASS wnd;
wnd.lpfnWndProc = WndProc;
wnd.hInstance = hInstance;
wnd.lpszClassName = windowName;
//Register window class
RegisterClass(&wnd);
//Create window
//! This returns NULL
HWND hWnd …Run Code Online (Sandbox Code Playgroud)