Solved

ask about difunction ALT-TAB,CTRL-ALT-DEL,,shutdown, and taskbar(hide)

Posted on 2001-06-15
8
392 Views
Last Modified: 2010-05-18
hi...

i want ask about disfunction ALT-TAB,CTRL-ALT-DEL, and start in taskbar (if i press key windows) ...

and make program about shutting down windows, taskbar hide, and screen saver windows will show if my program run (in form create)...

if i click button1.. screen saver will hide;
if i click button2... windows will shutdown;
if i click button3...taskbar will hide;
0
Comment
Question by:Rudy_Rai
8 Comments
 
LVL 22

Expert Comment

by:mnasman
ID: 6195300
Hello

  I don't have all the idea now, but i will give you some of them, and i will post the other soon, cuz i'm at weekend now

this procedure will disable ctrl+alt+del, u can enabled or disabled them by calling it with true or false

procedure SystemKeys(Disable: Boolean);
 var OldVal : LongInt;
begin
 SystemParametersInfo
    (SPI_SCREENSAVERRUNNING,
     Word(Disable),
     @OldVal,
     0);
end;
//==
SystemKeys(True); // to disabled ctrl+alt+del
SystemKeys(false); // to enabled ctrl+alt+del

and this procedure for show and hide taskbar

procedure ShowTaskBar(bShow: Boolean);
begin
if bShow = True then
 ShowWindow(FindWindow
  ('Shell_TrayWnd',nil), SW_SHOWNA)
else
 ShowWindow(FindWindow
  ('Shell_TrayWnd',nil), SW_HIDE);
end;


send me email at nasman@mogaza.org and i will send you the compelete project

Mohammed


0
 
LVL 22

Expert Comment

by:mnasman
ID: 6195349
Hello

  Forget to include shut down procedure

procedure ShutDown;
begin
  ExitWindowsEx(EWX_SHUTDOWN, 0 );
end;


but if you don't want Windows does not send the  messages WM_QUERYENDSESSION and WM_ENDSESSION to the applications
and let ur applicatoin to forces processes to terminate.
currently running in the system. This can cause the applications to lose data.  Therefore, you should only use this flag in an emergency.    

change the flag to

  ExitWindowsEx(EWX_FORCE or EWX_SHUTDOWN, 0 );

Mohammed

0
 
LVL 3

Expert Comment

by:VSF
ID: 6195590
Here we go:
I think this can be of great value... take a look!Hope this helps!

VSF
www.enge.cjb.net
www,victory.hpg.com.br
UIN:14016999

OPEN START MENU
procedure TForm1.Button1Click(Sender: TObject);
begin  
  SendMessage(Form1.handle,WM_SYSCOMMAND,SC_TASKLIST,0);
end;
------------------------
TURN MONITOR ON/OFF
{turn monitor off}  

SendMessage(Application.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, 0);  
   
{turn monitor on}  

SendMessage(Application.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, -1);
-----------------------
ENABLE AND DISABLE CD AUTORUN
procedure TForm1.SetCDAutoRun(AAutoRun:Boolean);  
const DoAutoRun : array[Boolean] of Integer = (0,1);  
var Reg:TRegistry;  
begin  
  try Reg := TRegistry.Create;  
  Reg.RootKey := HKEY_LOCAL_MACHINE;  
  if Reg.KeyExists('System\CurrentControlSet\Services\Class\CDROM') then  
  begin  
    if Reg.OpenKey('System\CurrentControlSet\Services\Class\CDROM',FALSE) then  
    Reg.WriteBinaryData('AutoRun',DoAutoRun[AAutoRun],1);  

  finally  
  Reg.Free;  
  end;  
  ShowMessage('Your settings will take effect on the next reboot of    Windows.');  
end;
---------------------------
PREVENT CTRL+ALT+DEL
VAR  
    OldValue:Longbool;  

{on}  

SystemParametersInfo(97,Word(True),@OldValue,0);  
   

{off}  
SystemParametersInfo(97,Word(False),@OldValue,0);
----------------------------
SUSPEND THE PC
SetSystemPowerState(FALSE,FALSE);
----------------------
...shutdown / reboot / logoff WIndows 9x / NT / Me / 2000 ?

program shutdown;
{$APPTYPE CONSOLE}
uses
  SysUtils,
  Windows;

// Shutdown Program
// (c) 2000 NeuralAbyss Software
// www.neuralabyss.com

var
   logoff: boolean = false;
   reboot: boolean = false;
   warn: boolean = false;
   downQuick: boolean = false;
   cancelShutdown: boolean = false;
   powerOff: boolean = false;
   timeDelay: integer = 0;

function HasParam(Opt: Char): Boolean;
var
   x: integer;
begin
     result := false;
     for x := 1 to paramCount do
         if (paramstr(x) = '-'+opt) or (paramstr(x) = '/'+opt) then result := true;
end;

function GetErrorString: String;
var
   lz: Cardinal;
   err: array[0..512] of Char;
begin
     lz := GetLastError;
     FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nil, lz, 0, @err, 512, nil);
     result := string(err);
end;

procedure DoShutdown;
var
   rl,flgs: Cardinal;
   hToken: Cardinal;
   tkp: TOKEN_PRIVILEGES;
begin
     flgs := 0;
     if downQuick then flgs := flgs or EWX_FORCE;
     if not reboot then flgs := flgs or EWX_SHUTDOWN;
     if reboot then flgs := flgs or EWX_REBOOT;
     if poweroff and (not reboot) then flgs := flgs or EWX_POWEROFF;
     if logoff then flgs := (flgs and (not (EWX_REBOOT or EWX_SHUTDOWN or EWX_POWEROFF))) or EWX_LOGOFF;
     if Win32Platform = VER_PLATFORM_WIN32_NT then begin
        if not OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
           Writeln('Cannot open process token. ['+GetErrorString+']')
        else begin
             if LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tkp.Privileges[0].Luid) then begin
             tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
             tkp.PrivilegeCount := 1;
             AdjustTokenPrivileges(hToken, False, tkp, 0, nil, rl);
             if GetLastError <> ERROR_SUCCESS then
                   Writeln('Error adjusting process privileges.');
             end else Writeln('Cannot find privilege value. ['+GetErrorString+']');
        end;
{        if CancelShutdown then
           if AbortSystemShutdown(nil) = False then
              Writeln(\'Cannot abort. [\'+GetErrorString+\']\')
           else
               Writeln(\'Cancelled.\')
        else begin
             if InitiateSystemShutdown(nil, nil, timeDelay, downQuick, Reboot) = False then
                Writeln(\'Cannot go down. [\'+GetErrorString+\']\')
             else
                 Writeln(\'Shutting down!\');
        end;}
     end;
//     else begin
          ExitWindowsEx(flgs, 0);
//     end;
end;

begin
     Writeln('Shutdown v0.3 for Win32 (similar to the Linux version)');
     Writeln('(c) 2000 NeuralAbyss Software. All Rights Reserved.');
     if HasParam('?') or (ParamCount=0) then begin
        Writeln('Usage:    shutdown [-akrhfnc] [-t secs]');
        Writeln('                  -k:      don''t really shutdown, only warn.');
        Writeln('                  -r:      reboot after shutdown.');
        Writeln('                  -h:      halt after shutdown.');
        Writeln('                  -p:      power off after shutdown');
        Writeln('                  -l:      log off only');
        Writeln('                  -n:      kill apps that don''t want to die.');
        Writeln('                  -c:      cancel a running shutdown.');
     end else begin
         if HasParam('k') then warn := true;
         if HasParam('r') then reboot := true;
         if HasParam('h') and reboot then begin
            Writeln('Error: Cannot specify -r and -h parameters together!');
            Exit;
         end;
         if HasParam('h') then reboot := false;
         if HasParam('n') then downQuick := true;
         if HasParam('c') then cancelShutdown := true;
         if HasParam('p') then powerOff := true;
         if HasParam('l') then logoff := true;
         DoShutdown;
     end;
end.
---------------------
...disable / enable / hide / show taskbar ?
 
This is very easy. All that you have to do is obtain the window handle
of the taskbar window and then you can disable or hide it.
The window handle is obtained like this :

var
  HTaskbar : HWND;
begin
  HTaskBar:=FindWindow('Shell_TrayWnd',nil);

Now you have the window handle, you can use it to disable or hide the taskbar :

  EnableWindow(HTaskBar,False); //Disable the taskbar
  EnableWindow(HTaskBar,True); //Enable the taskbar
  ShowWindow(HTaskbar,SW_HIDE); //Hide the taskbar
  ShowWindow(HTaskbar,SW_SHOW); //Show the taskbar
-------------------
 Shutting down
     function ExitWindowsEx(uFlags : integer; dwReserved : word) : boolean;
      external 'user32.dll' name 'ExitWindowsEx';

      procedure Tchau;
      const
        EWX_LOGOFF = 0; // "logoff"
        EWX_SHUTDOWN = 1; // Regular Shutdown
        EWX_REBOOT = 2; // "reboot"                        EWX_FORCE = 4; // finish all process
        EWX_POWEROFF = 8; // turn off/on

      begin
        ExitWindowsEx(EWX_FORCE, 0);
      end;
\
0
 

Author Comment

by:Rudy_Rai
ID: 6196850
how about ALT_TAB and hide/show screen saver for windows..

or if i run my application, screen saver will show (with color black). if i click button1 display windows will show..(or screen saver will hide)...
0
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

 

Author Comment

by:Rudy_Rai
ID: 6196870
but if screen saver show, i still call another application
from my program

give me some example about it...
0
 

Author Comment

by:Rudy_Rai
ID: 6196998
can delphi hide icons(like my computer, my documents, recycle bin, etc) in display windows??
and show it again....

give me an example...

0
 
LVL 2

Expert Comment

by:danysz
ID: 6197214
listening......
0
 
LVL 22

Accepted Solution

by:
mnasman earned 250 total points
ID: 6197626
Hello

  this procedure will show and hide the desktop

procedure ShowDesktop(const YesNo : boolean);
var h : THandle;
begin
 h := FindWindow('ProgMan', nil);
 h := GetWindow(h, GW_CHILD);
 if YesNo = True then
   ShowWindow(h, SW_SHOW)
 else
   ShowWindow(h, SW_HIDE);
end;

ShowDesktop(False);  //hide desktop
ShowDesktop(True);  //Show desktop

Mohammed
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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

705 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

19 Experts available now in Live!

Get 1:1 Help Now