|
Hello!
I cannot solve two problems with my Rich Edit control (that I use in a dialog form):
1. How can I make it accept Tab keys. When I press the Tab key now my Rich Edit just looses focus instead of printing '\t'.
2. When I select some text with images or other OLE objects in some application, copy it and than paste in my Rich Edit, all the copied object (text, images, ole) appears in it. But I need to paste only text. I know of CRichEditCtrl::PasteSpecial(CF_TEXT) but don't know where to use it.
Thank you in advance.
|
|
|
|
|
Reunion wrote: 1. How can I make it accept Tab keys. When I press the Tab key now my Rich Edit just looses focus instead of printing '\t'.
Just a guess, but what does ctrl+tab do?
Reunion wrote: I know of CRichEditCtrl::PasteSpecial(CF_TEXT) but don't know where to use it.
Use it at the point in which you wish to add text to the clipboard.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Ctrl+tab does what I need, but how can I do the same with just tab?
|
|
|
|
|
Try subclassing the control. Then add a handler for the WM_GETDLGCODE message, and return DLGC_WANTTAB from it.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
I'll try today. And what about PasteSpecial?
|
|
|
|
|
Reunion wrote: And what about PasteSpecial?
What about it?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
First let me thank you for answering my question about tabs. Processing of WM_GETDLGCODE really helped. Thank you!
Well, one more thing I want to do is to control the data that a user pastes to the control (Rich Edit): I want only text to be pasted in the control (even if in clipboard there is other data with text - just like Notepad does it). I know that there is PasteSpecial function that can be called with CF_TEXT parameter. But where to call to control all the pasteing text?
|
|
|
|
|
Reunion wrote: I know that there is PasteSpecial function...
This method actually does the pasting from withing your code. It has no control over what the user might try to paste into it. If you are only interested in text, why not just use a regular edit control?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Because I need to make text colorizing. But it must be text, not tables or images or something else. I know for sure that there is a way to control the "cut-copy-paste" process... But how? MSDN says that PasteSpecial will help, but where to call it? I tried to catch WM_PASTE but my class, derived from CRichEditCtrl, can't catch it. Why???
|
|
|
|
|
In your derived class, add the following:
void CMyRichEditCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
bool bPasted = false;
if (toupper(nChar) == 'V' && GetAsyncKeyState(VK_CONTROL))
{
if (IsClipboardFormatAvailable(CF_TEXT))
{
if (OpenClipboard() != FALSE)
{
HANDLE h = GetClipboardData(CF_TEXT);
if (h != NULL)
{
LPTSTR lptstr = (LPTSTR) GlobalLock(h);
if (lptstr != NULL)
{
SetWindowText(lptstr);
GlobalUnlock(lptstr);
bPasted = true;
}
}
CloseClipboard();
}
}
}
if (! bPasted)
CRichEditCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Very well done! Thank you! There is only one thing that should be added to
if (toupper(nChar) == 'V' && GetAsyncKeyState(VK_CONTROL))
- its checking for SHIFT-INS combination.
Thank you very much!
|
|
|
|
|
Reunion wrote: There is only one thing that should be added...its checking for SHIFT-INS combination.
Correct. Not once have I ever used that combination to insert text.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
One more and final: in your case the new text replaces the whole text in the control. So it's better to use ReplaceSel function instead of SetWindowText. Now everything is correct. Here is the final code:
<br />
void CRichEditCtrlEx::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)<br />
{<br />
bool bPasted = false;<br />
if((toupper(nChar) == 'V' && GetAsyncKeyState(VK_CONTROL)) || (nChar == VK_INSERT && GetAsyncKeyState(VK_SHIFT)))<br />
if(IsClipboardFormatAvailable(CF_TEXT))<br />
if(OpenClipboard() != FALSE){<br />
HANDLE h = GetClipboardData(CF_TEXT);<br />
if(h != NULL){<br />
LPTSTR lptstr = (LPTSTR)GlobalLock(h);<br />
if(lptstr != NULL){<br />
ReplaceSel(lptstr);<br />
GlobalUnlock(lptstr);<br />
bPasted = true;<br />
}<br />
}<br />
CloseClipboard();<br />
}<br />
if(!bPasted)<br />
CRichEditCtrl::OnKeyDown(nChar, nRepCnt, nFlags);<br />
}<br />
Thank you once more!
|
|
|
|
|
Hi,
I have a view class derived from CFormView. I have a timer in it which is fired for every 20 seconds. In the timer, I am repainting the form view with some bitmaps in OnPaint handler. When I am in the timer, the form view UI is stuck, i.e I am not able to click any other bottons on the form view. Can any one please give me some suggestions so that my UI responds to events even when the timer code is trying to refresh the view.
Thanks
Madhavi
|
|
|
|
|
Put the timer and the code that belongs to it in a separate thread.
That should do the trick.
|
|
|
|
|
Thanks...my problem is solved...
|
|
|
|
|
i want to create a setup file for
a MFC project ,
do Visual Studio contain any such
software.
thank u
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
Which Visual Studio ? Different versions have come with different solutions. I use Advanced Installer[^], it's a great solution, and the free version will probably do all you need ( although I bought it ).
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
what's wrong with Install Shield?
He is like a one-legged man in a bum kicking competition. -Novjot Sidhu
--[v]--
|
|
|
|
|
I've done installs with install shield. It's probably more powerful than AdvancedInstaller, but as a result, it takes a lot longer to get the same end result.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
Install shield
it is very powerful!
|
|
|
|
|
Thank you evryone for ur help
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
How can I add a dialog to Cview?
|
|
|
|
|
Create a new dialog class and make it a member variable for modeless, or create it in the scope of the function that calls it for modal dialogs.
Christian Graus - Microsoft MVP - C++
|
|
|
|