Improved control transparency on Windows.

This commit is contained in:
Pietro Gagliardi 2014-08-28 10:30:53 -04:00
parent 72c56d6e16
commit ff4f0ec25e
3 changed files with 47 additions and 4 deletions

View File

@ -89,10 +89,13 @@ BOOL sharedWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *
*lResult = forwardNotify(hwnd, uMsg, wParam, lParam); *lResult = forwardNotify(hwnd, uMsg, wParam, lParam);
return TRUE; return TRUE;
case WM_CTLCOLORSTATIC: case WM_CTLCOLORSTATIC:
case WM_CTLCOLORBTN:
exstyle = (DWORD) GetWindowLongPtrW((HWND) lParam, GWL_EXSTYLE); exstyle = (DWORD) GetWindowLongPtrW((HWND) lParam, GWL_EXSTYLE);
if ((exstyle & WS_EX_TRANSPARENT) != 0) { // TODO clean this up
{// if ((exstyle & WS_EX_TRANSPARENT) != 0) {
if (SetBkMode((HDC) wParam, TRANSPARENT) == 0) if (SetBkMode((HDC) wParam, TRANSPARENT) == 0)
xpanic("error setting transparent background mode to Labels", GetLastError()); xpanic("error setting transparent background mode to Labels", GetLastError());
paintControlBackground((HWND) lParam, (HDC) wParam);
*lResult = (LRESULT) hollowBrush; *lResult = (LRESULT) hollowBrush;
return TRUE; return TRUE;
} }
@ -100,3 +103,35 @@ BOOL sharedWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *
} }
return FALSE; return FALSE;
} }
void paintControlBackground(HWND hwnd, HDC dc)
{
HWND parent;
RECT r;
POINT p;
int saved;
// TODO traverse deeper if a groupbox
// TODO implement WM_PRINTCLIENT in window_windows.c
parent = GetParent(hwnd);
if (parent == NULL)
xpanic("error getting parent container of control in paintControlBackground()", GetLastError());
parent = GetParent(parent);
if (parent == NULL)
xpanic("error getting parent control of control in paintControlBackground()", GetLastError());
if (GetWindowRect(hwnd, &r) == 0)
xpanic("error getting control's window rect in paintControlBackground()", GetLastError());
// the above is a window rect; convert to client rect
p.x = r.left;
p.y = r.top;
if (ScreenToClient(parent, &p) == 0)
xpanic("error getting client origin of control in paintControlBackground()", GetLastError());
saved = SaveDC(dc);
if (saved == 0)
xpanic("error saving DC info in paintControlBackground()", GetLastError());
if (SetWindowOrgEx(dc, p.x, p.y, NULL) == 0)
xpanic("error moving window origin in paintControlBackground()", GetLastError());
SendMessageW(parent, WM_PRINTCLIENT, (WPARAM) dc, PRF_CLIENT);
if (RestoreDC(dc, saved) == 0)
xpanic("error restoring DC info in paintControlBackground()", GetLastError());
}

View File

@ -100,6 +100,7 @@ extern void setWindowText(HWND, LPWSTR);
extern void updateWindow(HWND); extern void updateWindow(HWND);
extern void *getWindowData(HWND, UINT, WPARAM, LPARAM, LRESULT *, void (*)(void *, HWND)); extern void *getWindowData(HWND, UINT, WPARAM, LPARAM, LRESULT *, void (*)(void *, HWND));
extern BOOL sharedWndProc(HWND, UINT, WPARAM, LPARAM, LRESULT *); extern BOOL sharedWndProc(HWND, UINT, WPARAM, LPARAM, LRESULT *);
extern void paintControlBackground(HWND, HDC);
// tab_windows.go // tab_windows.go
extern LPWSTR xWC_TABCONTROL; extern LPWSTR xWC_TABCONTROL;

View File

@ -116,13 +116,20 @@ func (tw *testwin) addfe() {
OpenFile(tw.w, tw.openFile) OpenFile(tw.w, tw.openFile)
}) })
tw.fnlabel = NewStandaloneLabel("<no file selected>") tw.fnlabel = NewStandaloneLabel("<no file selected>")
tw.festack = NewVerticalStack(tw.festart, tw.felabel, tw.festop, tw.festack = NewVerticalStack(tw.festart,
tw.felabel,
tw.festop,
NewCheckbox("This is a checkbox test"),
Space(), Space(),
tw.vedit, tw.vedit,
Space(), Space(),
NewCheckbox("This is a checkbox test"),
tw.openbtn, tw.fnlabel) tw.openbtn, tw.fnlabel)
tw.festack.SetStretchy(3) tw.festack.SetStretchy(4)
tw.festack.SetStretchy(5) tw.festack.SetStretchy(6)
tw.festack = NewHorizontalStack(tw.festack, Space())
tw.festack.SetStretchy(0)
tw.festack.SetStretchy(1)
tw.t.Append("Foreign Events", tw.festack) tw.t.Append("Foreign Events", tw.festack)
} }