static void DrawProperties(HWND hwnd, HDC hdc) { PropertiesLayout *layoutData = FindPropertyWindowByHwnd(hwnd); ScopedFont fontLeftTxt(GetSimpleFont(hdc, LEFT_TXT_FONT, LEFT_TXT_FONT_SIZE)); ScopedFont fontRightTxt(GetSimpleFont(hdc, RIGHT_TXT_FONT, RIGHT_TXT_FONT_SIZE)); HGDIOBJ origFont = SelectObject(hdc, fontLeftTxt); /* Just to remember the orig font */ SetBkMode(hdc, TRANSPARENT); ClientRect rcClient(hwnd); FillRect(hdc, &rcClient.ToRECT(), gBrushAboutBg); SetTextColor(hdc, WIN_COL_BLACK); /* render text on the left*/ SelectObject(hdc, fontLeftTxt); for (size_t i = 0; i < layoutData->Count(); i++) { PropertyEl *el = layoutData->At(i); DrawText(hdc, el->leftTxt, -1, &el->leftPos.ToRECT(), DT_RIGHT | DT_NOPREFIX); } /* render text on the right */ SelectObject(hdc, fontRightTxt); for (size_t i = 0; i < layoutData->Count(); i++) { PropertyEl *el = layoutData->At(i); RectI rc = el->rightPos; if (rc.x + rc.dx > rcClient.x + rcClient.dx - PROPERTIES_RECT_PADDING) rc.dx = rcClient.x + rcClient.dx - PROPERTIES_RECT_PADDING - rc.x; DrawText(hdc, el->rightTxt, -1, &rc.ToRECT(), DT_LEFT | DT_PATH_ELLIPSIS | DT_NOPREFIX); } SelectObject(hdc, origFont); }
static LRESULT OnPaint(HWND hwnd) { ClientRect rect(hwnd); DoubleBuffer buffer(hwnd, rect); HDC hdc = buffer.GetDC(); HBRUSH brushBg = CreateSolidBrush(COL_WINDOW_BG); HBRUSH brushWhite = GetStockBrush(WHITE_BRUSH); FillRect(hdc, &rect.ToRECT(), brushBg); PreviewBase *preview = (PreviewBase *)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (preview && preview->renderer) { int pageNo = GetScrollPos(hwnd, SB_VERT); RectD page = preview->renderer->GetPageRect(pageNo); if (!page.IsEmpty()) { rect.Inflate(-PREVIEW_MARGIN, -PREVIEW_MARGIN); float zoom = (float)min(rect.dx / page.dx, rect.dy / page.dy) - 0.001f; RectI onScreen = RectD(rect.x, rect.y, page.dx * zoom, page.dy * zoom).Round(); onScreen.Offset((rect.dx - onScreen.dx) / 2, (rect.dy - onScreen.dy) / 2); FillRect(hdc, &onScreen.ToRECT(), brushWhite); preview->renderer->Render(hdc, onScreen, pageNo, zoom); } } DeleteObject(brushBg); DeleteObject(brushWhite); PAINTSTRUCT ps; buffer.Flush(BeginPaint(hwnd, &ps)); EndPaint(hwnd, &ps); return 0; }
static void NotificationWndOnPaint(HWND hwnd, NotificationWnd *wnd) { PAINTSTRUCT ps; HDC hdcWnd = BeginPaint(hwnd, &ps); ClientRect rect(hwnd); DoubleBuffer buffer(hwnd, rect); HDC hdc = buffer.GetDC(); HFONT oldfnt = SelectFont(hdc, wnd->font); RECT rTmp = rect.ToRECT(); DrawFrameControl(hdc, &rTmp, DFC_BUTTON, DFCS_BUTTONPUSH); if (wnd->highlight) { SetBkMode(hdc, OPAQUE); SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT)); } else { SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT)); } rect.Inflate(-PADDING, -PADDING); RectI rectMsg = rect; if (wnd->hasProgress) rectMsg.dy -= PROGRESS_HEIGHT + PADDING / 2; if (wnd->hasCancel) rectMsg.dx -= 20; ScopedMem<WCHAR> text(win::GetText(hwnd)); rTmp = rectMsg.ToRECT(); DrawText(hdc, text, -1, &rTmp, DT_SINGLELINE | DT_NOPREFIX); if (wnd->hasCancel) { rTmp = GetCancelRect(hwnd).ToRECT(); DrawFrameControl(hdc, &rTmp, DFC_CAPTION, DFCS_CAPTIONCLOSE | DFCS_FLAT); } if (wnd->hasProgress) { rect.dx = wnd->progressWidth; rect.y += rectMsg.dy + PADDING / 2; rect.dy = PROGRESS_HEIGHT; PaintRect(hdc, rect); rect.x += 2; rect.dx = (wnd->progressWidth - 3) * wnd->progress / 100; rect.y += 2; rect.dy -= 3; HBRUSH brush = GetStockBrush(BLACK_BRUSH); rTmp = rect.ToRECT(); FillRect(hdc, &rTmp, brush); DeleteObject(brush); } SelectFont(hdc, oldfnt); buffer.Flush(hdcWnd); EndPaint(hwnd, &ps); }
RectI GetWorkAreaRect(RectI rect) { MONITORINFO mi = { 0 }; mi.cbSize = sizeof mi; HMONITOR monitor = MonitorFromRect(&rect.ToRECT(), MONITOR_DEFAULTTONEAREST); BOOL ok = GetMonitorInfo(monitor, &mi); if (!ok) SystemParametersInfo(SPI_GETWORKAREA, 0, &mi.rcWork, 0); return RectI::FromRECT(mi.rcWork); }
static void DrawProperties(HWND hwnd, HDC hdc) { PropertiesLayout *layoutData = FindPropertyWindowByHwnd(hwnd); ScopedFont fontLeftTxt(CreateSimpleFont(hdc, LEFT_TXT_FONT, LEFT_TXT_FONT_SIZE)); ScopedFont fontRightTxt(CreateSimpleFont(hdc, RIGHT_TXT_FONT, RIGHT_TXT_FONT_SIZE)); HGDIOBJ origFont = SelectObject(hdc, fontLeftTxt); /* Just to remember the orig font */ SetBkMode(hdc, TRANSPARENT); ClientRect rcClient(hwnd); RECT rTmp = rcClient.ToRECT(); ScopedGdiObj<HBRUSH> brushAboutBg(CreateSolidBrush(GetAboutBgColor())); FillRect(hdc, &rTmp, brushAboutBg); SetTextColor(hdc, WIN_COL_BLACK); /* render text on the left*/ SelectObject(hdc, fontLeftTxt); for (size_t i = 0; i < layoutData->Count(); i++) { PropertyEl *el = layoutData->At(i); const WCHAR *txt = el->leftTxt; rTmp = el->leftPos.ToRECT(); DrawText(hdc, txt, -1, &rTmp, DT_RIGHT | DT_NOPREFIX); } /* render text on the right */ SelectObject(hdc, fontRightTxt); for (size_t i = 0; i < layoutData->Count(); i++) { PropertyEl *el = layoutData->At(i); const WCHAR *txt = el->rightTxt; RectI rc = el->rightPos; if (rc.x + rc.dx > rcClient.x + rcClient.dx - PROPERTIES_RECT_PADDING) rc.dx = rcClient.x + rcClient.dx - PROPERTIES_RECT_PADDING - rc.x; rTmp = rc.ToRECT(); UINT format = DT_LEFT | DT_NOPREFIX | (el->isPath ? DT_PATH_ELLIPSIS : DT_WORD_ELLIPSIS); DrawText(hdc, txt, -1, &rTmp, format); } SelectObject(hdc, origFont); }
void WindowInfo::CreateInfotip(const WCHAR *text, RectI& rc, bool multiline) { if (str::IsEmpty(text)) { this->DeleteInfotip(); return; } TOOLINFO ti = { 0 }; ti.cbSize = sizeof(ti); ti.hwnd = this->hwndCanvas; ti.uFlags = TTF_SUBCLASS; ti.lpszText = (WCHAR *)text; ti.rect = rc.ToRECT(); if (multiline || str::FindChar(text, '\n')) SendMessage(this->hwndInfotip, TTM_SETMAXTIPWIDTH, 0, MULTILINE_INFOTIP_WIDTH_PX); else SendMessage(this->hwndInfotip, TTM_SETMAXTIPWIDTH, 0, -1); SendMessage(this->hwndInfotip, this->infotipVisible ? TTM_NEWTOOLRECT : TTM_ADDTOOL, 0, (LPARAM)&ti); this->infotipVisible = true; }
LRESULT CALLBACK NotificationWnd::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)\ { NotificationWnd *wnd = (NotificationWnd *)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (WM_ERASEBKGND == message) { // do nothing, helps to avoid flicker return TRUE; } if (WM_TIMER == message && TIMEOUT_TIMER_ID == wParam) { if (wnd->notificationCb) wnd->notificationCb->RemoveNotification(wnd); else delete wnd; return 0; } if (WM_PAINT == message && wnd) { PAINTSTRUCT ps; HDC hdcWnd = BeginPaint(hwnd, &ps); ClientRect rect(hwnd); DoubleBuffer buffer(hwnd, rect); HDC hdc = buffer.GetDC(); HFONT oldfnt = SelectFont(hdc, wnd->font); RECT rTmp = rect.ToRECT(); DrawFrameControl(hdc, &rTmp, DFC_BUTTON, DFCS_BUTTONPUSH); if (wnd->highlight) { SetBkMode(hdc, OPAQUE); SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT)); } else { SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT)); } rect.Inflate(-PADDING, -PADDING); RectI rectMsg = rect; if (wnd->hasProgress) rectMsg.dy -= PROGRESS_HEIGHT + PADDING / 2; if (wnd->hasCancel) rectMsg.dx -= 20; ScopedMem<WCHAR> text(win::GetText(hwnd)); rTmp = rectMsg.ToRECT(); DrawText(hdc, text, -1, &rTmp, DT_SINGLELINE | DT_NOPREFIX); if (wnd->hasCancel) { rTmp = GetCancelRect(hwnd).ToRECT(); DrawFrameControl(hdc, &rTmp, DFC_CAPTION, DFCS_CAPTIONCLOSE | DFCS_FLAT); } if (wnd->hasProgress) { rect.dx = wnd->progressWidth; rect.y += rectMsg.dy + PADDING / 2; rect.dy = PROGRESS_HEIGHT; PaintRect(hdc, rect); rect.x += 2; rect.dx = (wnd->progressWidth - 3) * wnd->progress / 100; rect.y += 2; rect.dy -= 3; HBRUSH brush = GetStockBrush(BLACK_BRUSH); rTmp = rect.ToRECT(); FillRect(hdc, &rTmp, brush); DeleteObject(brush); } SelectFont(hdc, oldfnt); buffer.Flush(hdcWnd); EndPaint(hwnd, &ps); return 0; } if (WM_SETCURSOR == message && wnd->hasCancel) { POINT pt; if (GetCursorPosInHwnd(hwnd, pt) && GetCancelRect(hwnd).Contains(PointI(pt.x, pt.y))) { SetCursor(LoadCursor(NULL, IDC_HAND)); return TRUE; } } if (WM_LBUTTONUP == message && wnd->hasCancel) { if (GetCancelRect(hwnd).Contains(PointI(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)))) { if (wnd->notificationCb) wnd->notificationCb->RemoveNotification(wnd); else delete wnd; return 0; } } return DefWindowProc(hwnd, message, wParam, lParam); }
LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam) { NPP instance = (NPP)GetWindowLongPtr(hWnd, GWLP_USERDATA); if (uiMsg == WM_PAINT) { InstanceData *data = (InstanceData *)instance->pdata; PAINTSTRUCT ps; HDC hDC = BeginPaint(hWnd, &ps); HBRUSH brushBg = CreateSolidBrush(COL_WINDOW_BG); HFONT hFont = GetSimpleFont(hDC, L"MS Shell Dlg", 14); bool isRtL = IsLanguageRtL(gTranslationIdx); // set up double buffering RectI rcClient = ClientRect(hWnd); DoubleBuffer buffer(hWnd, rcClient); HDC hDCBuffer = buffer.GetDC(); // display message centered in the window RECT rectClient = rcClient.ToRECT(); FillRect(hDCBuffer, &rectClient, brushBg); hFont = (HFONT)SelectObject(hDCBuffer, hFont); SetTextColor(hDCBuffer, RGB(0, 0, 0)); SetBkMode(hDCBuffer, TRANSPARENT); DrawCenteredText(hDCBuffer, rcClient, data->message, isRtL); // draw a progress bar, if a download is in progress if (0 < data->progress && data->progress <= 1) { SIZE msgSize; RectI rcProgress = rcClient; HBRUSH brushProgress = CreateSolidBrush(RGB(0x80, 0x80, 0xff)); GetTextExtentPoint32(hDCBuffer, data->message, (int)str::Len(data->message), &msgSize); rcProgress.Inflate(-(rcProgress.dx - msgSize.cx) / 2, -(rcProgress.dy - msgSize.cy) / 2 + 2); rcProgress.Offset(0, msgSize.cy + 4 + 2); RECT rectProgress = rcProgress.ToRECT(); FillRect(hDCBuffer, &rectProgress, GetStockBrush(WHITE_BRUSH)); RectI rcProgressAll = rcProgress; rcProgress.dx = (int)(data->progress * rcProgress.dx); rectProgress = rcProgress.ToRECT(); FillRect(hDCBuffer, &rectProgress, brushProgress); DeleteObject(brushProgress); ScopedMem<WCHAR> currSize(FormatSizeSuccint(data->currSize)); if (0 == data->totalSize || data->currSize > data->totalSize) { // total size unknown or bogus => show just the current size DrawCenteredText(hDCBuffer, rcProgressAll, currSize, isRtL); } else { ScopedMem<WCHAR> totalSize(FormatSizeSuccint(data->totalSize)); ScopedMem<WCHAR> s(str::Format(_TR("%s of %s"), currSize, totalSize)); DrawCenteredText(hDCBuffer, rcProgressAll, s, isRtL); } } // draw the buffer on screen buffer.Flush(hDC); DeleteObject(SelectObject(hDCBuffer, hFont)); DeleteObject(brushBg); EndPaint(hWnd, &ps); HWND hChild = FindWindowEx(hWnd, NULL, NULL, NULL); if (hChild) InvalidateRect(hChild, NULL, FALSE); } else if (uiMsg == WM_SIZE) { HWND hChild = FindWindowEx(hWnd, NULL, NULL, NULL); if (hChild) { ClientRect rcClient(hWnd); MoveWindow(hChild, rcClient.x, rcClient.y, rcClient.dx, rcClient.dy, FALSE); } } else if (uiMsg == WM_COPYDATA) { COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lParam; if (cds && 0x4C5255 /* URL */ == cds->dwData) { plogf("sp: NPN_GetURL %s", cds->dwData, (const char *)cds->lpData); gNPNFuncs.geturl(instance, (const char *)cds->lpData, "_blank"); return TRUE; } } return DefWindowProc(hWnd, uiMsg, wParam, lParam); }
void DrawCenteredText(HDC hdc, RectI& r, const WCHAR *txt, bool isRTL) { SetBkMode(hdc, TRANSPARENT); DrawText(hdc, txt, -1, &r.ToRECT(), DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX | (isRTL ? DT_RTLREADING : 0)); }
LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam) { InstanceData *data = (InstanceData *)GetWindowLongPtr(hWnd, GWLP_USERDATA); if (uiMsg == WM_PAINT) { PAINTSTRUCT ps; HDC hDC = BeginPaint(hWnd, &ps); HBRUSH brushBg = CreateSolidBrush(COL_WINDOW_BG); HFONT hFont = GetSimpleFont(hDC, _T("MS Shell Dlg"), 14); // set up double buffering RectI rcClient = ClientRect(hWnd); DoubleBuffer buffer(hWnd, rcClient); HDC hDCBuffer = buffer.GetDC(); // display message centered in the window FillRect(hDCBuffer, &rcClient.ToRECT(), brushBg); hFont = (HFONT)SelectObject(hDCBuffer, hFont); SetTextColor(hDCBuffer, RGB(0, 0, 0)); SetBkMode(hDCBuffer, TRANSPARENT); DrawCenteredText(hDCBuffer, rcClient, data->message); // draw a progress bar, if a download is in progress if (0 < data->progress && data->progress <= 1) { SIZE msgSize; RectI rcProgress = rcClient; HBRUSH brushProgress = CreateSolidBrush(RGB(0x80, 0x80, 0xff)); GetTextExtentPoint32(hDCBuffer, data->message, (int)str::Len(data->message), &msgSize); rcProgress.Inflate(-(rcProgress.dx - msgSize.cx) / 2, -(rcProgress.dy - msgSize.cy) / 2 + 2); rcProgress.Offset(0, msgSize.cy + 4 + 2); FillRect(hDCBuffer, &rcProgress.ToRECT(), GetStockBrush(WHITE_BRUSH)); RectI rcProgressAll = rcProgress; rcProgress.dx = (int)(data->progress * rcProgress.dx); FillRect(hDCBuffer, &rcProgress.ToRECT(), brushProgress); DeleteObject(brushProgress); ScopedMem<TCHAR> currSize(FormatSizeSuccint(data->currSize)); if (0 == data->totalSize || data->currSize > data->totalSize) { // total size unknown or bogus => show just the current size DrawCenteredText(hDCBuffer, rcProgressAll, currSize); } else { ScopedMem<TCHAR> totalSize(FormatSizeSuccint(data->totalSize)); ScopedMem<TCHAR> s(str::Format(_T("%s of %s"), currSize, totalSize)); DrawCenteredText(hDCBuffer, rcProgressAll, s); } } // draw the buffer on screen buffer.Flush(hDC); DeleteObject(SelectObject(hDCBuffer, hFont)); DeleteObject(brushBg); EndPaint(hWnd, &ps); HWND hChild = FindWindowEx(hWnd, NULL, NULL, NULL); if (hChild) InvalidateRect(hChild, NULL, FALSE); } else if (uiMsg == WM_SIZE) { HWND hChild = FindWindowEx(hWnd, NULL, NULL, NULL); if (hChild) { ClientRect rcClient(hWnd); MoveWindow(hChild, rcClient.x, rcClient.y, rcClient.dx, rcClient.dy, FALSE); } } return DefWindowProc(hWnd, uiMsg, wParam, lParam); }