Link to home
Start Free TrialLog in
Avatar of ahen72
ahen72

asked on

replace the default Windows Start Menu

Hello,

I want to replace the default Windows Start Menu with my own popupmenu.
Left and right mouse click for different popupmenus.

I hope you can help me.

Best regards
Achim Henning
Avatar of GloomyFriar
GloomyFriar

Firstly hide standard "Start" button.

Then make fake "Start" button from your programm.
Avatar of ahen72

ASKER

That's what I already did - works ... but I need do have different Start button bitmaps for different types of operating sytems ... and
I need to lock the taskbar, because my new start button is just always on top of the start buttons starting positonm.

I'm looking for a way to hook the mouse ... any ideas/solutios ?

regards
Achim

ASKER CERTIFIED SOLUTION
Avatar of fanar
fanar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello Achim, I read your post and what you're doing picked my interest Therefore I wanted to ask you something about the swapping startbutton-thing. (sorry but I really haven't got a clue as to how I could help you out  > it seems the other way around actually but I'm more than willing to reward you for an answer to my question and I'm far from greedy so;)
How do you get a hold of the startbutton and place your own on the taskbar? i manage to hide it but I'd like to know how I could add something to it like for instance a startbutton. Can you perhaps share your code with me since uptil now I didnot think this was possible and to be honest I'm still not convinced it can......Thanks in advance and tell me what you need for sharing your code which does the swapping thing okay?

My regards,

Paul
Hey they code below was not written by me but it shows u how to use a journal hook which monitors the mouse and when the user clicks anywhere it tells u the window on which it was clicked( the HWND of the window) so u can put ur own button there and check to see its hwnd then popup menu.

Or

U could put this into a dll and make a mouse hook but thats longer and more complicated.

unit MouseButton;

interface

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

type
  TForm1 = class(TForm)
    Button_StartJour: TButton;
    Button_StopJour: TButton;
    ApplicationEvents1: TApplicationEvents;
    Memo1: TMemo;
    procedure Button_StartJourClick(Sender: TObject);
    procedure Button_StopJourClick(Sender: TObject);
    procedure ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  JHook: THandle;
Track: Boolean;

implementation

{$R *.dfm}

function JournalProc(Code, wParam: Integer; var EventStrut: TEVENTMSG): Integer; stdcall;
var
Char1: PChar;
Title: array[0..256] of char;
begin
{this is the JournalRecordProc}
Result := CallNextHookEx(JHook, Code, wParam, Longint(@EventStrut));
{the CallNextHookEX is not really needed for journal hook since it it not
really in a hook chain, but it's standard for a Hook}
if Code < 0 then Exit;
{you should cancel operation if you get HC_SYSMODALON}
if Code = HC_SYSMODALON then Exit;
if (Code = HC_ACTION) then
begin
{the EventStrut record has the Information about the mouse or keyboard
event. You said you just wanted the mouse button events so I get the
mouse down and mouse up event messages}
  if EventStrut.message = WM_LBUTTONDOWN then
  begin
   GetWindowText(GetActiveWindow,Title,256);
   form1.Memo1.Lines.Add(String(Title)+'-'+IntToStr((EventStrut.hwnd)));
  end;
end;
end;


procedure TForm1.Button_StartJourClick(Sender: TObject);

begin
if Track then
begin
ShowMessage('Mouse is already being Journaled, can not restart');
Exit;
end;

JHook := SetWindowsHookEx(WH_JOURNALRECORD , @JournalProc, hInstance,0);
{SetWindowsHookEx starts the Hook}
if JHook > 0 then
begin
Track := True;
end else
ShowMessage('No Journal Hook availible');
end;



procedure TForm1.Button_StopJourClick(Sender: TObject);
begin
Track := False;
UnhookWindowsHookEx(JHook);
JHook := 0;
end;


procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
  var Handled: Boolean);
begin
{the journal hook is automaticly camceled if the Task manager
(Ctrl-Alt-Del) or the Ctrl-Esc keys are pressed, you restart it
when the WM_CANCELJOURNAL is sent to the parent window, Application}
Handled := False;
if (Msg.message = WM_CANCELJOURNAL) and Track then
JHook := SetWindowsHookEx(WH_JOURNALRECORD , @JournalProc, 0, 0);
end;


procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnhookWindowsHookEx(JHook);

end;

procedure TForm1.FormCreate(Sender: TObject);
begin

end;

end.


DFM File

object Form1: TForm1
  Left = 192
  Top = 123
  Width = 544
  Height = 375
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnClose = FormClose
  PixelsPerInch = 96
  TextHeight = 13
  object Button_StartJour: TButton
    Left = 32
    Top = 24
    Width = 113
    Height = 25
    Caption = 'Button_StartJour'
    TabOrder = 0
    OnClick = Button_StartJourClick
  end
  object Button_StopJour: TButton
    Left = 32
    Top = 88
    Width = 105
    Height = 25
    Caption = 'Button_StopJour'
    TabOrder = 1
    OnClick = Button_StopJourClick
  end
  object ListBox1: TListBox
    Left = 160
    Top = 56
    Width = 305
    Height = 273
    ItemHeight = 13
    TabOrder = 2
  end
  object ApplicationEvents1: TApplicationEvents
    OnMessage = ApplicationEvents1Message
    Left = 224
    Top = 8
  end
end


Avatar of ahen72

ASKER

Fanar,

I can see now where the user clicks and I can show my own startmenu when he is clicking on the startbutton, but the problem is that the original startmenu is then already opened ! Do you you now how to disable this, too ?


Best regards and thanks so far
Achim
Avatar of ahen72

ASKER

I also find a very good solution on: http://www.swissdelphicenter.ch/en/showcode.php?id=328 --> Code at the end !

With that solution it's possible to complete hide the start button and put a new button where the original was.
But that's only working with normal buttons not with BITBTN ... but I need a BITBTN !
Perhaps someone can help again !

Thanks in advance
Achim

The code from http://www.swissdelphicenter.ch/en/showcode.php?id=328:



{
  The ShowStartButton function shows how to hide the start
  button, how to disable the windows buttons (LWin and RWin)
  (indirectly) and consequently how to hide the start menu.
}

procedure ShowStartButton(bvisible: Boolean);
var
  h: hwnd;
  TaskWindow: hwnd;
begin
  if bvisible then
  begin
    h := FindWindowEx(GetDesktopWindow, 0, 'Button', nil);
    TaskWindow := FindWindow('Shell_TrayWnd', nil);
    ShowWindow(h, 1);
    Windows.SetParent(h, TaskWindow);
  end  
  else
  begin
    h := FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'Button', nil);
    ShowWindow(h, 0);
    Windows.SetParent(h, 0);
  end;
end;


{Example to hide/reshow the Startbutton}

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowStartButton(False); // or true to reshow
end;

{Furthermore, you could create your own Startbutton and
replace the original one with your own.}
var
  b: TButton;  // or another Type of button
  h, Window: hwnd;
begin
  Window := FindWindow('Shell_TrayWnd', nil);
  b := TButton.Create(nil);
  b.ParentWindow := Window;
  b.Caption := 'Start';
  b.Width := 52;
  b.Height := 22;
  b.Font.Style := [fsbold];
end;
Hey check this out this is a hook program that subclasses msn and then adds a menu to it. It incluedes event handling also

You should find everything u need in here

https://www.experts-exchange.com/questions/20429026/SubClassing-Extern-Program.html#7621675

Hope this helps ,
Anar