In the installer software package you need to display a long text. The text should be stretched in width, place the heading "USER AGREEMENT" in the center, make it bold, somewhere oblique, indent some and inject other beauty.

How to do it correctly from the code? Or is it easier to draw in a graphic editor, save the picture, and load it with a background (only it will have to be scrolled somehow - how?)?

PS: preferably of course from the code so that you can pull up the file and the text fell into place.

  • Use msdn richedit it supports formatted text. - nick_n_a
  • As an option is more complicated, OLE-window can display a Web-page with formatting. - nick_n_a
  • one
    For richedit, text can be jotted up in Word or wordpad (save RTF), as here is an example load. - nick_n_a
  • Is it necessary to use FILE to drive text into richedit? If the file is added to the end of the installer and it simply reads itself at startup, will it be possible to upload this content to richedit? Just the installer is formed on the server, and when a request to download the client receives a single installer file. - Iceman
  • No, you can write in the stream "your" load from memory. From memory the text is loaded fine. - nick_n_a

1 answer 1

Here are some sketches of how you can format text in rtf + richedit under windows.

// Функция взять-отдать текст int GetSetRtf(HWND Handle, char* data, int max){ DWORD st[5]; // можно использовать стандартную структуру это что б не искать библиотеки st[0] = (DWORD)&st[3]; st[1] = 0 ; st[2] = (DWORD)&EditStreamCallback; st[3] = (DWORD)data; st[4] = max; if (max == 0 ) { return ::SendMessageA(Handle,WM_USER + 73,2,(DWORD)&st); // EM_STREAMIN } else { ::SendMessageA(Handle,WM_USER + 74,2,(DWORD)&st); } } // Вспомагательный стрим DWORD __stdcall EditStreamCallback(char ** cookie,LPBYTE pbBuff, LONG cb, LONG FAR * pcb){ int x = (int)cookie[1]; int j = 0; if (x == 0 ) { while (*cookie[0] != 0 ) { pbBuff[x++] = *cookie[0]++; if (x>=cb) break; } if (x<cb) pbBuff[x] = 0; *pcb = x; } return 0; } // Как использовать CoInitialize(0); // Надо InitCommonControls(); // в msdn написано что надо в случае использования стилей окна, без работает LoadLibraryA("riched20.dll"); // Тоже надо, новая библиотека называется Msftedit.dll можно её HWND Edit1 = CreateWindow("RichEdit20A","(info)", WS_VISIBLE | WS_CHILD | ES_MULTILINE | ES_WANTRETURN |ES_LEFT, 151,32,600,200,w.Handle/*родительское окно*/,0,hInstance,0); GetSetRtf(Edit1, "{\\rtf1\\ansi\\ansicpg1251\\deff0\\deflang1049{\\fonttbl{\\f0\\fswiss\\fcharset0 Courier New;}}\\f0 62452}" , 0); 

Link to msdn

If you want to use pictures in rtf, then you need to connect another module in initialization. In most cases, these sketches are enough. Make the text not editable, and so on - set the styles ES _ ***.

It is also necessary to note that 20 is not the latest version - but everywhere 98 XP 2008 works. For Unicode, you need a W-version instead of A. There is somewhere a description of which version that can. I think the support of the old versions will not turn off soon. Many programs use richedit.

The linker does not need to say anything, because additional functions are not used. #include <richedit.h> does not always work well, you need to either correct a define, or connect #include <richedit20.h> . The second version (20) has a fairly good functionality, and the compiler does not always "connect" it.

A few words on the tags. \ need to be escaped with \\ two (but there are four of them in char *). \pard; -new (\ r \ n rtf ignores) \b \b0 put / remove bold. I will not prompt the link to a good help, but it is not difficult to find.

  • riched20.dll - MinGW does not know -lriched20. Can you tell me what you can pass to his linker? - Iceman
  • It does not need to link. It needs to be loaded using LoadLibrary in the code directly (in the WinMain section or FormCreate and so on) necessarily . An example that I wrote - you can not even connect richedit.h. Constats are in commctrl.h. I wrote a code sample. - nick_n_a
  • Probably more correct to say dynamic. Static links to exe-shnik directly. Here's another example with msdn msdn.microsoft.com/en-us/library/windows/desktop/ ... I did not write you InitCommonControls. - nick_n_a
  • Thank! Text brought. But it is necessary statically linkoval ... damn (( - Iceman
  • one
    This library comes with any bare Windows 98 / xp / 2003/2008. It is standard for Windows, on its base the Windows interface is built. In the system32 folder, it is always on par with kernel32.dll and others, even if an office is not installed. There will be no problems with it. - nick_n_a