xtd 0.2.0
wnd_proc.cpp

demonstrates the use of wnd_proc method.

Windows

macOS

Gnome

#include <xtd/drawing/system_brushes>
#include <xtd/forms/application>
#include <xtd/forms/form>
#include <xtd/forms/window_messages>
using namespace xtd;
using namespace xtd::drawing;
using namespace xtd::forms;
namespace wnd_proc_example {
class form1 : public form {
public:
form1() {
client_size({300, 300});
text("form1");
}
protected:
void on_paint(paint_event_args& e) override {
// Paint a string in different styles depending on whether the application is active.
if (app_active) {
e.graphics().fill_rectangle(system_brushes::menu_highlight(), 10, 10, 280, 50);
e.graphics().draw_string("Application is active", font(), system_brushes::control_text(), 10, 10);
} else {
e.graphics().fill_rectangle(system_brushes::control(), 10, 10, 280, 50);
e.graphics().draw_string("Application is inactive", font(), system_brushes::control_text(), 10, 10);
}
}
void wnd_proc(message& m) override {
// Listen for operating system messages.
switch (m.msg) {
// The WM_ACTIVATEAPP message occurs when the application becomes the active application or becomes inactive.
case WM_ACTIVATEAPP:
// The wparam value identifies what is occurring.
app_active = (as<int>(m.wparam) != 0);
// Invalidate to get new text painted.
invalidate();
break;
}
}
private:
bool app_active = true;
};
}
auto main() -> int {
application::run(wnd_proc_example::form1 {});
}
Defines a particular format for text, including font face, size, and style attributes....
Definition font.hpp:45
drawing::font_family font_family() const noexcept
Gets the xtd::drawing::font_family associated with this xtd::drawing::font.
static xtd::drawing::solid_brush control_text()
Gets a solid_brush that is the color of the control text.
static xtd::drawing::solid_brush menu_highlight()
Gets a solid_brush that is the color of the menu highlight.
static xtd::drawing::solid_brush control()
Gets a solid_brush that is the color of the control.
static void run()
Begins running a standard application message loop on the current thread, without a form.
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
void wnd_proc(message &message) override
Processes Windows messages.
void on_paint(paint_event_args &e) override
Raises the xtd::forms::control::paint event.
Provides data for the xtd::forms::control::paint event.
Definition paint_event_args.hpp:30
@ bold
Bold text.
Definition font_style.hpp:21
type_t as(any_object &o)
Casts a type into another type.
Definition __as_any_object.hpp:59
@ m
The M key.
Definition console_key.hpp:112
@ e
The E key.
Definition console_key.hpp:96
@ point
Specifies a printer's point (1/72 inch) as the unit of measure.
Definition graphics_unit.hpp:25
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition actions_system_images.hpp:10
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition texts.hpp:217
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Implements a Windows message.
Definition message.hpp:33