• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

Moving the desktop

Anyone ever seen the desktop moved down? for example

  a a a a a                                  
   b b b b                                          a a a a a
  c c c c c c    so then it looks like this     b b b b
                                                       c c c c c c

drops down a level? i have seen this done, just not know how..

Thanks Again You Lot...


Craig C. need to buy some points  i think :)
0
craig_capel
Asked:
craig_capel
  • 7
  • 5
  • 4
1 Solution
 
ptmcompCommented:
Sorry, I don't undertand what you want to do.
0
 
craig_capelAuthor Commented:
For example, where my computer is, its at the top of the screen, what happens if i was to put a something at the top of the screen, BUT! i dont want to loose my computer icon, so i some how drop the icons down a couple of inches, and put my program at the top.......

-------------
.. My Comp .
..               .
..               .
..................


-------------
.. -My prog-.
.. My Comp .
..               .
..               .
..................


droping all the icons down to fit my workspace in, its going to be an alternative to the start bar......

0
 
ptmcompCommented:
The Desktop is a listview and you can get it's handle through the winapi functions. Then you can use all the functions like ListView_SetItemPosition32 with this handle.
Regards, ptm.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
craig_capelAuthor Commented:
unit desktop1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
h: hwnd;
begin
  h:=findwindow('Progman',nil);
      {  showwindow(h,sw_show);  }  just checking.....
{ void ListView_SetItemPosition32(
   HWND hwnd,
    int iItem,
    nt x,
    int y
   );}
 ListView_SetItemPosition32(h,nil,1,90);

end;

end.


No joy, unkown command in Delphi4, any way of getting it to see this command?

Thanks for your help ptm.....

Craig C.
0
 
ptmcompCommented:
There is missing the unit CommCtrl.
0
 
craig_capelAuthor Commented:
Well yes that command had some effect, it crashes it!, however i was having a hard time getting the handle of the windows.... i just thought of a new way of doing what i need.

 movewindow(3592,random(100),random(199),639,480,true);

where 3529 = hande of desktop, all i need is a findwindow 'string' for it to work....

var
h: hwnd;
begin
  h:=findwindow('#32769:Desktop',nil);
  showwindow(h,sw_show);
{ void ListView_SetItemPosition32(
   HWND hwnd,
    int iItem,
    nt x,
    int y 3592
 );}

{ movewindow(3592,random(100),random(199),639,480,true);}
 {  movewindow(3592,1,1,800,600,true);}

Looks VERY good when you move it around.....
0
 
craig_capelAuthor Commented:
h:=findwindow('#32769:Desktop',nil);   < sorry, this here needs to be changed, i can not find one that works.....
0
 
intheCommented:
uses commctrl;

procedure TForm1.Button1Click(Sender: TObject);
var
h : hwnd;
begin
h:=FindWindowEx(FindWindowEx(FindWindow('Progman','Program Manager'),0,'SHELLDLL_DefView',''),0,'SysListView32','');
ListView_SetItemPosition(h,2,2,4);

end;


the first 2 is the index number of listview icon to move,the 2,4 is the desktops listview coordinates to move to.

Regards Barry
0
 
ptmcompCommented:
You propose my and craig_capel's comment as an answer?
0
 
intheCommented:
well after i read the last comment
>>>>>>>
 h:=findwindow('#32769:Desktop',nil);   < sorry, this here needs to be changed, i can not find one that works.....
<<<<<<<<
i tested till got it to work and posted code showing how to do it ..
but to answer the question more fully youll see you need the index number of listview icon to move so youll need to get the desktop icons positions first or you wont know what icons to move and see what i find:

// "hook.dpr" - DLL project

library hook;

uses windows, messages, commctrl;

{$ifndef ver120} type cardinal = integer; {$endif}

function HookMessageProc(code, wParam, lParam: integer) : integer; stdcall;
begin
  result:=0;
end;

exports HookMessageProc;

type TDesktopItems  = record
                        itemCount : integer;
                        items     : array [0..$FFFE] of record
                                      pos  : TPoint;
                                      name : array [0..MAX_PATH] of char;
                                    end;
                      end;
     TPDesktopItems = ^TDesktopItems;

var fm  : cardinal;
    pdi : TPDesktopItems;
    lv  : cardinal;
    i1  : integer;
    lvi : TLVItem;
    ev  : cardinal;
begin
  lv:=FindWindowEx(FindWindowEx(FindWindow('Progman','Program Manager'),0,'SHELLDLL_DefView',''),0,'SysListView32','');
  if (lv<>0) and (GetCurrentThreadID=GetWindowThreadProcessID(lv,nil)) then begin
    fm:=OpenFileMapping(FILE_MAP_ALL_ACCESS,false,'mappedMemoryForDesktopIcons');
    if fm<>0 then
      try
        pdi:=MapViewOfFile(fm,FILE_MAP_ALL_ACCESS,0,0,0);
        if pdi<>nil then
          try
            with pdi^ do begin
              i1:=SendMessage(lv,LVM_GETITEMCOUNT,0,0);
              if i1<itemCount then itemCount:=i1;
              zeroMemory(@lvi,sizeOf(TLVItem));
              for i1:=0 to itemCount-1 do begin
                SendMessage(lv,LVM_GETITEMPOSITION,i1,integer(@items[i1].pos));
                with lvi do begin mask:=LVIF_TEXT; iSubItem:=0; pszText:=items[i1].name; cchTextMax:=MAX_PATH end;
                items[i1].name[SendMessage(lv,LVM_GETITEMTEXT,i1,integer(@lvi))]:=#0;
              end;
            end;
          finally UnMapViewOfFile(pdi) end;
      finally CloseHandle(fm) end;
    ev:=OpenEvent(EVENT_ALL_ACCESS,false,'eventForDesktopIcons');
    if ev<>0 then
      try
        SetEvent(ev);
      finally CloseHandle(ev) end;
  end;
end.

// "desktopItems.pas" - the main unit

unit desktopItems;

interface

uses Windows, Messages, SysUtils, CommCtrl;

type IDesktopItems = interface ['{AD828DE0-3570-11D3-A52D-00005A180D69}']
                       function  ItemCount   : integer;
                       function  GetPosition (index: integer) : TPoint;
                       property  Position    [index: integer] : TPoint read GetPosition;
                       function  GetName     (index: integer) : string;
                       property  Name        [index: integer] : string read GetName;
                       procedure Refresh;
                     end;

function GetDesktopItems : IDesktopItems;

implementation

{$ifndef ver120} type cardinal = integer; {$endif}

type TDesktopItem   = record
                        pos  : TPoint;
                        name : array [0..MAX_PATH] of char;
                      end;
     TDesktopItems  = record
                        itemCount : integer;
                        items     : array [0..$FFFE] of TDesktopItem;
                      end;
     TPDesktopItems = ^TDesktopItems;
     TIDesktopItems = class (TInterfacedObject, IDesktopItems)
                      private
                        FFileMapping   : cardinal;
                        FPDesktopItems : TPDesktopItems;
                        constructor Create;
                        destructor Destroy; override;
                        function  ItemCount   : integer;
                        function  GetPosition (index: integer) : TPoint;
                        function  GetName     (index: integer) : string;
                        procedure Refresh;
                      end;

constructor TIDesktopItems.Create;
begin
  inherited;
  Refresh;
end;

destructor TIDesktopItems.Destroy;
begin
  if FPDesktopItems<>nil then UnMapViewOfFile(FPDesktopItems);
  if FFileMapping  <>0   then CloseHandle    (FFileMapping  );
  inherited;
end;

function TIDesktopItems.ItemCount : integer;
begin
  result:=FPDesktopItems^.itemCount;
end;

function TIDesktopItems.GetPosition(index: integer) : TPoint;
begin
  if (index<0) or (index>=FPDesktopItems^.itemCount) then
    raise Exception.Create('Index out of range.');
  result:=FPDesktopItems^.items[index].pos;
end;

function TIDesktopItems.GetName(index: integer) : string;
begin
  if (index<0) or (index>=FPDesktopItems^.itemCount) then
    raise Exception.Create('Index out of range.');
  result:=FPDesktopItems^.items[index].name;
end;

procedure TIDesktopItems.Refresh;
var lv   : cardinal;
    ic   : integer;
    dll  : cardinal;
    hook : cardinal;
    ev   : cardinal;
begin
  if FPDesktopItems<>nil then UnMapViewOfFile(FPDesktopItems);
  if FFileMapping  <>0   then CloseHandle    (FFileMapping  );
  lv:=FindWindowEx(FindWindowEx(FindWindow('Progman','Program Manager'),0,'SHELLDLL_DefView',''),0,'SysListView32','');
  if lv<>0 then ic:=SendMessage(lv,LVM_GETITEMCOUNT,0,0) else ic:=0;
  FFileMapping:=CreateFileMapping(cardinal(-1),nil,PAGE_READWRITE,0,4+ic*sizeOf(TDesktopItem),'mappedMemoryForDesktopIcons');
  if FFileMapping<>0 then begin
    FPDesktopItems:=MapViewOfFile(FFileMapping,FILE_MAP_ALL_ACCESS,0,0,0);
    FPDesktopItems^.itemCount:=ic;
    dll:=LoadLibrary(pchar(ExtractFilePath(ParamStr(0))+'hook.dll'));
    if dll<>0 then
      try
        ev:=CreateEvent(nil,true,false,'eventForDesktopIcons');
        if ev<>0 then
          try
            hook:=SetWindowsHookEx(WH_GETMESSAGE,GetProcAddress(dll,'HookMessageProc'),dll,GetWindowThreadProcessID(lv,nil));
            if hook<>0 then
              try
                PostThreadMessage(GetWindowThreadProcessID(lv,nil),WM_NULL,0,0);
                WaitForSingleObject(ev,2000);
              finally UnhookWindowsHookEx(hook) end;
          finally CloseHandle(ev) end;
      finally FreeLibrary(dll) end;
  end else FPDesktopItems:=nil;
end;

function GetDesktopItems : IDesktopItems;
begin
  result:=TIDesktopItems.Create;
end;

end.

// "testDesktopItems.dpr" - application test project

program testDesktopItems;

uses Windows,
     SysUtils,
     desktopItems in 'desktopItems.pas';

procedure testDesktopItemsUnit;
var i1 : integer;
    s1 : string;
begin
  with GetDesktopItems do
    for i1:=0 to ItemCount-1 do
      s1:=s1+IntToStr(Position[i1].x)+'/'+IntToStr(Position[i1].y)+': "'+Name[i1]+'"'#$D#$A;
  MessageBox(0,pchar(s1),'Desktop Icons',0);
end;

begin
  testDesktopItemsUnit;
end.


i think you find that usefull..
0
 
craig_capelAuthor Commented:
Barry, you out to get all the points :)


Thanks i already got the code of you before to make it work thanks......


inthe, yes i would find it usefull, and really you did not need to go to the trouble of that, but thanks anyway, you really are an expert from all that!...

which means, i am going to have to give the points to inthe, otherwise its not totally fair? is it.....

Craig C.
0
 
intheCommented:
well now im confused  ;-)
do you need more help ?

Regards Barry
0
 
ptmcompCommented:
I think if that's your solution the points are for inthe
0
 
craig_capelAuthor Commented:
Taken From Above "which means, i am going to have to give the points to inthe, otherwise its not totally fair? is it..... "

that is saying that inthe gets the points :)

Like i said... inthe has the points.... post another message quick as an answer before i change my mind!...

Craig C.
0
 
intheCommented:
ok :-)
0
 
craig_capelAuthor Commented:
happy now :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now