A modeless message box. * Use AddMessageBoxText to add content and display * the window. On WM_CLOSE the window is hidden, not destroyed. */
| 525 | * the window. On WM_CLOSE the window is hidden, not destroyed. |
| 526 | */ |
| 527 | static INT_PTR CALLBACK |
| 528 | MessageDialogFunc(HWND hwnd, UINT msg, UNUSED WPARAM wParam, LPARAM lParam) |
| 529 | { |
| 530 | HICON hIcon; |
| 531 | HWND hmsg; |
| 532 | const UINT top_margin = DPI_SCALE(16); |
| 533 | const UINT side_margin = DPI_SCALE(20); |
| 534 | NMHDR *nmh; |
| 535 | |
| 536 | switch (msg) |
| 537 | { |
| 538 | case WM_INITDIALOG: |
| 539 | hIcon = LoadLocalizedIcon(ID_ICO_APP); |
| 540 | if (hIcon) |
| 541 | { |
| 542 | SendMessage(hwnd, WM_SETICON, (WPARAM)(ICON_SMALL), (LPARAM)(hIcon)); |
| 543 | SendMessage(hwnd, WM_SETICON, (WPARAM)(ICON_BIG), (LPARAM)(hIcon)); |
| 544 | } |
| 545 | hmsg = GetDlgItem(hwnd, ID_TXT_MESSAGE); |
| 546 | SetWindowText(hwnd, L"OpenVPN Messages"); |
| 547 | SendMessage(hmsg, |
| 548 | EM_SETMARGINS, |
| 549 | EC_LEFTMARGIN | EC_RIGHTMARGIN, |
| 550 | MAKELPARAM(side_margin, side_margin)); |
| 551 | if (LangFlowDirection() == 1) |
| 552 | { |
| 553 | LONG exstyle = GetWindowLong(hwnd, GWL_EXSTYLE); |
| 554 | SetWindowLong(hwnd, GWL_EXSTYLE, exstyle | WS_EX_RTLREADING | WS_EX_LAYOUTRTL); |
| 555 | exstyle = GetWindowLong(hmsg, GWL_EXSTYLE); |
| 556 | SetWindowLong(hmsg, GWL_EXSTYLE, exstyle | WS_EX_LEFTSCROLLBAR); |
| 557 | } |
| 558 | |
| 559 | enable_url_detection(hmsg); |
| 560 | |
| 561 | /* Position the window close to top right corner of the screen */ |
| 562 | RECT rc; |
| 563 | GetWindowRect(hwnd, &rc); |
| 564 | OffsetRect(&rc, -rc.left, -rc.top); |
| 565 | int ox = GetSystemMetrics(SM_CXSCREEN); /* screen size along x */ |
| 566 | ox -= rc.right + DPI_SCALE(rand() % 50 + 25); |
| 567 | int oy = DPI_SCALE(rand() % 50 + 25); |
| 568 | SetWindowPos(hwnd, HWND_TOP, ox > 0 ? ox : 0, oy, 0, 0, SWP_NOSIZE); |
| 569 | |
| 570 | return TRUE; |
| 571 | |
| 572 | case WM_SIZE: |
| 573 | hmsg = GetDlgItem(hwnd, ID_TXT_MESSAGE); |
| 574 | /* leave some space as top margin */ |
| 575 | SetWindowPos(hmsg, NULL, 0, top_margin, LOWORD(lParam), HIWORD(lParam) - top_margin, 0); |
| 576 | InvalidateRect(hwnd, NULL, TRUE); |
| 577 | break; |
| 578 | |
| 579 | /* set the whole client area background to white */ |
| 580 | case WM_CTLCOLORDLG: |
| 581 | case WM_CTLCOLORSTATIC: |
| 582 | return (INT_PTR)GetStockObject(WHITE_BRUSH); |
| 583 | break; |
| 584 |
nothing calls this directly
no test coverage detected