Repository navigation
Expand file tree
/
Copy pathMenuBitmap.h
More file actions
43 lines (34 loc) · 1.64 KB
/
Copy pathMenuBitmap.h
File metadata and controls
43 lines (34 loc) · 1.64 KB
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
// Turning downloaded image bytes into bitmaps a tray menu can show.
#pragma once
#include <windows.h>
#include <string>
#include <vector>
// Owns the bitmaps a menu points at. A menu never takes ownership of an
// hbmpItem, and DestroyMenu leaves it alone, so the handles have to outlive
// TrackPopupMenu and be deleted afterwards.
class MenuBitmaps {
public:
MenuBitmaps() = default;
~MenuBitmaps() { Clear(); }
MenuBitmaps(const MenuBitmaps&) = delete;
MenuBitmaps& operator=(const MenuBitmaps&) = delete;
// Returns the same handle, so it can be used inline in a MENUITEMINFOW.
HBITMAP Keep(HBITMAP bitmap);
void Clear();
private:
std::vector<HBITMAP> bitmaps_;
};
// Physical-pixel size for a menu thumbnail on the monitor the menu will pop up
// on. Pass the size you designed at 96 dpi.
SIZE MenuThumbnailSize(POINT screenPoint, int logicalWidth, int logicalHeight);
// The size Windows itself uses for the small check/icon column, same monitor.
SIZE MenuCheckSize(POINT screenPoint);
// Decodes JPEG (or PNG/BMP/GIF) bytes into a 32bpp top-down DIB section with
// premultiplied alpha, centre-cropped to size. That is the only shape a themed
// menu blends correctly. Throws AppError. COM must already be initialized on
// the calling thread.
HBITMAP CreateMenuThumbnail(const std::string& bytes, SIZE size);
// Shrinks an image to fit inside maxWidth x maxHeight, keeping its aspect, and
// returns it as JPEG bytes. Used to cache a small stand-in for a full-size
// picture so the menu never has to decode the original. Throws AppError.
std::string EncodeThumbnailJpeg(const std::string& bytes, int maxWidth, int maxHeight);