Solved

windows manager

Posted on 2001-09-05
9
157 Views
Last Modified: 2010-04-06
i know this is asking a lot but i am providing 250 points.

Can someone please post code for a windows manager.

ie a listbox with all the open windows and then you can click on an open window and have the ability to:

minimize window
maxamize window
disable sys menu
enable sys menu
Close selected window
change the text caption of a selected window


PLEASE can somone help?

thanks
0
Comment
Question by:marksmall
9 Comments
 

Author Comment

by:marksmall
ID: 6459139
oh i forgot to add

disable/enable "X"
disable/enable minimize and maxamise
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 6459422
basically you need to enumerate all the windows, and get their handles, using EnumWindows, e.g.

function EnumWindowsProc(Hw: hWnd; TF: TfrmEnumWin): Boolean; stdcall;
begin
  Result := True;
  // do whatever you want, store the handle, store the caption, etc
  // to get the caption, use GetWindowText
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  EnumWindows(@EnumWindowsProc);
end;

later on, to minimize a window, call
ShowWindow(handleToWindow, SW_MINIMIZE);
and likewise, substitute SW_MINIMIZE with SW_MAXIMIZE or SW_RESTORE or SW_HIDE/SW_SHOW for the other desired effects

to close a window, use
SendMessage(handleToWindow, WM_CLOSE, 0, 0);

to change caption, use
SetWindowText(handleToWindow, PChar(NewString));

you can use SetWindowLong to change the style of a window so that it does not have a system menu (remove WS_SYSMENU from the style)... see Madshi's comment on how to do it onto a different process: http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20178822

otherwise, I can't think of any ways to disable the system menu for now, but you may try this:

DestroyMenu(GetSystemMenu(handleToWindow, False));

and to recreate it again:

GetSystemMenu(handleToWindow, True);


When disabling the 'X', you should also remember to disable the Close command from the system menu
EnableMenuItem(GetSystemMenu(handleToWindow, False), SC_CLOSE, MF_BYCOMMAND or MF_GRAYED);



Hope that helps!


DragonSlayer
0
 
LVL 17

Expert Comment

by:inthe
ID: 6459726
DragonSlayer has covered it all pretty well ,so i just have to mention:
http://www.gxexplorer.org/

its a opensource explorer replacemnet ,maybe you can find something in it to enhance your app..
0
 

Author Comment

by:marksmall
ID: 6460336
thanks, but can anyone provide a full working program of this? i can increase the points!!!
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:marksmall
ID: 6628361
FIRST off all SORRY ABOUT DELAY, BEEN POORLY AND COULD GET ACCESS TO MY COMPUTER!

Secondly for 250 points could someone PLEASE provide me with a FULL source example!!!
0
 

Author Comment

by:marksmall
ID: 6628408
i got this code from a client server program but it has been adapted
for the client server, so i got the code that i think is necessary and
am posting it below, to see if some kind person will sort it out and
make it work in program thats NOT client server. i got this code
from the url mentioned in "nod31"s question! I want the program to
look EXACTALY like the one in this screen shot!!!

www.noel16.freeserve.co.uk/tasklist.jpg

if the option is selected then it displays ALL applications as well,
and if its not selected then it ONLY shows the open windows. It is
a listview that the info is dislpayed in!

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function TaskList(FirstHandle: THandle; ListAll: Boolean): string;
var
   lngLen:longint;
   strBuffer,This,All:string;
   TaskHandle:THandle;
   cChar:Char;
begin
   cChar:=Chr(13);
   TaskHandle:=GetWindow(FirstHandle,GW_HWNDFIRST);
   while TaskHandle > 0 do
   begin
      if (TaskHandle <> FirstHandle) and (TaskHandle <> Application.Handle) then
      begin
         lngLen:=GetWindowTextLength(TaskHandle) + 1;
         SetLength(strBuffer,lngLen);
         lngLen:=GetWindowText(TaskHandle,PChar(strBuffer),lngLen);
         if lngLen > 0 then
         begin
            This:=TrimRight(strBuffer);
            if ListAll then
               All:=All + This + cChar + IntToStr(TaskHandle) + cChar
            else
               if IsWindowVisible(TaskHandle) then
                  All:=All + This + cChar + IntToStr(TaskHandle) + cChar;
         end;
      end;
      TaskHandle:=GetWindow(TaskHandle,GW_HWNDNEXT);
   end;
   TaskList:=Copy(All,1,Length(All) - 1);
end;


0
 
LVL 9

Accepted Solution

by:
ginsonic earned 300 total points
ID: 6629305
Use next unit to list all processes and terminate the selected .

unit Unit1;

interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, TlHelp32;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    lst: TListBox;
    Button3: TButton;

    procedure Button1Click(Sender: TObject);
    procedure lstDblClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
    procedure Scrie(inf: TProcessEntry32);
  public
    { Public declarations }
    snapshot: THandle;
    info: array[0..100] of TProcessEntry32;
    count: integer;
    procedure RefreshList;
  end;

var
  Form1: TForm1;
  names:String;

implementation

{$R *.DFM}

procedure TForm1.RefreshList;
var inf: TProcessEntry32;
begin
  SnapShot:=CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS,0);
  lst.Clear; count:=0; inf.dwSize:=sizeof(inf);
  Process32First(snapshot,inf); scrie(inf);
  while Process32Next(snapshot,inf) do scrie(inf);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  RefreshList;
end;

procedure TForm1.Scrie(inf: TProcessEntry32);
begin
  info[count]:=inf;
  lst.items.add(info[count].szExeFile);
  inc(count);
end;

procedure TForm1.lstDblClick(Sender: TObject);
var z: integer;
  str: TStringList;
begin
  z:=lst.ItemIndex;
  str:=TStringList.Create;
  try
    str.add(format('Usage      = %4d',[info[z].cntUsage]));
    str.add(format('ProcessID  = %8x',[info[z].th32ProcessID]));
    str.add(format('def. HeapID= %8x',[info[z].th32DefaultHeapID]));
    str.add(format('ModuleID   = %8x',[info[z].th32ModuleID]));
    str.add(format('Threads    = %4d',[info[z].cntThreads]));
    str.add(format('Parent Proc= %8x',[info[z].th32ParentProcessID]));
    str.add(format('Class Base = %4d',[info[z].pcPriClassBase]));
    str.add(format('ExeFile    = %s',[info[z].szExeFile]));
    names:= info[z].szExeFile;
    ShowMessage(str.Text);
  finally
    str.Free;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var z: integer;
    han: THandle;
begin
  z:=lst.ItemIndex; if z=-1 then exit;
  han:=OpenProcess(PROCESS_TERMINATE,false,info[z].th32ProcessID);
  TerminateProcess(han,0); WaitForSingleObject(han,INFINITE);
  CloseHandle(SnapShot);
  RefreshList;
end;


end.
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6629307
Just handle to processes and do what you wish .
Good luck.
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6629308
Sorry for Button3. Just remove it .
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

13 Experts available now in Live!

Get 1:1 Help Now