91
The concept / Re: Tutor_02 (C++ VS2022 GDImage64 tutorial)
« Last post by Patrice Terrier on June 20, 2023, 02:07:11 pm »I shall give it a try...
Among them, CreateWindowExW(0, GDImageClassName, Resource((WCHAR*) L"paintbrush.png"), ...), is the one used by every GDImage container.
Resource((WCHAR*) L"paintbrush.png"), means use this image to paint the background of the control, it works like the desktop wallpaper background in Windows.
IDR_APPLE RCDATA DISCARDABLE "res\\apple.png"
I strongly believe that, from the user's point of view, your application's appearance is the biggest single factor that can make the difference between your product and that of your competitors.
This is where WinLIFT comes in, it helps you to make the difference...
Patrice Terrier
'AUTHOR section -------------------------------------------------------------
"AUTHOR,|Skin design: <Patrice Terrier> E-mail: pterrier@zapsolution.com"
'"BACKGROUNDPATH, C:\Users\Public\Pictures\Sample Pictures
'BITMAP section -------------------------------------------------------------
"CTLBACK, @PATH@Busi\CTLBACK.jpg"
"MENUBAR, @PATH@Busi\MENUBAR.png"
"MENUBACK, @PATH@Busi\MENUBAK.png"
"BUTTON, @PATH@Busi\BUTTON.png"
"CAPTIONL, @PATH@Busi\CAPTIONL.png"
"CAPTIONM, @PATH@Busi\CAPTIONM.png"
"CAPTIONR, @PATH@Busi\CAPTIONR.png"
"SIDEL, @PATH@Busi\SIDEL.png"
"SIDER, @PATH@Busi\SIDER.png"
"RADIOBUT, @PATH@Busi\RADIOBUT.png"
"CHECKBUT, @PATH@Busi\CHECKBUT.png"
"CAPLED, @PATH@Busi\BTN_Led.png"
"PROGRESS, @PATH@Busi\PROGRESS.png"
"CPOPUPR, @PATH@Busi\CPOPUPR.png"
"BOTTOML, @PATH@Busi\BOTTOML.png"
"BOTTOMM, @PATH@Busi\BOTTOMM.png"
"BOTTOMR, @PATH@Busi\BOTTOMR.png"
"SYSCLOSE, @PATH@Busi\BTN_Close.png"
"SYSRESTORE, @PATH@Busi\BTN_Restore.png"
"SYSMINIMIZE, @PATH@Busi\BTN_Minimize.png"
"SYSMAXIMIZE, @PATH@Busi\BTN_Maximize.png"
"TABBUTTON, @PATH@Busi\TABBUTTON.png" ' 4.01
"HORZBAR, @PATH@Busi\HORZBAR.png" ' 4.20
"VERTBAR, @PATH@Busi\VERTBAR.png" ' 4.20
"SBPICTO, @PATH@Busi\SBPICTO.png" ' 4.20 ScrollBar picto
"DRAGWIN, @PATH@Busi\DRAGWIN.png" ' 4.17
"BTNTRACK, @PATH@Busi\BTNTRACK.png" ' 4.26 TrackBar thumb button
"MENUNAV, @PATH@Busi\MENUNAV.png" ' 4.35
"ICON_PROG, @PATH@Busi\ICON.png" ' 4.38
"ICON_ALERT, @PATH@Busi\ICON_Alert.png"' 4.38
"ICON_ERROR, @PATH@Busi\ICON_Error.png"' 4.38
"ICON_INFO, @PATH@Busi\ICON_Info.png" ' 4.38
"ICON_INPUT, @PATH@Busi\ICON_Input.png"' 4.38
"DLG_ALERT, @PATH@Busi\DLG_Alert.png" ' 4.38
"DLG_INPUT, @PATH@Busi\DLG_Input.png" ' 4.38
"DLG_INFO, @PATH@Busi\DLG_Info.png" ' 4.38
'SIZE & COORDINATES section -------------------------------------------------
"CYSTATUS, 18" ' SIZE: height of status bar. Std = 18
"CXSIZE, 18" ' SIZE: X size of system buttons. Std = 18
"CYSIZE, 18" ' SIZE: Y size of system button. Std = 18
"CXSYSBUT, 17" ' Sys buttons X offset from right side.
"CYSYSBUT, 10" ' Sys buttons Y offset from top side.
"CXCAPTEXT, 52" ' Caption text X offset from left side
"CYCAPTEXT, 12" ' SIZE: Y pos of caption text
"CXSYSLED, 40" ' Led X offset from right side.
"CYSYSLED, 40" ' Led Y offset from top side.
"XBUT3DBORDER, 04" ' Horizontal non stretched button border
"YBUT3DBORDER, 04" ' Vertical non stretched button border
"CXSYSICON, 18" ' SIZE: X pos of system icon.
"CYSYSICON, 09" ' SIZE: Y pos of system icon.
"ICONSIZE, 30" ' The icon size.
"PAINT_BORDER, 1" ' 0 = %PAINT_TILING_MODE, 1 = %PAINT_STRETCH_MODE
"PAINT_BACKGROUND, 1" ' 0 = %PAINT_TILING_MODE, 1 = %PAINT_STRETCH_MODE
"CYCAPTION, 48" ' 0 = Use size of CAPTIONM bitmap
"CXFRAMELEFT, 0" ' 0 = Use size of SIDEL bitmap
"CXFRAMERIGHT, 0" ' 0 = Use size of SIDER bitmap
"CYFRAMEBOTTOM, 0" ' 0 = Use size of BOTTOM bitmap
"OUTER_GLOW, 1" ' 0 = OFF, 1 = ON (Caption + PushButton)
"SKIN_ICON, 1" ' 0 = OFF, 1 = ON (Display skin icon on caption instead of default)
'COLOR section --------------------------------------------------------------
"CAPTIONTEXT, 255,240,240,240" ' RGB active caption text color.
"INACTIVECAPTIONTEXT, 255,128,128,128" ' RGB inactive caption text color.
"ACTIVECAPTION, 255,224,223,227" ' RGB active caption background color.
"INACTIVECAPTION, 255,235,235,235" ' RGB inactive caption background color.
"BTNTEXT, 255,230,230,230" ' RGB font color to use in button.
"POPMENUTEXT, 255,255,255,255" ' RGB PopMenu and Status text color.
"POPMENUHILITE, 255,48,48,48" ' RGB PopMenu 3D color.
"WINDOWTEXT, 255,230,230,230" ' RGB default main window text color.
"HILITEBACK, 255,209,209,209" ' RGB active item background in control.
"HILITETEXT, 255,64,64,64" ' RGB active item text in control.
"ACTIVMENU, 255,250,250,250" ' RGB active menu bar text color.
"INACTIVMENU, 255,133,138,133" ' RGB inactive menu bar text color.
"MENUBARHILITE, 255,250,250,250" ' 4.35 RGB menu bar hilite.
"GRAYEDCOLOR, 255,128,128,128" ' 4.53 for grayed text control.
"3DLEFTTOP, 255,58,58,58" ' RGB skDrawRect3D left top color.
"3DRIGHTBOTTOM, 255,126,126,126" ' RGB skDrawRect3D right bottom color.
"CARETCOLOR, 255,128,0,0" ' 4.36+ RGB caret color.
"EDITCOLORTEXT, 255,220,220,220" ' 4.01+ RGB Edit text color.
"EDITCOLORBACK, 255,048,048,048" ' 4.01+ RGB Edit background color.
"EDITCOLORRECTUP, 255,092,092,092" ' 4.01+ RGB Edit frame top/left color.
"EDITCOLORRECTDOWN, 255,092,092,092" ' 4.01+ RGB Edit frame bottom/right color.
"MENUBORDERFRAME, 255,32,32,32" ' 4.01+ RGB Menu frame border color.
"TBTRACKCOLOR, 255,160,160,160" ' 4.26 Track bar hilight color
"TBPOSCOLOR, 255,0,74,201" ' 4.26 Track bar progress color
"SHADOW, 255,32,32,32" ' RGB shadow item translucent color. 128,128,128
"TRANSLUCENCY, 70" ' Shadow translucency.
"MENUTRANSLUCENCY, 90" ' Menu translucency percentage
"USEFONT, Segoe UI Emoji" ' Font to use Trebuchet MS
"DWM_AERO, 0" ' 4.70, 0 = OFF, 1 = ON (Use VISTA-SEVEN Aero composited mode)
"DWM_LEFT, 00" ' 4.70, DWM left border size.
"DWM_TOP, 00" ' 4.70, DWM top border size.
"DWM_RIGHT, 00" ' 4.70, DWM right border size.
"DWM_BOTTOM, 00" ' 4.70, DWM bottom border size.
"AEROCOLOR, 000,000,000,000" ' 4.70, ARGB color to paint behind transparent background.
"BLURCOLOR, 000,000,000,000" ' 4.74, ARGB BLUR color.
"TIPCOLORTEXT, 255,255,255,255" ' 5.00+ TIP text color.
"TIPCOLORBACK, 255,128,128,128" ' 5.00+ TIP background color.
"SPLIT_VERT, @PATH@Busi\SplitV.png" ' 7.00
"SPLIT_HORZ, @PATH@Busi\SplitH.png" ' 7.00
long ZD_DrawTextToCtrl (IN HWND hCtrl, IN WCHAR* sUseText, IN long x, IN long y, IN DWORD ColrARGB,
IN WCHAR* sUseFont, IN long UseSize, IN long ObjID, IN long ZS_STYLE, IN short Use3D, IN long UseStrFormat) { // dllexport
return ZD_DrawTextToCtrlEx(hCtrl, sUseText, x, y, 0, 0, ColrARGB, sUseFont, UseSize, ObjID, ZS_STYLE, Use3D, UseStrFormat);
}
long ZD_DrawTextToCtrlEx (IN HWND hCtrl, IN WCHAR* UseText, IN long x, IN long y, IN long w, IN long h, IN DWORD ColrARGB,
IN WCHAR* UseFont, IN long UseSize, IN long ObjID, IN long ZS_STYLE, IN short Use3D, IN long UseStrFormat) { // dllexport
long nRet = 0;
if (IsWindow(hCtrl)) {
RECTF layoutRect = {0}, boundingBox = {0};
HDC hIC;
LONG_PTR graphics = 0, strFormat = 0;
long nExistItem = 0, nItem = 0;
long ObjectType = OBJECT_TEXT;
BYTE nPrivateFont = UsePrivateFont(UseFont);
nExistItem = DetectObjectItem(hCtrl, ObjectType, ObjID);
if (nExistItem > -1) { // if the object already exist { we ReUse it
nItem = nExistItem;
// We clear the previous font being used
if (g_zObj[nItem].curfont) { GdipDeleteFont(g_zObj[nItem].curfont); } // Delete the font object
if (g_zObj[nItem].privateFont == 0) { GdipDeleteFontFamily(g_zObj[nItem].fontfam); } // Delete the font family object
} else {
nItem = zGetNewItem();
}
GdipCreateStringFormat(NULL, NULL, strFormat);
if (nPrivateFont == 0) {
GdipCreateFontFamilyFromName(UseFont, 0, g_zObj[nItem].fontfam);
} else {
g_zObj[nItem].fontfam = LoadPrivateFont(UseFont); // Create a PrivateFont
}
GdipCreateFont(g_zObj[nItem].fontfam, (float) UseSize, FontStyleRegular, UnitPixel, g_zObj[nItem].curfont);
hIC = zDisplayDC();
GdipCreateFromHDC(hIC, graphics);
long codepointsFitted = 0, linesFilled = 0;
GdipMeasureString(graphics, UseText, lstrlen(UseText), g_zObj[nItem].curfont, layoutRect, strFormat, boundingBox, codepointsFitted, linesFilled);
GdipDeleteGraphics(graphics);
GdipDeleteStringFormat(strFormat);
DeleteDC(hIC);
g_zObj[nItem].hwnd = hCtrl;
g_zObj[nItem].objtype = MAKLNG(ObjectType, 0);
//wcscpy_s(g_zObj[nItem].usefont, UseFont); // WARNING 64 bytes only
// START 09-15-2017 WARNING 64 bytes only in zObj.usefont
long nLen = lstrlen(UseFont);
long nLenUsefont = strSize(g_zObj[nItem].usefont);
if (nLen > nLenUsefont) {
WCHAR PathName[MAX_PATH] = {0};
WCHAR FilName[MAX_PATH] = {0};
zSplitN(UseFont, &PathName[0], &FilName[0]);
if (nPrivateFont) {
UsePrivateFontPath(PathName, 1);
nPrivateFont = 2;
}
MoveMemory(g_zObj[nItem].usefont, FilName, min(lstrlen(FilName), nLenUsefont) * sizeof(WCHAR));
} else {
MoveMemory(g_zObj[nItem].usefont, UseFont, min(nLen, nLenUsefont) * sizeof(WCHAR));
}
// END 09-15-2017 WARNING 64 bytes only in zObj.usefont
g_zObj[nItem].usesize = UseSize;
g_zObj[nItem].argb = ColrARGB;
g_zObj[nItem].use3d = Use3D;
g_zObj[nItem].x1 = x;
g_zObj[nItem].y1 = y;
g_zObj[nItem].style = ZS_STYLE;
if (CheckStyle(ZS_STYLE, ZS_VISIBLE)) {
g_zObj[nItem].visible = TRUE;
}
if (nExistItem < 0) { // We put the new object on top of z-order
// and we keep it unchanged when it already exist
zUpdateZorder(hCtrl, nItem);
}
g_zObj[nItem].metacount = lstrlen(UseText); // 0;
MoveMemory(&g_zObj[nItem].metadata[0], UseText, g_zObj[nItem].metacount * sizeof(WCHAR));
if (w == 0) { w = (long)(boundingBox.right + 1.0f); }
if (h == 0) { h = (long)(boundingBox.bottom + 2.0f); }
g_zObj[nItem].x2 = w;
g_zObj[nItem].y2 = h;
g_zObj[nItem].id = ObjID;
g_zObj[nItem].strformat = UseStrFormat;
g_zObj[nItem].scale = 1.0f;
g_zObj[nItem].framecount = 0;
g_zObj[nItem].frametouse = 0;
g_zObj[nItem].privateFont = nPrivateFont;
nRet = -1;
}
return nRet;
}
void ZD_SetObjectUse3Dshadow (IN long ObjID, IN short Use3D) { // dllexport
long nItem = zItemFromID(ObjID);
if (nItem > -1) { g_zObj[nItem].use3d = Use3D; }
}
long ZD_DrawTextToDC (IN HDC hDC, IN WCHAR* UseText, IN long x, IN long y, IN DWORD ColrARGB,
IN WCHAR* UseFont, IN long UseSize, IN short Use3D, IN long UseStrFormat) { // dllexport
long nRet = 0;
RECTF layoutRect = { 0 };
RECTF boundingBox = { 0 };
LONG_PTR graphics = 0, TempFont = 0, fontfam = 0, strFormat = 0;
wstring sUseText = (WCHAR*) UseText;
BYTE nPrivateFont = UsePrivateFont(UseFont);
// Create matching font
if (nPrivateFont == 0) {
GdipCreateFontFamilyFromName(UseFont, 0, fontfam);
} else {
fontfam = LoadPrivateFont(UseFont); // Create a PrivateFont
}
if (fontfam) {
GdipCreateFont(fontfam, (float) UseSize, FontStyleRegular, UnitPixel, TempFont);
if (TempFont) {
// Shadow offset use NULL if you don't want a shadow,
// use positive value to display shadow right, negative value to display shadow left
// Draw the string
GdipCreateStringFormat(0, 0, strFormat);
GdipCreateFromHDC(hDC, graphics);
sUseText = TRIM$(sUseText, $SPACE);
long codepointsFitted = 0, linesFilled = 0, nLen = (long) sUseText.length();
GdipMeasureString(graphics, (WCHAR*) sUseText.c_str(), nLen, TempFont, layoutRect, strFormat, boundingBox, codepointsFitted, linesFilled);
GdipDeleteStringFormat(strFormat);
long xWidth = roundL(boundingBox.right + 0.5f);
long yHeight = roundL(boundingBox.bottom + 1.5f);
if (Use3D) { // Fly!
RECT rb; SetRect(&rb, x, y, x + xWidth, y + yHeight);
BlurTextPlus(hDC, UseText, rb, TempFont, 4, (LONG_PTR)UseStrFormat);
}
nRet = DrawStringFormatedEx(graphics,
(WCHAR*) sUseText.c_str(),
x, y,
xWidth,
yHeight,
ColrARGB,
TextRenderingHintAntiAlias,
TempFont,
Use3D,
UseStrFormat);
GdipDeleteGraphics(graphics);
GdipDeleteFont(TempFont); // Delete the font object
}
if (nPrivateFont == 0) { GdipDeleteFontFamily(fontfam); } // Delete the font family object
}
return nRet;
}
void BlurTextPlus(IN HDC hDC, IN WCHAR* sTxt, IN RECT &rb, IN LONG_PTR UseFont, IN long TextRendering, IN LONG_PTR nStrFormat) {
BITMAP bm = {0};
long nRet = 0, P = 0, nDiv = 0, xDiv = 0, yDiv = 0, xWidth = 0, yHeight = 0, UseColor = 0;
LONG_PTR graphics = 0, img = 0, imgAttr = 0, lpCallback = 0, callbackdata = 0;
HDC hDC1 = 0, hDC2 = 0;
HBITMAP hBM1 = 0, hBM2 = 0;
float sT = 0.0f;
RECT rc;
BYTE Alpha = 0;
nDiv = 3; // 4; // Blur level
xWidth = Width(rb);
yHeight = Height(rb);
SetRect(&rc, 0, 0, xWidth, yHeight);
xDiv = (long) (xWidth / nDiv);
yDiv = (long) (yHeight / nDiv);
hDC1 = CreateCompatibleDC(hDC);
hBM1 = zCreateDIBSection(hDC1, xWidth, yHeight, 32);
HGDIOBJ oldBM1 = SelectObject(hDC1, hBM1);
UseColor = ZD_ARGB(192, 10, 10, 10);
if (GdipCreateFromHDC(hDC1, graphics) == 0) {
DrawStringFormatedEx(graphics, sTxt, 0, 0, xWidth, yHeight, UseColor, TextRendering, UseFont, 0, nStrFormat);
GdipDeleteGraphics(graphics);
}
// Copy from DC source
hDC2 = CreateCompatibleDC(hDC);
hBM2 = zCreateDIBSection(hDC2, xDiv, yDiv, 32);
HGDIOBJ oldBM2 = SelectObject(hDC2, hBM2);
// Perform reduction
if (GdipCreateFromHDC(hDC2, graphics) == 0) {
img = zBitmapToImage(hDC1);
GdipSetInterpolationMode(graphics, 2);
GdipDrawImageRectRectI(graphics, img, 0, 0, xDiv, yDiv, 0, 0, xWidth, yHeight, 2, imgAttr, lpCallback, callbackdata);
GdipDeleteGraphics(graphics);
GdipDisposeImage(img);
}
DeleteObject(hBM1);
SelectObject(hDC1, oldBM1); DeleteDC(hDC1);
// Blur from reduction
if (GdipCreateFromHDC(hDC, graphics) == 0) {
//Alpha = zGetAValue(UseColor);
Alpha = LOBYTE((UseColor) >> 24);
// Use this to setup the transparency level (changing the alpha channel)
if (Alpha < 255) {
GetObject(hBM2, sizeof(bm), &bm);
sT = (float) (min(254, Alpha) / 255.0f);
BYTE* A = (BYTE*) bm.bmBits;
long nBitCount = bm.bmWidth * bm.bmHeight * 4 + 3;
for (P = 3; P < nBitCount; P += 4) {
A[P] = (BYTE) (A[P] * sT);
}
}
img = zBitmapToImage(hDC2);
GdipSetInterpolationMode(graphics, 2);
for (P = 0; P < min(max(nDiv - 1, 1), 4); P++) {
nRet = GdipDrawImageRectRectI(graphics, img, rb.left, rb.top, xWidth, yHeight, 0, 0, xDiv, yDiv, 2, imgAttr, lpCallback, callbackdata);
}
GdipDeleteGraphics(graphics);
GdipDisposeImage(img);
}
DeleteObject(hBM2);
SelectObject(hDC2, oldBM2); DeleteDC(hDC2);
}