|
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++
|
|
|
|
|
By that I mean embedded a modal dialog inside a SDI view.
|
|
|
|
|
Embedding in what way ? So the modal dialog is part of the CView window ? Or just so that the modal dialog is shown by the view ? If the former, you can't. If the latter, exactly as I said. In your view, create the dialog class, and call DoModal on it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
Use CFormView
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
This is an assignment and we're recommanded not to use CFormView, but somehow to mimic the CFromView ways
|
|
|
|
|
Oh. You said a 'Modal dialog'. Otherwise, I'd have said to use CFormView. CFormView gives you a dialog like view, it does NOT 'add a modal dialog to your CView'.
If you're not allowed to use CFormView, then create your own controls, and embed them into your CView in your view constructor.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
According to assignment specification, It is feasible to add modal dialog to CView, and add controls to this dialog.
|
|
|
|
|
Hmmm - perhaps you can add a dialog, but it can't possible be modal, that's not what modal means.
I'm going to have a play with this.
Christian Graus - Microsoft MVP - C++
|
|
|
|