Here is the code to add a close button into the ToastWindow
LRESULT CALLBACK ToastCallBack(IN HWND hWnd, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam) {
LRESULT nRet = FALSE; // Do not stop the event processing in GDImage.
long nID = ZI_MouseOverObjectID();
switch (uMsg) {
case WM_LBUTTONUP:
if (nID == ID_TOAST_HIDE) { HideToast(); }
break;
}
return nRet;
}
void ToastWindow(IN WCHAR* UseIcon, IN WCHAR* UseCaption, IN WCHAR* UseComment) { //IN HWND hParent, IN HINSTANCE hInstance) {
if (gP.hToast) { DestroyWindow(gP.hToast); }
WCHAR zFont[MAX_PATH]; ClearMemory(zFont, sizeof(zFont));
Path_Combine(zFont, skSkinFolder(), L"trebuc.ttf");
// We compute the correct size
long CommentW = 0, CommentH = 0;
ZD_GetTextBound(UseComment, zFont, 14, CommentW, CommentH, ZD_TextHorzUp, FontStyleRegular); // We use horizontal orientation
long UseW = CommentW + 4;
long UseH = CommentH;
long CaptionW = 0, CaptionH = 0;
ZD_GetTextBound(UseCaption, zFont, 18, CaptionW, CaptionH, ZD_TextHorzUp, FontStyleRegular); // We use horizontal orientation
UseW = max(UseW, CaptionW + 4);
UseH += CaptionH;
long bmW = 0, bmH = 0;
HBITMAP hBitmap = ZI_CreateBitmapFromFile(UseIcon, bmW, bmH);
UseW = 4 + bmW + 4 + UseW + 4;
UseH = 4 + max(bmH, UseH) + 4 + 4;
// Here we create the compositing array
// Note: The z-order composition will match the array order, the lower indice at the bottom, the higher on top.
const long nCount = 5;
ZOBJECT arrayobj[nCount]; ClearMemory(&arrayobj[0], sizeof(arrayobj));
ZI_CreateBitmapObject(arrayobj[2], 4, 4, hBitmap, ZD_ARGB(255, 0,0,0), ZS_VISIBLE);
ZI_CreateTextObject(arrayobj[3], UseCaption, 4 + bmW + 4, 4, CaptionW + 8, CaptionH + 8, ZD_ARGB(255, 255,240,140), zFont, 18, ZS_VISIBLE, 1, StringAlignmentNear, FontStyleRegular);
ZI_CreateTextObject(arrayobj[4], UseComment, 4 + bmW + 4, 4 + CaptionH + 4, CommentW + 8, CommentH + 8, ZD_ARGB(255, 255,213,83), zFont, 14, ZS_VISIBLE, 1, StringAlignmentNear, FontStyleRegular);
ZI_CreateRectangleObject(arrayobj[1], 1, 1, UseW - 3, UseH - 3, ZD_ARGB(255, 255,240,140), 1, ZS_VISIBLE | ZS_DRAFT, ZD_DRAW_OUTLINE, 0);
ZI_CreateRectangleObject(arrayobj[0], 0, 0, UseW, UseH, ZD_ARGB(128, 128,128,128), 0, ZS_VISIBLE | ZS_DRAFT, ZD_DRAW_FILLED, 0);
WCHAR zFile[MAX_PATH]; ClearMemory(zFile, sizeof(zFile));
Path_Combine(zFile, zGetTempPath(), L"zToast.png");
//Path_Combine(zFile, EXEpath(), L"zToast.png");
ZI_CreateImageComposited(zFile, UseW, UseH, arrayobj, nCount);
RECT rw; GetWindowRect(gP.hGL, &rw);
long x = rw.right - UseW;
long y = rw.bottom - UseH;
// This API requires the use of a file name, rather than a bitmap handle. It can create/use a region on the fly.
HWND hWnd = ZI_CreateWindowFromImage(WS_POPUP, zFile, x, y, gP.hGL, 0, 0, 0);
if (IsWindow(hWnd)) {
ZI_DwmEnable(hWnd);
WCHAR zResource[MAX_PATH]; ClearMemory(zResource, sizeof(zResource));
Path_Combine(zResource, skSkinFolder(), L"T_Close.png");
long w = 0, h = 0;
hBitmap = ZI_CreateBitmapFromFile(zResource, w, h);
x = UseW - w - 8; y = 8;
long nID = ID_TOAST_HIDE;
ZD_DrawBitmapToCtrl(hWnd, x, y, hBitmap, ZD_ColorARGB(255, 0), nID, ZS_VISIBLE);
ZD_SetObjectLocked(nID, TRUE);
//MonitorMessages(hWnd, (LONG_PTR) ToastCallBack);
ZI_EventMessageEx(hWnd, (LONG_PTR) ToastCallBack, WM_LBUTTONUP, TRUE);
gP.hToast = hWnd;
}
zKillFile(zFile);
}
The new close button is attached to this post (to put into the Reader folder).
Add the new constant below line 131 in constants.h
#define ID_LAST ID_GAUGE_GPU
#define ID_TOAST_HIDE ID_LAST + 1