-
Notifications
You must be signed in to change notification settings - Fork 0
/
Windows_splash_screen.cpp
67 lines (52 loc) · 2.23 KB
/
Windows_splash_screen.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
This Windows-only example demonstrates how to implement a simple splash screen that displays
an image from a Bitmap resource. It's the user's responsibility to build an executable that
contains a Bitmap resource, with whatever IDE or toolchain they're using (how to do that is
beyond the scope of this example). I have used Visual Studio to build and test the example.
*/
#include <nana/gui.hpp>
#include <nana/gui/timer.hpp>
#include <nana/paint/pixel_buffer.hpp>
#include <Windows.h>
#define IDB_SPLASH 103 // change this integer value to whatever the ID of the Bitmap resource is
using namespace nana;
void get_pixels_from_bmp_resource(unsigned height, RGBQUAD *buf, int resid)
{
HBITMAP bmp = reinterpret_cast<HBITMAP>(LoadImageA(GetModuleHandleA(0), MAKEINTRESOURCEA(resid), IMAGE_BITMAP, 0, 0, 0));
HDC memdc = CreateCompatibleDC(0);
SelectObject(memdc, bmp);
BITMAPINFO bmi = {0};
bmi.bmiHeader.biSize = sizeof bmi.bmiHeader;
GetDIBits(memdc, bmp, 0, 0, NULL, &bmi, DIB_RGB_COLORS);
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
GetDIBits(memdc, bmp, 0, height, buf, &bmi, DIB_RGB_COLORS);
DeleteDC(memdc);
DeleteObject(bmp);
}
int main()
{
// change these values to the actual width and height of the BMP image
const unsigned IMG_W{1920}, IMG_H{1080};
auto pixels{std::make_unique<RGBQUAD[]>(IMG_W * IMG_H)}; // allocate memory for pixel buffer
get_pixels_from_bmp_resource(IMG_H, pixels.get(), IDB_SPLASH); // IDB_SPLASH is the ID of the BMP resource
form fm; // main form
// This is the splash window. If its size is different than the size of the image,
// the image will be stretched to fill it.
form splash(API::make_center(1280, 720), appear::bald<>());
drawing{splash}.draw([&](paint::graphics &graph)
{
paint::pixel_buffer pxbuf(IMG_W, IMG_H);
pxbuf.put(reinterpret_cast<const unsigned char*>(pixels.get()), IMG_W, IMG_H, 32, IMG_W*sizeof(RGBQUAD), false);
rectangle r{point{0, 0}, pxbuf.size()};
rectangle rw{point{0, 0}, splash.size()};
pxbuf.stretch(r, graph.handle(), rw);
});
splash.show();
splash.events().unload([&] { fm.show(); });
timer t;
t.elapse([&] { splash.close(); });
t.interval(3000); // the splash window will be displayed for 3000 milliseconds
t.start();
exec();
}