|
最近项目里需要一个游戏菜单,翻遍了目前网吧的游戏菜单,什么形状都有人做了,而且有很多做的很漂亮。那么我将以一个什么样的思路去做呢?要做出自己的特色。下面我来一步步的把步骤说上来,希望对新手有帮助。
前些日子,一直在玩鱼鱼桌面秀这款软件,做的很不错。但不大适应网吧,好,就瞄准这个软件的一些可取之处来做。首先这款软件的桌面图标其实是一个小窗体,利用GDI把PNG背景画到窗体上。代码如下:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm2 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{$R PNG.RES}
uses ActiveX;
type
DebugEventLevel = (
DebugEventLevelFatal,
DebugEventLevelWarning
);
TDebugEventLevel = DebugEventLevel;
DebugEventProc = procedure(level: DebugEventLevel; message: PChar); stdcall;
GdiplusStartupInput = packed record
GdiplusVersion: Cardinal;
DebugEventCallback: DebugEventProc;
SuppressBackgroundThread: BOOL;
SuppressExternalCodecs: BOOL;
end;
TGdiplusStartupInput = GdiplusStartupInput;
PGdiplusStartupInput = ^TGdiplusStartupInput;
NotificationHookProc = function(out token: ULONG): Integer; stdcall;
NotificationUnhookProc = procedure(token: ULONG); stdcall;
GdiplusStartupOutput = packed record
NotificationHook : NotificationHookProc;
NotificationUnhook: NotificationUnhookProc;
end;
TGdiplusStartupOutput = GdiplusStartupOutput;
PGdiplusStartupOutput = ^TGdiplusStartupOutput;
function GdipCreateHBITMAPFromBitmap(bitmap: THandle; out hbmReturn: HBITMAP;
background: Longword): Integer; stdcall; external 'gdiplus.dll';
function GdipCreateBitmapFromFile(filename: PWChar; out bitmap: THandle): Integer;
stdcall; external 'gdiplus.dll';
function GdipCreateBitmapFromStreamICM(stream: ISTREAM;
out bitmap: THandle): Integer; stdcall; external 'gdiplus.dll';
function GdipDisposeImage(image: THandle): Integer; stdcall;
stdcall; external 'gdiplus.dll';
function GdiplusStartup(out token: ULONG; input: PGdiplusStartupInput;
output: PGdiplusStartupOutput): Integer; stdcall; external 'gdiplus.dll';
procedure GdiplusShutdown(token: ULONG); stdcall; external 'gdiplus.dll';
procedure TForm2.FormCreate(Sender: TObject);
var
vGdip: THandle;
vBitmap: HBITMAP;
vOldBitmap: HBITMAP;
vPoint1, vPoint2: TPoint;
vSize: TSize;
vBlendFunction: TBlendFunction;
vDC: HDC;
vBitmapInfo: TBitmapInfoHeader;
vDIBSection: TDIBSection;
vBuffer: PChar;
vStream: IStream;
vGlobal: THandle;
begin
SetWindowLong(Handle, GWL_EXSTYLE,
GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
///////Begin 从资源中载入
with TResourceStream.Create(HInstance, 'NETGAME', 'PNG') do try
vGlobal := GlobalAlloc(GHND, Size);
if vGlobal = 0 then Exit;
vBuffer := GlobalLock(vGlobal);
if not Assigned(vBuffer) then Exit;
try
Read(vBuffer^, Size);
finally
GlobalUnlock(vGdip);
end;
if CreateStreamOnHGlobal(vGlobal, False, vStream) <> S_OK then Exit;
if GdipCreateBitmapFromStreamICM(vStream, vGdip) <> S_OK then Exit;
GlobalFree(vGlobal);
finally
Free;
end;
///////End 从资源中载入
if GdipCreateHBITMAPFromBitmap(vGdip, vBitmap, 0) <> S_OK then Exit;
vBitmapInfo.biSize := SizeOf(vBitmapInfo);
GetObject(vBitmap, SizeOf(vDIBSection), @vDIBSection);
vPoint1 := Point(Left, Top);
vPoint2 := Point(0, 0);
vSize.cx := vDIBSection.dsBm.bmWidth;
vSize.cy := vDIBSection.dsBm.bmHeight;
vBlendFunction.BlendOp := AC_SRC_OVER;
vBlendFunction.BlendFlags := 0;
vBlendFunction.SourceConstantAlpha := $FF; // 透明度
vBlendFunction.AlphaFormat := AC_SRC_ALPHA; //同上
vDC := CreateCompatibleDC(Canvas.Handle);
vOldBitmap := SelectObject(vDC, vBitmap);
UpdateLayeredWindow(Handle, Canvas.Handle,
@vPoint1, @vSize, vDC, @vPoint2, 0, @vBlendFunction, ULW_ALPHA);
SelectObject(vDC, vOldBitmap);
DeleteDC(vDC);
DeleteObject(vBitmap);
GdipDisposeImage(vGdip);
end;
procedure TForm2.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
Perform(WM_SYSCOMMAND, SC_MOVE or HTCLIENT, 0); // 拖动
end;
var
vStartupInput: TGDIPlusStartupInput;
vToken: ULONG;
initialization
vStartupInput.DebugEventCallback := nil;
vStartupInput.SuppressBackgroundThread := False;
vStartupInput.SuppressExternalCodecs := False;
vStartupInput.GdiplusVersion := 1;
GdiplusStartup(vToken, @vStartupInput, nil);
finalization
GdiplusShutdown(vToken);
end.
上面的代码实现了类似桌面精灵样的东西,窗体形状就是PNG图片形状,而且是透明的。
这是一个小小的例子。 |
广告, 技术, 空间, 系统, 服务器, 教程, 破解, 服务器, 诺德尔, 破解, 3389, 服务器, 锐起, 网吧, 无盘, 教程, 绿茶, 诺德尔, 软件, 系统, 诺德尔, 绿茶, 系统, FTP, Windows, 系统, 电脑, 教程, 网络, ROS, ROS, ROS, 路由, 路由, linux, 网络,
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|