Jump to content

Simplest window example ever


Josh
 Share

Recommended Posts

	LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
{
	switch( message )
	{
		case WM_DESTROY:
			PostQuitMessage( 0 ) ;
			return 0;
			break;
	}
	return DefWindowProc( hwnd, message, wparam, lparam );
}

//Create the window
WindowsWindow* window=new Window;
window->width=width;
window->height=height;
window->wndclass.cbClsExtra = 0;
window->wndclass.cbWndExtra = 0;
window->wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
window->wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
window->wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
window->wndclass.lpfnWndProc = WndProc;
window->wndclass.lpszClassName = TEXT("le3_window_class");	
window->wndclass.lpszMenuName = 0;
window->wndclass.style = CS_HREDRAW|CS_VREDRAW;
RegisterClass( &window->wndclass );
window->hwnd = CreateWindowA(TEXT("le3_window_class"),TEXT("Leadwerks Engine"),WS_OVERLAPPEDWINDOW,200,200,width,height,NULL,NULL,NULL,NULL);
ShowWindow(window->hwnd,SW_SHOW);
UpdateWindow(window->hwnd);

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Yeah well this is kinda shorter, and works on all platforms:

SDL_Surface* screen = NULL; 

//Set up screen
screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );

 

Or maybe not on all, but on a nice amount of platforms:

SDL supports Linux, Windows, Windows CE, BeOS, MacOS, Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX. The code contains support for AmigaOS, Dreamcast, Atari, AIX, OSF/Tru64, RISC OS, SymbianOS, and OS/2, but these are not officially supported.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

I mean this is the simplest code possible to create a Windows with the Win32 API. I found another example, and had to strip out tons of unnecessary code to get the result above. I thought it might be useful to anyone trying to create a basic window.

 

I want to minimize the number of external libraries the engine relies on, so SDL is not preferable.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I put a wrapper round the Win32 interface and used that to write my editor, I like developing using the win32 API. It's lean and mean and very straight forward once you get used to it.

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

I want to minimize the number of external libraries the engine relies on, so SDL is not preferable.

That's a bad idea, since SDL brings so much good stuff in a small library:

- fastest UDP networking library

- only library which has forcefeedback for PS3 and XBOX controllers and other joysticks too

- window creating function

- keyboard reading functions

I think SDL is the only cross-platform library which is able to access the hardware on all platforms.

If you don't use SDL, you will waste a lot of time trying to implement those essential features yourself so that they work on all platforms,

and you should rather focus on the engine itself, and let the peripherial features be handled by SDL.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

"Working" does not mean "supported". Official support is almost always quite helpful. Now, on this site, unofficial support is helpful and friendly too, but on most other sites, people will bite your head off and make you feel like a retard, just because for whatever reason, you don't quite understand something that they think is simple. So I can understand why Josh might want official support for other platforms...

LE Version: 2.50 (Eventually)

Link to comment
Share on other sites

Maybe LE 3 can have a plugin for whatever library you want to use, which would be useful when the user wants to use his own custom SDL and not rely on any hardcoded library in LE 3.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Maybe LE 3 can have a plugin for whatever library you want to use, which would be useful when the user wants to use his own custom SDL and not rely on any hardcoded library in LE 3.

You are free to implement your own drivers for device input, window creation, etc.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...