Solved

Disabling [CRTL + ESC]

Posted on 1999-01-02
9
427 Views
Last Modified: 2010-04-04
I have made a little client server program. The program is loaded as shell from system.ini.
I have made alittle dll to prevent users from pressing [CRTL + ESC] to start tasklist or an explorer. When I use this little dll it works fine as long as I not load the program as shell, but when I do I am not able to press on a main-menu or move scrollbars d:(
What is wrong and how can I solve this.

BTW I am using Delphi 4 Client / Server, and I want my program to work no matter if you are in win95 or win98 (no NT)
Thank in advance, Fantasia
0
Comment
Question by:fantasia123098
  • 4
  • 4
9 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1354212
Can you please post the code of your little dll? Only thing that I can imagine is that there is something wrong with that.

If you don't use this dll, you can click at your mainmenu again, right?

Regards, Madshi.
0
 
LVL 5

Expert Comment

by:heathprovost
ID: 1354213
How are you disabling [CRTL + ESC]?  I mean what method are you using
0
 

Author Comment

by:fantasia123098
ID: 1354214
4 Madshi (and heathprovost) this is the source code :
library ClientDll;

{$C FIXED PERMANENT PRELOAD}

uses
    WinProcs,
  SysUtils;
Const
     hHookCBT : THandle = 0;

function CBTHookFunc( nCode : Integer;
                      wparam : WParam;
                      lparam : LParam): LRESULT  stdCall;
begin
     if nCode=HCBT_SYSCOMMAND then begin
       MessageBeep(0);
       Result:=1; { removes message }
     end
     else
      { call next hook in chain }
      Result:=CallNextHookEx(hHookCBT, nCode, wParam, lParam);
end;

procedure InstallCBTHook; EXPORT;
var
  hLib : THandle;
  hProgMan : HWnd;
begin
  hLib:=GetModuleHandle('ClientDll');
  if (hHookCBT=0) then begin
    hProgMan:=FindWindow('Progman', NIL);
    hHookCBT:=SetWindowsHookEx(WH_CBT, @CBTHookFunc, hLib,
                               GetWindowThreadProcessId(hProgMan, nil));
  end;
end;

procedure RemoveCBTHook; EXPORT;
begin
  if (hHookCBT<>0) then begin
    UnhookWindowsHookEx(hHookCBT);
    hHookCBT:=0;
  end;
end;

EXPORTS
  InstallCBTHook,
  RemoveCBTHook;

end.

in the Main form´s OnCreate event i typed

"InstallCBTHook" and I remove when the machine restarts.

If I call the procedure "RemoveCBTHook" it works ok again, also if I don´t use the DLL then the mainmenus and scrollbars are just fine.  What is the problem, I think that I have made a mistake :)

Fantasia
0
 
LVL 20

Accepted Solution

by:
Madshi earned 20 total points
ID: 1354215
Fantasia,

the wParam parameter of your CBTHookFunc function is one of the following values:

SC_CLOSE      Closes the window.
SC_CONTEXTHELP      Changes the cursor to a question mark with a pointer. If the user then clicks a control in the dialog box, the control receives a WM_HELP message.
SC_DEFAULT      Selects the default item; the user double-clicked the window menu.
SC_HOTKEY      Activates the window associated with the application-specified hot key. The low-order word of lParam identifies the window to activate.
SC_HSCROLL      Scrolls horizontally.
SC_KEYMENU      Retrieves the window menu as a result of a keystroke.
SC_MAXIMIZE (or SC_ZOOM)      Maximizes the window.
SC_MINIMIZE (or SC_ICON)      Minimizes the window.
SC_MONITORPOWER      Windows 95 only: Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer.
SC_MOUSEMENU      Retrieves the window menu as a result of a mouse click.
SC_MOVE      Moves the window.
SC_NEXTWINDOW      Moves to the next window.
SC_PREVWINDOW      Moves to the previous window.
SC_RESTORE      Restores the window to its normal position and size.
SC_SCREENSAVE      Executes the screen saver application specified in the [boot] section of the SYSTEM.INI file.
SC_SIZE      Sizes the window.
SC_TASKLIST      Executes or activates Windows Task Manager.
SC_VSCROLL      Scrolls vertically.

You see that you prevent a lot of things. You should look through all these values and delete only some messages. E.g., I think if you allow SC_HSCROLL/SC_VSCROLL, the scrollbar will work again...

Then please look at this extract from the win32.hlp file:
"If nCode is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by CallNextHookEx."

Please change your code to follow this guideline, too.

Regards, Madshi.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:fantasia123098
ID: 1354216
Hi Madshi, Thank you for the good information, now I will try to fix this little Dll.
Is it ok if I post again if I can´t make it work?

Fantasia
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1354217
Yes, of course...  :-)
0
 

Author Comment

by:fantasia123098
ID: 1354218
4 Madshi.
Phew - I will never get this app to run :(
I can´t make it work, what am I doing wrong? Please Help
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1354219
Hi fantasia,

try to use this CBTHookFunc in your dll:

function CBTHookFunc(nCode: integer; wparam: wParam; lparam: lParam) : LRESULT; stdCall;
begin
  if (nCode=HCBT_SYSCOMMAND) and
     ((wParam=SC_TASKLIST) or (wParam=SC_NEXTWINDOW) or (wParam=SC_PREVWINDOW)) then begin
    MessageBeep(0);
    result:=1; // removes message
  end else // call next hook in chain
    result:=CallNextHookEx(hHookCBT,nCode,wParam,lParam);
end;

If that doesn't work, please tell me WHAT does not work in detail. Then you'll probably have to wait two days. In the moment I've no free time at all. In 2 days I can test it for you...

Regards, Madshi.
0
 

Author Comment

by:fantasia123098
ID: 1354220
Thank you Madshi, I will noe try to use it.
In the dll I made I did something like :
"case wParam of", but it did not work the right way.

Thans from Fantasia
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now