Solved

Disabling [CRTL + ESC]

Posted on 1999-01-02
9
426 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
Comment Utility
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
Comment Utility
How are you disabling [CRTL + ESC]?  I mean what method are you using
0
 

Author Comment

by:fantasia123098
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:fantasia123098
Comment Utility
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
Comment Utility
Yes, of course...  :-)
0
 

Author Comment

by:fantasia123098
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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 discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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