Solved

Disabling [CRTL + ESC]

Posted on 1999-01-02
9
428 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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
 

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 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