蓝色动力网络

 找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 4139|回复: 0

网吧游戏菜单开发步骤之一

[复制链接]
发表于 2008-8-12 09:27:42 | 显示全部楼层 |阅读模式
最近项目里需要一个游戏菜单,翻遍了目前网吧的游戏菜单,什么形状都有人做了,而且有很多做的很漂亮。那么我将以一个什么样的思路去做呢?要做出自己的特色。下面我来一步步的把步骤说上来,希望对新手有帮助。

    前些日子,一直在玩鱼鱼桌面秀这款软件,做的很不错。但不大适应网吧,好,就瞄准这个软件的一些可取之处来做。首先这款软件的桌面图标其实是一个小窗体,利用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图片形状,而且是透明的。

这是一个小小的例子。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

蓝色动力网络微信平台
网站管理,业务合作联系邮箱: admin#lansedongli.com    QQ:13412492 限网站业务问题.
网站帐号、密码、密保找回请使用注册邮箱,发送邮件至 password#lansedongli.com ,否则不予受理.
免责声明:本论坛所有文字和图片仅代表其个人观点.
本站某些资料或文章来自于互联网,不代表本站观点,如果侵犯了您的权益,请来信告知,我们会在三天内删除.
为了给大家一个更好的交流场所,请勿在本论坛发表与中华人民共和国法律相抵触的言论,请合作,谢谢!
Copyright © 2007-2019 Corporation Powered by网吧系统 版权所有    转载请注明!
浙ICP备11043737号-1 程序:Discuz! x3.4

湘公网安备 43018102000145号

手机版|Archiver|蓝色动力网络   

快速回复 返回顶部 返回列表