Answer the question
In order to leave comments, you need to log in
Convenient writing of UI on Win32 with animations?
Generally. I write UI for my software. I used to do it on MFC, but I got tired of the huge weight. Now I do with the help of dialog boxes and pure Win32. It turns out beautifully. And so - I decided to write my big project with a beautiful UI and low weight. But already at the stage of creating the interface and animations for it, I came across this:
(Creating a Subclass to track button hover. Buttons are made as STATIC in order to give them a beautiful look)
LRESULT CALLBACK STATIC1_Subclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
LRESULT CALLBACK STATIC2_Subclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
LRESULT CALLBACK STATIC3_Subclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
LRESULT CALLBACK STATIC4_Subclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
LRESULT CALLBACK STATIC5_Subclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
LRESULT CALLBACK STATIC6_Subclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
LRESULT CALLBACK STATIC7_Subclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
LRESULT CALLBACK STATIC8_Subclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
LRESULT CALLBACK STATIC9_Subclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
LRESULT CALLBACK STATIC10_Subclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
bool hoverStatic1, hoverStatic2, hoverStatic3, hoverStatic4, hoverStatic5,
hoverStatic6, hoverStatic7, hoverStatic8, hoverStatic9, hoverStatic10 = false;
void RestoreAll() {
if (hoverStatic1) {
hoverStatic1 = false;
InvalidateRect(GetDlgItem(hWnd, IDC_STATIC1), 0, 0);
}
if (hoverStatic2) {
hoverStatic2 = false;
InvalidateRect(GetDlgItem(hWnd, IDC_STATIC2), 0, 0);
}
if (hoverStatic3) {
hoverStatic3 = false;
InvalidateRect(GetDlgItem(hWnd, IDC_STATIC3), 0, 0);
}
if (hoverStatic4) {
hoverStatic4 = false;
InvalidateRect(GetDlgItem(hWnd, IDC_STATIC4), 0, 0);
}
if (hoverStatic5) {
hoverStatic5 = false;
InvalidateRect(GetDlgItem(hWnd, IDC_STATIC5), 0, 0);
}
if (hoverStatic6) {
hoverStatic6 = false;
InvalidateRect(GetDlgItem(hWnd, IDC_STATIC6), 0, 0);
}
if (hoverStatic7) {
hoverStatic7 = false;
InvalidateRect(GetDlgItem(hWnd, IDC_STATIC7), 0, 0);
}
if (hoverStatic8) {
hoverStatic8 = false;
InvalidateRect(GetDlgItem(hWnd, IDC_STATIC8), 0, 0);
}
if (hoverStatic9) {
hoverStatic9 = false;
InvalidateRect(GetDlgItem(hWnd, IDC_STATIC9), 0, 0);
}
if (hoverStatic10) {
hoverStatic10 = false;
InvalidateRect(GetDlgItem(hWnd, IDC_STATIC10), 0, 0);
}
}
case WM_CTLCOLORSTATIC:
{
HDC hStatic = (HDC)wParam;
SetTextColor(hStatic, RGB(255, 255, 255));
SetBkMode(hStatic, TRANSPARENT);
if (hoverStatic1 ||
hoverStatic2 ||
hoverStatic3 ||
hoverStatic4 ||
hoverStatic5 ||
hoverStatic6 ||
hoverStatic7 ||
hoverStatic8 ||
hoverStatic9 ||
hoverStatic10)
return (UINT)hbHoverStatic;
return (UINT)hbDlg;
}
Answer the question
In order to leave comments, you need to log in
Dump the entire boilerplate (this is the name of the stupid boilerplate code, why is it called so - stomp on the wiki) to the autogenerator. Qt uses its own xml generator -> boilerplate for this.
Actually, there are two ways, rdin, in my opinion, is stupid, and used by venda and android - this is to write a parser that will eat the description of the form during application execution and draw it, and the second, how Qt does it (described in the paragraph above)
The first method is terrible in that it is very difficult to write a parser that works in runtime without bugs and holes.
You can use wxWidgets instead of Qt. It develops thinner and worse, but if you know MFC, then Widgets will seem like old friends to you. And they use native controls, not their own, like Qt, so applications for Windows are both lightweight and not alien.
Plus - you can forget about digging in vinapi, like a bad dream.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question