mwcxx/test.cc
2026-04-20 05:29:42 +09:00

65 lines
1.5 KiB
C++

#include <MwCXX/Core.h>
#include <MwCXX/Widget/Window.h>
#include <MwCXX/Widget/Button.h>
#include <MwCXX/Widget/ListBox.h>
#include <MwCXX/Dialog/MessageBox.h>
#include <iostream>
/* Note: Since C++ binding does not know when dialog gets freed - you should listen to CloseHandler for dialogs, and destroy widget */
static void close_msg(MwCXX::Window* window) {
delete window;
}
static void close_msg(MwCXX::Button* button) {
delete button->GetParent();
}
class MyButton : public MwCXX::Button {
protected:
void OnActivate() {
MwCXX::Window* msg;
msg = MwCXX::MessageBox(this->GetParent(), "Hello", "Hello world", MwMB_BUTTONOK | MwMB_ICONNEWS);
msg->CloseHandler = close_msg;
MwCXX::MessageBoxGetChild(msg, MwMB_BUTTONOK)->ActivateHandler = close_msg;
}
public:
MWCXX_CONSTRUCTOR(MyButton, MwCXX::Button) {
this->SetText("Hello, world!");
}
};
class MyWindow : public MwCXX::Window {
private:
MyButton* epic;
MwCXX::ListBox* epic2;
protected:
void
OnResize() {
MwRect rc = this->GetArea();
this->epic->Resize(rc.width - 20, rc.height - 20);
}
public:
MWCXX_CONSTRUCTOR(MyWindow, MwCXX::Window) {
this->epic = new MyButton("epic app", this, 10, 10, 640 - 10 * 2, 240 - 10);
this->epic2 = new MwCXX::ListBox("epic app", this, 10, 10 + 240 - 10, 640 - 10 * 2, 240 - 10);
this->epic2->Set(-1, 0, "Test");
}
};
int main() {
MyWindow* wnd;
MwCXX::Init();
wnd = new MyWindow("epic app", NULL, MwDEFAULT, MwDEFAULT, 640, 480);
wnd->Loop();
}