| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| C++ and WinAPI Discuss Windows API related issues using C++ (and Visual C++). This is a non-MFC forum. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Rich Text box Questions
ok so I manage to create a RICHEDIT with:
[code]rtfctl = CreateWindow("RICHEDIT","text",WS_BORDER|WS_CHILD|WS_VISIBLE|ES_MULTILINE|WS_VSCROLL|WS_HSCROLL,10,10,300,300,MAINSS,0,hInstance,0);[\CODE] Now heres where I'm stuck at 1. I have it set to multiline and both scrollbars are visible. But the text won't go beyond horizontally. If I remove the multiline then it will go beyond it but then it will only be that one line. 2. How can I introduce syntax highlighting for it? In VB I would then find the word and use selcolor and similar functions to change the color but this method would slow down after a couple of lines. So I asked about it and someone told me I need to parse it. How do I go about doing that? Thanks |
|
#2
|
|||
|
|||
|
Re: Rich Text box Questions
Quote:
Code:
/* =================================================================
Write a character in the RTF control
================================================================= */
int RTFEDIT_putc(char c, COLORREF col, int h, int x)
{
CHARFORMAT cf; char buf[2]; // HDC hdc;
Edit_Enable(hRTF, FALSE);
ZeroMemory(&cf, sizeof(CHARFORMAT));
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_BOLD | CFM_COLOR | CFM_ITALIC |
CFM_SIZE | CFM_UNDERLINE;
cf.dwEffects = 0;
if (h > 0)
cf.yHeight = h;
else
cf.yHeight = 160;
cf.yOffset = 0;
if (col > 0)
cf.crTextColor = col;
else
cf.crTextColor = RGB(0,0,0);
Edit_SetSel(hRTF, x, x+1);
buf[0] = c; buf[1] = '\0';
SendMessage(hRTF, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf);
Edit_ReplaceSel(hRTF, buf);
Edit_SetSel(hRTF, 0, 0);
Edit_Enable(hRTF, TRUE);
return TRUE;
}
Quote:
Quote:
|
|
#3
|
|||
|
|||
|
Re: Rich Text box Questions
Quote:
Also how can I make the text go beyond the right side of the rtf textbox? Like I said once it gets there it goes to a new line. Thanks again |
|
#4
|
|||
|
|||
|
Re: Rich Text box Questions
__________________
Vlad - MS MVP [2007 - 2010] - www.FeinSoftware.com Convenience and productivity tools for Microsoft Visual Studio: FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more... |
|
#5
|
|||
|
|||
|
Re: Rich Text box Questions
|
|
#6
|
|||
|
|||
|
Re: Rich Text box Questions
ok so I took the code and added comments. Now the comments that I added, are the comments correct or wrong?
Also if you see //??? bla bla bla then that means I think I know what it is but still don't know or I don't know Thanks ![]() Code:
/* =================================================================
Write a character in the RTF control
================================================================= */
int RTFEDIT_putc(char c, COLORREF col, int h, int x)// Custom Function
{
CHARFORMAT cf; char buf[2]; // HDC hdc; // Declarations
Edit_Enable(hRTF, FALSE);// Disables the RTF Edit box
ZeroMemory(&cf, sizeof(CHARFORMAT)); //???
cf.cbSize = sizeof(CHARFORMAT); //???
cf.dwMask = CFM_BOLD | CFM_COLOR | CFM_ITALIC |CFM_SIZE | CFM_UNDERLINE;// What will be edited
cf.dwEffects = 0;//??? Effects like tranparency
if (h > 0)
cf.yHeight = h; ;//??? Hight of the text
else
cf.yHeight = 160;//??? Hight of the text
cf.yOffset = 0;//???
if (col > 0)
cf.crTextColor = col;// Sets the color from col
else
cf.crTextColor = RGB(0,0,0);// Sets the color Black
Edit_SetSel(hRTF, x, x+1);// Sets the Selection
buf[0] = c; buf[1] = '\0';//???
SendMessage(hRTF, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf);// Sends data to RTF Edit
Edit_ReplaceSel(hRTF, buf);// Replaces the selected text
Edit_SetSel(hRTF, 0, 0);// Sets the Selection to
Edit_Enable(hRTF, TRUE); // Enable the RTF Edit Box
return TRUE;// Returns to the main program
}
|
|
#7
|
|||
|
|||
|
Re: Rich Text box Questions
Code:
ZeroMemory(&cf, sizeof(CHARFORMAT)); //??? cf.cbSize = sizeof(CHARFORMAT); //??? Code:
cf.dwEffects = 0;//??? Effects like tranparency Code:
if (h > 0)
cf.yHeight = h; ;//??? Hight of the text
else
cf.yHeight = 160;//??? Hight of the text
cf.yOffset = 0;//???
Code:
buf[0] = c; buf[1] = '\0';//??? Edit_ReplaceSel(hRTF, buf);// Replaces the selected text Your other comments are correct. |
|
#8
|
|||
|
|||
|
Re: Rich Text box Questions
cool thanks for pointing that out
![]() Also I came across an error in Dev C++ its saying that CHARFORMAT does not name a type. So I think its saying that it doesn't exists like if I use handle instead of HWND. Do I need to include a library? |
|
#9
|
|||
|
|||
|
Re: Rich Text box Questions
I don't know about DevC++, but CHARFORMAT should be a macro that evaluates to CHARFORMATA or CHARFORMATW depending on the build. It should be defined in richedit.h:
Code:
#if (_RICHEDIT_VER >= 0x0200) #ifdef UNICODE #define CHARFORMAT CHARFORMATW #else #define CHARFORMAT CHARFORMATA #endif // UNICODE #else #define CHARFORMAT CHARFORMATA #endif // _RICHEDIT_VER >= 0x0200 |
|
#10
|
|||
|
|||
|
Re: Rich Text box Questions
I use dev_cpp.
At the begining of my file, I have: Code:
#include <windows.h> #include <windowsx.h> #include <richedit.h> #include <commdlg.h> I have Code:
if (!hRTFLib)
hRTFLib = LoadLibrary("RICHED32.DLL");
if (!hRTFLib) {
char szErr[255];
wsprintf(szErr, "LoadLibrary RICHED32.DLL failed. Error code %ld", GetLastError());
MessageBox(hWndParent, szErr, "Error", MB_OK );
hRTFLib = NULL;
return FALSE;
}
hRTF = CreateWindow("RICHEDIT", // Class Name of RTF Edit
"", // Text of edit control
WS_CHILD | WS_VISIBLE | ES_MULTILINE |
WS_VSCROLL | WS_BORDER |
ES_AUTOVSCROLL | ES_NOHIDESEL, // Window style
0, 0, // Initially create 0 size,
0, 0, // Main Wnd's WM_SIZE handler will resize
hWndParent, // Use main parent
(HMENU)0, // ID of zero (we don't care)
(HINSTANCE) GetWindowLong(hWndParent, GWL_HINSTANCE), // This app instance owns this window
NULL // Don't need data in WM_CREATE
);
SetFocus(hRTF);
...
|
|
#11
|
|||
|
|||
|
Re: Rich Text box Questions
Quote:
Yep I needed richedit.h Thanks for posting your code and helping me out with this. Appreciate it ! Quote:
Yea, I needed richedit.h. Thanks for letting me know! ^_^
|
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|