======如何替换开始菜单(开始按钮)?在线等===== 我要做自己的开始菜单,如何把 Windows98 的“开始”按钮替换成我自己的按钮? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 思路:1. 得到开始按钮的句柄2. 隐含开始按钮, 新建一个按钮并且放在原来开始按钮的位置上.3. 取得新建按钮的事件, 并在里面写你想要的代码.4. 窗体关闭时记得把原来的开始按钮恢复!代码如下:unit StartButton;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) btnRestore: TButton; btnNew: TButton; procedure FormCreate(Sender: TObject); procedure btnNewClick(Sender: TObject); procedure btnRestoreClick(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } FNewButton : Boolean; // Check whether new start button had been created. procedure NewButtonMsg (Var Msg : TMessage); // new button events. public { Public declarations } end;var Form1: TForm1; OldProc, NewProc : Pointer; StartBtnHwnd, TrayHwnd, ReplaceBtnHwnd : Hwnd;implementation{$R *.DFM}function ButtonWndProc (CtlHandle : Hwnd; uMsg : Uint; AWParam : Wparam; ALparam : Lparam): HResult ;stdcall;var Rct : TRect; pt : TPoint;begin if uMsg = WM_LBUTTONUP then begin GetCursorPos(pt); GetClientRect(CtlHandle,Rct); MapWindowPoints(0,ctlHandle,pt,1); if PtInRect(Rct,pt) then Showmessage('You had clicked the new button !') end; Result := CallWindowProc(OldProc, CtlHandle,uMsg, AWParam, ALParam);end;procedure TForm1.FormCreate(Sender: TObject);begin TrayHwnd := FindWindow('Shell_TrayWnd', nil); StartBtnHwnd := FindWindowEx(TrayHwnd,0,'Button',nil);end;procedure TForm1.btnNewClick(Sender: TObject);var Rct : TRect; fnt : HFont;begin // Create New Button to replace start button! if FNewButton then Exit; // Don't create when new button had been created. Windows.GetWindowRect(StartBtnHwnd,Rct); ReplaceBtnHwnd := CreateWindowEx(WS_EX_WINDOWEDGE, 'Button','btnStartButton',WS_Child or WS_Visible, 0,0,rct.right - rct.left, Rct.bottom - Rct.top, TrayHwnd,0,0,nil); // Create a button, which parent is windows's Tray. if ReplaceBtnHwnd > 0 then begin // Hide old Start button. SetWindowPos(StartBtnHwnd,HWND_BOTTOM, Rct.left,rct.top,rct.right - rct.left, Rct.bottom - Rct.top, SWP_HIDEWINDOW {OR SWP_NOREDRAW}); // Set New button's font and caption. SetWindowText(ReplaceBtnHwnd, 'Start'); fnt := CreateFont(0,0,0,0,FW_NORMAL,0,0,0,ANSI_CHARSET,0,0,0,0,'Time New Romans'); SendMessage(ReplaceBtnHwnd, WM_SETFONT,fnt,MAKELPARAM(0,0)); // Show New start button. SetWindowPos(ReplaceBtnHwnd,HWND_TOPMOST, Rct.left,rct.top,rct.right - rct.left, Rct.bottom - Rct.top, SWP_SHOWWINDOW); ShowWindow(ReplaceBtnHwnd,SW_ShowNormal); UpdateWindow(ReplaceBtnHwnd); // To handle the new messages. NewProc := Pointer(LongInt(MakeObjectInstance(NewButtonMsg))); OldProc := Pointer(SetWindowLong(ReplaceBtnHwnd,GWL_WNDPROC,LongInt(NewProc))); if NewProc = nil then begin Showmessage('Can not grab new button''s message!'); Exit; end; FNewButton := True; end;end;procedure TForm1.btnRestoreClick(Sender: TObject);begin if FNewButton then // Restore Old Start button. begin SetWindowLong(ReplaceBtnHwnd,GWL_WNDPROC,LongInt(OldProc)); DestroyWindow(ReplaceBtnHwnd); ReplaceBtnHwnd := 0; ShowWindow(StartBtnHwnd,SW_ShowNormal); SetWindowPos(StartBtnHwnd,HWND_TOPMOST,0,0,50,30,SWP_SHOWWINDOW); FNewButton := False; end;end;procedure TForm1.NewButtonMsg(var Msg: TMessage);begin if Msg.Msg = WM_LBUTTONUP then showMessage('You had click the new start button') else Msg.Result := CallWindowProc(OldProc,ReplaceBtnHwnd,Msg.msg, msg.wParam, msg.lParam);end;procedure TForm1.FormDestroy(Sender: TObject);begin if FNewButton then btnRestoreClick(self); // Restore button when form exiting.end;end. 请教 语句怎么写 Treeview的问题 出让3成股份寻同步软件制作人员, 兼职即可 怎样把一个工程里的一个窗体Form1 复制到另一个工程中? 为什么打开某个窗体时Delphi会立即退出? 不太难,但是我不会!!! 在Delphi中如何把做好的软件发布? 向高手请教,急急急??? 为什么我点了dbgrid中的一行,前面也出现了一个小黑三角,可dbgrid1.SelectedRows.Count总是为0? 急问,关于delphi中调用Excel的问题 各位兄台,好东西不看可惜! 为什么Win2000下好好的Bmp图片到Win98下面目全非?
1. 得到开始按钮的句柄
2. 隐含开始按钮, 新建一个按钮并且放在原来开始按钮的位置上.
3. 取得新建按钮的事件, 并在里面写你想要的代码.
4. 窗体关闭时记得把原来的开始按钮恢复!代码如下:
unit StartButton;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
btnRestore: TButton;
btnNew: TButton;
procedure FormCreate(Sender: TObject);
procedure btnNewClick(Sender: TObject);
procedure btnRestoreClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
FNewButton : Boolean; // Check whether new start button had been created.
procedure NewButtonMsg (Var Msg : TMessage); // new button events.
public
{ Public declarations }
end;var
Form1: TForm1;
OldProc, NewProc : Pointer;
StartBtnHwnd, TrayHwnd, ReplaceBtnHwnd : Hwnd;implementation{$R *.DFM}function ButtonWndProc (CtlHandle : Hwnd; uMsg : Uint; AWParam : Wparam; ALparam : Lparam): HResult ;stdcall;
var
Rct : TRect;
pt : TPoint;
begin
if uMsg = WM_LBUTTONUP then
begin
GetCursorPos(pt);
GetClientRect(CtlHandle,Rct);
MapWindowPoints(0,ctlHandle,pt,1);
if PtInRect(Rct,pt) then
Showmessage('You had clicked the new button !')
end;
Result := CallWindowProc(OldProc, CtlHandle,uMsg, AWParam, ALParam);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
TrayHwnd := FindWindow('Shell_TrayWnd', nil);
StartBtnHwnd := FindWindowEx(TrayHwnd,0,'Button',nil);
end;procedure TForm1.btnNewClick(Sender: TObject);
var
Rct : TRect;
fnt : HFont;
begin
// Create New Button to replace start button!
if FNewButton then Exit; // Don't create when new button had been created.
Windows.GetWindowRect(StartBtnHwnd,Rct);
ReplaceBtnHwnd := CreateWindowEx(WS_EX_WINDOWEDGE,
'Button','btnStartButton',WS_Child or WS_Visible,
0,0,rct.right - rct.left, Rct.bottom - Rct.top,
TrayHwnd,0,0,nil); // Create a button, which parent is windows's Tray.
if ReplaceBtnHwnd > 0 then
begin
// Hide old Start button.
SetWindowPos(StartBtnHwnd,HWND_BOTTOM,
Rct.left,rct.top,rct.right - rct.left, Rct.bottom - Rct.top,
SWP_HIDEWINDOW {OR SWP_NOREDRAW});
// Set New button's font and caption.
SetWindowText(ReplaceBtnHwnd, 'Start');
fnt := CreateFont(0,0,0,0,FW_NORMAL,0,0,0,ANSI_CHARSET,0,0,0,0,'Time New Romans');
SendMessage(ReplaceBtnHwnd, WM_SETFONT,fnt,MAKELPARAM(0,0));
// Show New start button.
SetWindowPos(ReplaceBtnHwnd,HWND_TOPMOST,
Rct.left,rct.top,rct.right - rct.left, Rct.bottom - Rct.top,
SWP_SHOWWINDOW);
ShowWindow(ReplaceBtnHwnd,SW_ShowNormal);
UpdateWindow(ReplaceBtnHwnd);
// To handle the new messages.
NewProc := Pointer(LongInt(MakeObjectInstance(NewButtonMsg)));
OldProc := Pointer(SetWindowLong(ReplaceBtnHwnd,GWL_WNDPROC,LongInt(NewProc)));
if NewProc = nil then
begin
Showmessage('Can not grab new button''s message!');
Exit;
end;
FNewButton := True;
end;end;procedure TForm1.btnRestoreClick(Sender: TObject);
begin
if FNewButton then // Restore Old Start button.
begin
SetWindowLong(ReplaceBtnHwnd,GWL_WNDPROC,LongInt(OldProc));
DestroyWindow(ReplaceBtnHwnd);
ReplaceBtnHwnd := 0;
ShowWindow(StartBtnHwnd,SW_ShowNormal);
SetWindowPos(StartBtnHwnd,HWND_TOPMOST,0,0,50,30,SWP_SHOWWINDOW);
FNewButton := False;
end;
end;procedure TForm1.NewButtonMsg(var Msg: TMessage);
begin
if Msg.Msg = WM_LBUTTONUP then
showMessage('You had click the new start button')
else
Msg.Result := CallWindowProc(OldProc,ReplaceBtnHwnd,Msg.msg, msg.wParam, msg.lParam);
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
if FNewButton then
btnRestoreClick(self); // Restore button when form exiting.
end;end.