Add new message to the message box window */
| 436 | |
| 437 | /* Add new message to the message box window */ |
| 438 | static void |
| 439 | AddMessageBoxText(HWND hwnd, const wchar_t *text, const wchar_t *title, const wchar_t *from) |
| 440 | { |
| 441 | HWND hmsg = GetDlgItem(hwnd, ID_TXT_MESSAGE); |
| 442 | DWORD align[2] = { PFA_LEFT, PFA_RIGHT }; /* default alignments for text and title */ |
| 443 | |
| 444 | if (LangFlowDirection() == 1) |
| 445 | { |
| 446 | align[0] = PFA_RIGHT; |
| 447 | align[1] = PFA_LEFT; |
| 448 | } |
| 449 | |
| 450 | /* Start adding new message at the top */ |
| 451 | SendMessage(hmsg, EM_SETSEL, 0, 0); |
| 452 | |
| 453 | CHARFORMATW cfm = { .cbSize = sizeof(CHARFORMATW) }; |
| 454 | |
| 455 | /* save current alignment */ |
| 456 | PARAFORMAT pf = { .cbSize = sizeof(PARAFORMAT) }; |
| 457 | SendMessage(hmsg, EM_GETPARAFORMAT, 0, (LPARAM)&pf); |
| 458 | WORD pf_align_saved = pf.dwMask & PFM_ALIGNMENT ? pf.wAlignment : align[0]; |
| 459 | pf.dwMask |= PFM_ALIGNMENT; |
| 460 | |
| 461 | if (from && wcslen(from)) |
| 462 | { |
| 463 | /* Change font to italics */ |
| 464 | SendMessage(hmsg, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cfm); |
| 465 | cfm.dwMask |= CFM_ITALIC; |
| 466 | cfm.dwEffects |= CFE_ITALIC; |
| 467 | |
| 468 | SendMessage(hmsg, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfm); |
| 469 | /* Align to right */ |
| 470 | pf.wAlignment = align[1]; |
| 471 | SendMessage(hmsg, EM_SETPARAFORMAT, 0, (LPARAM)&pf); |
| 472 | SendMessage(hmsg, EM_REPLACESEL, FALSE, (LPARAM)from); |
| 473 | SendMessage(hmsg, EM_REPLACESEL, FALSE, (LPARAM)L"\n"); |
| 474 | } |
| 475 | |
| 476 | pf.wAlignment = align[0]; |
| 477 | SendMessage(hmsg, EM_SETPARAFORMAT, 0, (LPARAM)&pf); |
| 478 | |
| 479 | if (title && wcslen(title)) |
| 480 | { |
| 481 | /* Increase font size and set font color for title of the message */ |
| 482 | SendMessage(hmsg, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cfm); |
| 483 | cfm.dwMask |= CFM_SIZE | CFM_COLOR; |
| 484 | cfm.yHeight = MulDiv(cfm.yHeight, 4, 3); /* scale up by 1.33: 12 pt if default is 9 pt */ |
| 485 | cfm.crTextColor = RGB(0, 0x33, 0x99); |
| 486 | cfm.dwEffects = 0; |
| 487 | |
| 488 | SendMessage(hmsg, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfm); |
| 489 | SendMessage(hmsg, EM_REPLACESEL, FALSE, (LPARAM)title); |
| 490 | SendMessage(hmsg, EM_REPLACESEL, FALSE, (LPARAM)L"\n"); |
| 491 | } |
| 492 | |
| 493 | /* Revert to default font and set the text */ |
| 494 | SendMessage(hmsg, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cfm); |
| 495 | SendMessage(hmsg, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfm); |
no test coverage detected