CBPGUI C++ Library (Beta)

Lately I've been working on a C++ library that was built around the Win32 API. This library is an OO library made for quick and easy GUI creation for applications on the Windows operating system. You can download it here: http://www.sendspace.com/file/hzmpuw . Please take some time to look through all the files and let me know if you've found any errors, or places where more functions could be added, or places where things can be done better.

I'll now provide a few examples, but before you run any of these you need to set up the library. It is rather easy to do, just download the folder, and extract it to your include folder for your IDE.

Examples:

Basic & Blank Window:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//Include the headers.
#include <CBPGUI/CBPGUI.h>
//Allow access to the CBPGUI namespace.
using namespace nsCBPGUI; 
//Application entry point will be called when the program is ran, this is just a defined as WinMain.
ApplicationEntryPoint ()
{
	//Create the window.
	WindowCreation Window ("CBPGUI Library Testing Application");
	//Set the size.
	Window.SetLocation (315, 115, 700, 480);
	//Create the window, and exit the application is the window couldn't be created.
	if (Window.Create () < 0) return 0;
	//Handle the messages.
	return MessageLoop ();
}


Adding a window procedure, just like in Win32, message handling will be in the WindowProcedure functions.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <CBPGUI/CBPGUI.h>
using namespace nsCBPGUI; 
//Window procedure function.
LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
	//Handle the messages.
	switch (uiMsg)
	{
		case WM_DESTROY: //When we destroy the window.
			PostQuitMessage (0); //Exit the message loop.
			break;
		default: //handle all other messages.
			return DefWindowProc (hWnd, uiMsg, wParam, lParam);
	}
	return 0;
} 
ApplicationEntryPoint ()
{
	WindowCreation Window ("CBPGUI Library Testing Application");
	Window.SetLocation (315, 115, 700, 480);
	//Add the callback.
	Window.SetCallback (WndProc);
	if (Window.Create () < 0) return 0;
	return MessageLoop ();
}


Now lets get onto making some controls, like buttons, edit boxes, ect.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <CBPGUI/CBPGUI.h>
using namespace nsCBPGUI;
LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
    //Allocate the edit box only one time.
    static EditCreation EditBox (hWnd); //Set parent window in the constructor.
	switch (uiMsg)
	{
		case WM_DESTROY:
			PostQuitMessage (0);
			break;
		case WM_CREATE: //When the window is created, I use this time to create controls.
			{
				//Create a button.
				ButtonCreation Button (hWnd); //Set parent window in the constructor.
				Button.SetLocation (5, 5, 130, 30); //Set the location.
				Button.SetText ("Click Me!"); //Set the text.
				Button.SetMenuID (1000); //Set the ID, so we know when its clicked.
				Button.Create (); //Create the button.
				//Create an edit box.
				EditBox.SetLocation (150, 5, 130, 30); //Set the location.
				EditBox.Create (); //Create the edit box.
			}
			break;
		case WM_COMMAND: //When something happens.
			switch (LOWORD (wParam))
			{
				case 1000: //1000 = the button Menu ID.
					//Display the text in the edit box.
					MessageBox (hWnd, EditBox.GetText ().c_str (), "Message:", MB_OK);
					break;
			}
		default:
			return DefWindowProc (hWnd, uiMsg, wParam, lParam);
	}
	return 0;
}
ApplicationEntryPoint ()
{
	WindowCreation Window ("CBPGUI Library Testing Application");
	Window.SetLocation (315, 115, 700, 480);
	Window.SetCallback (WndProc);
	if (Window.Create () < 0) return 0;
	return MessageLoop ();
}


We can also print text easily:
If you want you can change the font, see Font.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <CBPGUI/CBPGUI.h>
using namespace nsCBPGUI;
LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uiMsg)
	{
		case WM_DESTROY:
			PostQuitMessage (0);
			break;
		case WM_PAINT: //When we paint the window, used for displaying graphics.
			{
				//Create an object to the DeviceContext.
				DeviceContext DC (hWnd); //Set the window to print to in the constructor.
				DC.PrintText (5, 5, "Hello World!!!!"); //Print the text at (5, 5)
			}
			break;
		default:
			return DefWindowProc (hWnd, uiMsg, wParam, lParam);
	}
	return 0;
} 
ApplicationEntryPoint ()
{
	WindowCreation Window ("CBPGUI Library Testing Application");
	Window.SetLocation (315, 115, 700, 480);
	Window.SetCallback (WndProc);
	if (Window.Create () < 0) return 0;
	return MessageLoop ();
}


There are many other things that you can do with this library, and many more things will be added soon.

Again, please let me know if you have any more ideas for this library, it is far from complete and you're help in completing it would be great.

When the library is complete, tutorials on using each feature will be added to the CBP youtube channel:

http://youtube.com/user/CurlyBraceProduction


-LeetGamer aka Write Great Code
Topic archived. No new replies allowed.