// Example program: // Using SDL2 to create an application window #include "SDL.h" #include "SDL_syswm.h" #include LRESULT CALLBACK My_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { printf("%.8x\n", msg); return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam); } int main(int argc, char* argv[]) { SDL_Window* window; // Declare a pointer SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2 // Create an application window with the following settings: window = SDL_CreateWindow( "An SDL2 window", // window title SDL_WINDOWPOS_UNDEFINED, // initial x position SDL_WINDOWPOS_UNDEFINED, // initial y position 640, // width, in pixels 480, // height, in pixels SDL_WINDOW_OPENGL // flags - see below ); // Check that the window was successfully created if (window == NULL) { // In the case that the window could not be made... printf("Could not create window: %s\n", SDL_GetError()); return 1; } SDL_SysWMinfo wmInfo; SDL_VERSION(&wmInfo.version); SDL_GetWindowWMInfo(window, &wmInfo); HWND hwnd = wmInfo.info.win.window; // The window is open: could enter program loop here (see SDL_PollEvent()) SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)My_WindowProc); int quit = 0; SDL_Event e; while (!quit) { //Handle events on queue while (SDL_PollEvent(&e) != 0) { //User requests quit if (e.type == SDL_QUIT) { quit = 1; } } } // Close and destroy the window SDL_DestroyWindow(window); // Clean up SDL_Quit(); return 0; }