Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC
Hello,
 
Using my MFC application, i have to disable Copy/Cut/Paste/Delete from the windows system, i was successful in disabling those while using keyboard shotcuts(Ctrl+C,Ctwhen trl+v,Ctrl+X,Ctrl+D) but i am struck for disabling the same on right click options,so that if the user try to do copy,cut,paste,delete operations through right click of mouse the those options should show disabled,
 
I have done the same kind of thing for disabling "Start Task Manager"(when the user right clicks on the taskbar) by changing the registry value name "DisableTaskMgr" and Value data as 1 in the registry settings,and i was successful using this.
 
Is there any specific registry value name to set in the registry to disable Copy/Cut/Paste/Delete options from right click or is there any other way to do it in MFC.
 

,kindly can any one suggest me for the same.
 

Thanks in Advance.
Posted 25-Sep-12 17:18pm
Edited 11-Oct-12 18:16pm
v4
Comments
Sergey Alexandrovich Kryukov at 25-Sep-12 23:41pm
   
Why?!
--SA
Argonia at 10-Oct-12 10:42am
   
if these Copy/Cut/Paste/Delete are buttons you can catch the message WM_CONTEXMENU (if you want to disable them if the context menu is activated ) or WM_RBUTTONDOWN for just a click .You can disable them with CButton::EnableWindow(FALSE / TRUE)
Rocky_Bas at 12-Oct-12 0:05am
   
Hi Argonia,thanks for the reply.But i have to disable this copy cut paste delete keys from the windows not on the application iam running.
 
I was successfull to disable the key board shotcut keys for the same,but i have disable those options even in the mouse right click.Because can even do copy,cut,paste,delete through mouse,so kindly suggest me for it.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Don't do it. The reasonable users won't forgive such abuse. Better explain why do you think you would need it, to get better advice.
 
—SA
  Permalink  
Comments
Rocky_Bas at 25-Sep-12 23:47pm
   
Hi Sergey,
 
These are the rights i need to provide in my application,that's the reason i want disable and if required enable those.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
Rocky_Bas at 5-Oct-12 5:10am
   
Hi Joan,i am able to track the keyboard and mouse events using Hooks,but how to exactly stop to do that particular operation.
 
I mean to say ,i the user is pressing delete button ,at this moment after tracking the delete event how to stop him deleting.
Joan Murt at 5-Oct-12 5:19am
   
Well, it all depends on the method you are using to capture the keystrockes, but typically there is a return value on the capture functions that will allow you to continue processing the message or not.
I don't know which method you've chosen, but take a look at the return value of the function you are using to pre-handle the keystrokes.
Rocky_Bas at 5-Oct-12 5:28am
   
In the KeyStroke function i have kept a condition
if(wParam == VK_DELETE)
so with this condition i can know user has pressed delete button in the keyboard,now in this i need to return some thing so that user cant do delete.
Joan Murt at 5-Oct-12 5:34am
   
I'm sorry but I don't know the "keystroke" function... are you using the pretranslate message? handling any message? Well, I'm sure you are handling a message as you have the wparam parameter here but... which one it is?
Rocky_Bas at 5-Oct-12 5:38am
   
KeyStroke function means it capture the events of keyboard
Joan Murt at 5-Oct-12 6:03am
   
Yes, of course :) I understand the meaning of keystroke...
What I'm asking is: keystroke gets called when a certain event has happened... which event is it? how have you linked the keystroke function to that event? which message are you handling here? is it PreTranslateMessage, WM_KEYUP, WM_KEYDOWN... ?
Joan Murt at 5-Oct-12 6:04am
   
Which is the return clause of the "keystroke" function?
Rocky_Bas at 6-Oct-12 0:50am
   
below is my code for keystroke ,this keystroke will be called if i press anything in the keyboard,so iam using VK_DELETE virtual key to track delete event.
 

LRESULT CRecordPlayerDlg::OnKeyStroke(WPARAM wParam, LPARAM lParam)
{
m_nTimeStamp = GetTickCount() - m_nTimeStamp;
CString csKeyTyped;
CString csKeyStatus;
csKeyStatus = "0¦0¦0¦0¦0¦0¦0¦0¦0¦0¦0";

 
if ((wParam==VK_SPACE)||(wParam==VK_RETURN)||
(wParam>=0x2f ) &&(wParam<=0x100))
{
// CAPSTATE,LSHIFT,LCTRL, LWINDOW, LALT, RALT, RWIN, MENU,RCTRL, RSHIFT,NUMLCOK
SHORT nCapital = GetKeyState( VK_CAPITAL );
// Left side
//****************************************************************************
SHORT nVirtKeyLeftShift = GetAsyncKeyState(VK_LSHIFT);
SHORT nLeftControl = GetAsyncKeyState( VK_LCONTROL );
// Hard Coded
SHORT nLWindows = GetAsyncKeyState( VK_LWIN );
SHORT nLAlt = GetAsyncKeyState( VK_LMENU );
//****************************************************************************
// Right Side
SHORT nRAlt = GetAsyncKeyState( VK_RMENU );
// Hard coded
SHORT nRWin = GetAsyncKeyState( VK_RWIN );
SHORT nMenu = GetAsyncKeyState( VK_APPS );
SHORT nRightControl = GetAsyncKeyState( VK_LCONTROL );
SHORT nVirtKeyRightShift= GetAsyncKeyState(VK_RSHIFT);
SHORT nVirtKeyCopy = GetAsyncKeyState(VK_DELETE);
//*****************************************************************************
 
// Num Lock
SHORT nNumLock = GetKeyState( VK_NUMLOCK );
 

int nCurrentPos = 0;
if( 0 != nCapital )
{
ReplaceString( csKeyStatus, nCurrentPos );
}
nCurrentPos = csKeyStatus.Find( SEPERATOR, nCurrentPos );
nCurrentPos++;
if( 0 != nVirtKeyLeftShift )
{
ReplaceString( csKeyStatus, nCurrentPos );
}
nCurrentPos = csKeyStatus.Find( SEPERATOR, nCurrentPos );
nCurrentPos++;
if( 0 != nLeftControl )
{
ReplaceString( csKeyStatus, nCurrentPos );
}
nCurrentPos = csKeyStatus.Find( SEPERATOR, nCurrentPos );
nCurrentPos++;
if( 0 != nLWindows )
{
ReplaceString( csKeyStatus, nCurrentPos );
}
nCurrentPos = csKeyStatus.Find( SEPERATOR, nCurrentPos );
nCurrentPos++;
if( 0 != nLAlt )
{
ReplaceString( csKeyStatus, nCurrentPos );
}
nCurrentPos = csKeyStatus.Find( SEPERATOR, nCurrentPos );
nCurrentPos++;
if( 0 != nRAlt )
{
ReplaceString( csKeyStatus, nCurrentPos );
}
nCurrentPos = csKeyStatus.Find( SEPERATOR, nCurrentPos );
nCurrentPos++;
if( 0 != nRWin )
{
ReplaceString( csKeyStatus, nCurrentPos );
}
nCurrentPos = csKeyStatus.Find( SEPERATOR, nCurrentPos );
nCurrentPos++;
if( 0 != nMenu )
{
ReplaceString( csKeyStatus, nCurrentPos );
}
nCurrentPos = csKeyStatus.Find( SEPERATOR, nCurrentPos );
nCurrentPos++;
if( 0 != nRightControl )
{
ReplaceString( csKeyStatus, nCurrentPos );
}
nCurrentPos = csKeyStatus.Find( SEPERATOR, nCurrentPos );
nCurrentPos++;
if( 0 != nVirtKeyRightShift )
{
ReplaceString( csKeyStatus, nCurrentPos );
}
nCurrentPos = csKeyStatus.Find( SEPERATOR, nCurrentPos );
nCurrentPos++;
if( 0 != nNumLock )
{
ReplaceString( csKeyStatus, nCurrentPos );
}
LPSTR csKey = new TCHAR[sizeof(TCHAR)];
GetKeyNameText( lParam, csKey, 4 );
csKeyTyped = csKey;
csKeyTyped += SEPERATOR;
csKeyStatus += SEPERATOR;
}
CString csKeyFormat;
CString csWParam;
csWParam.Format( "%x¦", wParam);
CString csTime;
csTime.Format( "%d", m_nTimeStamp );
csKeyFormat = "KeyBD¦";
csKeyFormat += csKeyTyped;
csKeyFormat += csKeyStatus;
csKeyFormat += csWParam;
csKeyFormat += csTime;
csKeyFormat += "\n";
m_csArray.Add( csKeyFormat );
m_nTimeStamp = GetTickCount();
if(wParam == VK_DELETE)
{
/********
Need to write the code to stop the event
 
*****/
 
}
return 1;
}
Joan Murt at 6-Oct-12 4:47am
   
This OnKeyStroke method is new for me, probably it is not standard and depends completely on the CRecordPlayerDlg dialog class.
 
Anyway, try to return 0 when you want to cancel further processing of the message.
Rocky_Bas at 6-Oct-12 5:02am
   
i have tried in the same way return 0 ,but its not working
Joan Murt at 6-Oct-12 9:57am
   
Then in your dialog add the handler of PreTranslateMessage and filter the message there.
 
See: http://www.codeproject.com/Questions/40901/Disable-esc-key-exit-for-MFC-Application
 
Who knows how the OnKeyStroke function is implemented, use the standard Microsoft option and you'll be safe and fine.
 
Good luck!
Rocky_Bas at 8-Oct-12 22:43pm
   
Hey Joan Murt,
Its working now, iam able the user from doing Copy/Cut/Paste,but its working only when i use keyboard,i even want to disable it from the mouse right click options,i think its possible through registries,can you help me out for this.
Rocky_Bas at 8-Oct-12 22:43pm
   
Hey Joan Murt,
Its working now, iam able the user from doing Copy/Cut/Paste,but its working only when i use keyboard,i even want to disable it from the mouse right click options,i think its possible through registries,can you help me out for this.
Joan Murt at 9-Oct-12 3:15am
   
With pretranslate message you can directly cancel the right click, but I've never done the registry modification you mention and I can't give you more help on that... I guess that a search on google is the only hope (apart of waiting for any other member to give you extra help on that).
 
I'm sorry...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.141022.1 | Last Updated 12 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100