This repository was archived by the owner on Jan 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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.
- Add the
Awnd.h
header file to yourmain.cpp
file.
#include "Awnd.h"
- Create a sample class for your application. the class must inheriate from the
AwndApp
class
class SampleApp : public App {
}
- 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;
}
- 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;
}
- Create a object from the
Application
class inside theonApplicationCreate()
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);
}
- Implement a function that takes a
time
floating point and that executes theonApplicationCreate()
public:
// Making a function to execute the application, time is the renderTime
void Execute(float time) {
onApplicationCreate(time);
}
- 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();
}
- 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);
}
- 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;
}
- You're finished!