Skip to content
This repository was archived by the owner on Jan 31, 2024. It is now read-only.

How to create a application with Awnd

Copy edited this page Feb 11, 2023 · 1 revision

In this article you will learn how to create a c++ win32 application using Awnd.

  1. Add the Awnd.h header file to your main.cpp file.
#include "Awnd.h"
  1. Create a sample class for your application. the class must inheriate from the AwndApp class
class SampleApp : public App {

}
  1. Add a constructor where you can set your width and height of your window
class SampleApp : public App {
public:
    App(int width, int height) {
		this->w = width;
		this->h = height;
	};

private:
    int w, h;
}
  1. Override the onApplicationCreate() function
class SampleApp : public App {
public:
    App(int width, int height) {
		this->w = width;
		this->h = height;
	};

private:

	void onApplicationCreate(float e_Time) override {

	}

private:
    int w, h;
}
  1. Create a object from the Application class inside the onApplicationCreate() function

The Application constructor we're using is this one:

Application(LPCWSTR windowsTitle, bool fullScreen, int rectwidth = 640, int rectheight = 480)
void onApplicationCreate(float e_Time) override {

		// Hidding Console Window
		HideConsole();

		// Initalizing The Application
		Application* app = new Application( (LPCWSTR)L"Hello World", false, w, h );
		app->runWindow(e_Time);
	}
  1. Implement a function that takes a time floating point and that executes the onApplicationCreate()
public:
    // Making a function to execute the application, time is the renderTime
	void Execute(float time) {
		onApplicationCreate(time);
    }
  1. Implement the Awnd::ComponentHandler() function.

The function is defined but empty. Awnd does handle the component creation. all you have to do is to implement the Awnd::ComponentHandler()

void Awnd::ComponentHandler(HWND hWnd){

}

Let's add a Button component! we will use this constructor:

Button(int x, int y, int width, int height, LPCWSTR text, HWND hwnd, HMENU Id);
// Define a MACRO for your button ID
#define IDC_BUTTO 11

void Awnd::ComponentHandler(HWND hWnd){
	// Creates the Button
    Awnd::Button* btn = new Awnd::Button(100, 300, 100, 20, L"Hello World", hWnd, (HMENU)IDC_BUTTO);
	
	// And then append it to the frame.
    btn->append();
}
  1. The application seems boring. Let's add Command Handling. Implement the Awnd::CommandHandler(WPARAM wParam) function

We're using Awnd's OnClick macro to add a click event for our button.

void Awnd::CommandHandler(WPARAM wParam) {

	// If the Button is Pressed the application exits.
	if (OnClick(wParam, IDC_BUTTO))
		exit(0);
}
  1. Almost done! now create a object of your class in your entry point
int main(){
    // Initalize the application and run it
    App* app = new App(1280, 720);
	app->Execute(5.0f);
	return 0;
}
  1. You're finished!
Clone this wiki locally