130分是我最后的一点分了,菜鸟想知道怎么实现象很多游戏那样,比如按了esc键,一个窗体慢慢变黑,然后另一个窗体显示出来,我想应该是在窗体关闭的事件加入了什么东

  • 主题发起人 主题发起人 wanglong
  • 开始时间 开始时间
W

wanglong

Unregistered / Unconfirmed
GUEST, unregistred user!
130分是我最后的一点分了,菜鸟想知道怎么实现象很多游戏那样,比如按了esc键,一个窗体慢慢变黑,然后另一个窗体显示出来,我想应该是在窗体关闭的事件加入了什么东西吧?请高手指点!!(130分)<br />菜鸟想知道怎么实现象很多游戏那样,比如按了esc键,一个窗体慢慢变黑,然后另一个窗体显示出来,我想应该是在窗体关闭的事件加入了什么东西吧?请高手指点!!
 
实现是很困难的,不过我推荐一个控件
SkinEngine
你在网上找找吧,做窗体皮肤的,还有很多效果
 
可以不可以用背景图片通过TIMER来控制呢
如果再用图片控件,应该有效果,不过资源占用可能不小
 
可以用DirectDraw:
-------------------------------------

///////////////////////////////////////////////////////////////////////////////
// mytest_api.dpr
///////////////////////////////////////////////////////////////////////////////
// This is my test program;
///////////////////////////////////////////////////////////////////////////////
program mytest_api;

//-----------------------------------------------------------------------------
// Include files
//-----------------------------------------------------------------------------
uses
Windows, Messages, DirectDraw, SysUtils, DDUtil;

{$R *.res}

const
//---------------------------------------------------------------------------
// Local definitions
//---------------------------------------------------------------------------
NAME: PChar = 'DDExample2';
TITLE: PChar = 'Direct Draw Example 2';
szBitmap: PChar = 'Background.BMP';
Step: Integer = 100; //Fade In Step Count
var
//---------------------------------------------------------------------------
// Global data
//---------------------------------------------------------------------------
g_pDD: IDirectDraw7; // DirectDraw object
g_pDDSPrimary: IDirectDrawSurface7; // DirectDraw primary surface
g_pDDSBackGround: IDirectDrawSurface7; // DirectDraw back surface
g_pDDPal: IDIRECTDRAWPALETTE; // The primary surface palette
ddsd: TDDSurfaceDesc2;
AnimPalette, OrgPalette: array[0..255] of PALETTEENTRY; //调色板条目
g_bActive: Boolean = False; // Is application active?

//-----------------------------------------------------------------------------
// Name: ReleaseAllObjects
// Desc: Finished with all objects we use; release them
//-----------------------------------------------------------------------------

procedure ReleaseAllObjects;
begin
if Assigned(g_pDD) then
begin
if Assigned(g_pDDSPrimary) then
begin
g_pDDSPrimary := nil;
end;
if Assigned(g_pDDPal) then
begin
g_pDDPal := nil;
end;
if Assigned(g_pDDSBackGround) then
begin
g_pDDSBackGround := nil;
end;
g_pDD := nil;
end;
end;

//-----------------------------------------------------------------------------
// Name: InitFail
// Desc: This function is called if an initialization function fails
//-----------------------------------------------------------------------------

function InitFail(h_Wnd: HWND; hRet: HRESULT; Text: string): HRESULT;
begin
ReleaseAllObjects;
MessageBox(h_Wnd, PChar(Text + ': ' + DDErrorString(hRet)), TITLE, MB_OK);
DestroyWindow(h_Wnd);
Result := hRet;
end;

//-----------------------------------------------------------------------------
// Name: FadeOut
// Desc: FadeOut
//-----------------------------------------------------------------------------

procedure FadeOut;
var
i, j: integer;
begin
for i := 0 to Step do
begin
for j := 0 to 255 do
begin
AnimPalette[j].peRed := OrgPalette[j].peRed - Trunc((OrgPalette[j].peRed * i) / Step);
AnimPalette[j].peGreen := OrgPalette[j].peGreen - Trunc((OrgPalette[j].peGreen * i) / Step);
AnimPalette[j].peBlue := OrgPalette[j].peBlue - Trunc((OrgPalette[j].peBlue * i) / Step);
AnimPalette[j].peFlags := PC_RESERVED;
end;
g_pDDPal.SetEntries(0, 0, 256, @AnimPalette);
Sleep(30);
end;
end;

//-----------------------------------------------------------------------------
// Name: FadeIn
// Desc: FadeIn
//-----------------------------------------------------------------------------

procedure FadeIn;
var
i, j: integer;
begin
for i := 0 to Step do
begin
for j := 0 to 255 do
begin
AnimPalette[j].peRed := Trunc((OrgPalette[j].peRed * i) / Step);
AnimPalette[j].peGreen := Trunc((OrgPalette[j].peGreen * i) / Step);
AnimPalette[j].peBlue := Trunc((OrgPalette[j].peBlue * i) / Step);
AnimPalette[j].peFlags := PC_RESERVED;
end;
g_pDDPal.SetEntries(0, 0, 256, @AnimPalette);
Sleep(30);
end;
end;

//-----------------------------------------------------------------------------
// Name: InitSurface
// Desc: Load a Bitmap into PrimarySurface.
//-----------------------------------------------------------------------------

procedure DrawSurface;
var
hRet: HRESULT;
begin
if g_pDDSBackGround = nil then exit;
hRet := g_pDDSPrimary.Blt(nil, g_pDDSBackGround, nil, DDBLT_WAIT, nil);
if hRet = DDERR_SURFACELOST then
begin
hRet := g_pDDSPrimary._Restore;
if hRet = DD_OK then
begin
hRet := g_pDDSBackGround._Restore;
if hRet = DD_OK then
begin
hRet := DDReLoadBitmap(g_pDDSBackGround, szBitmap);
if hRet = DD_OK then
g_pDDSPrimary.Blt(nil, g_pDDSBackGround, nil, DDBLT_WAIT, nil);
end;
end;
end;
end;

//-----------------------------------------------------------------------------
// Name: WindowProc
// Desc: The Main Window Procedure
//-----------------------------------------------------------------------------

function WindowProc(h_Wnd: HWND; aMSG: Cardinal; wParam: Cardinal; lParam: Integer): Integer; stdcall;
var
ps: PAINTSTRUCT;
begin
case aMSG of
// Pause if minimized
WM_ACTIVATE:
begin
if HIWORD(wParam) = 0 then
g_bActive := True
else
g_bActive := False;
Result := 0;
Exit;
end;
// Clean up and close the app
WM_DESTROY:
begin
ReleaseAllObjects;
PostQuitMessage(0);
Result := 0;
Exit;
end;
// Handle any non-accelerated key commands
WM_KEYDOWN:
begin
case wParam of
VK_ESCAPE:
begin
FadeOut;
PostMessage(h_Wnd, WM_CLOSE, 0, 0);
Result := 0;
Exit;
end;
VK_F11:
begin
FadeIn;
Result := 0;
Exit;
end;
Vk_F12:
begin
FadeOut;
Result := 0;
Exit;
end;
end;
end;
// Turn off the cursor since this is a full-screen app
WM_SETCURSOR:
begin
SetCursor(0);
Result := 1;
Exit;
end;
WM_PAINT:
begin
BeginPaint(h_Wnd, ps);
DrawSurface;
EndPaint(h_wnd, ps);
Result := 0;
Exit;
end;
end;

Result := DefWindowProc(h_Wnd, aMSG, wParam, lParam);
end;

//-----------------------------------------------------------------------------
// Name: InitApp
// Desc: Do work required for every instance of the application:
// Create the window, initialize data
//-----------------------------------------------------------------------------

function InitApp(hInst: THANDLE; nCmdShow: Integer): HRESULT;
var
h_Wnd: HWND;
wc: WNDCLASS;
hRet: HRESULT;
pDDTemp: IDirectDraw;
begin
// Set up and register window class
wc.style := CS_HREDRAW or CS_VREDRAW;
wc.lpfnWndProc := @WindowProc;
wc.cbClsExtra := 0;
wc.cbWndExtra := 0;
wc.hInstance := hInst;
wc.hIcon := LoadIcon(hInst, 'MAINICON');
wc.hCursor := LoadCursor(0, IDC_ARROW);
wc.hbrBackground := GetStockObject(BLACK_BRUSH);
wc.lpszMenuName := NAME;
wc.lpszClassName := NAME;
RegisterClass(wc);

// Create a window
h_Wnd := CreateWindowEx(WS_EX_TOPMOST,
NAME,
TITLE,
WS_POPUP,
0,
0,
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN),
0,
0,
hInst,
nil);

if h_Wnd = 0 then
begin
Result := 0;
Exit;
end;

ShowWindow(h_Wnd, nCmdShow);
UpdateWindow(h_Wnd);
SetFocus(h_Wnd);

///////////////////////////////////////////////////////////////////////////
// Create the main DirectDraw object
///////////////////////////////////////////////////////////////////////////
hRet := DirectDrawCreate(nil, pDDTemp, nil);
if hRet <> DD_OK then
begin
Result := InitFail(h_Wnd, hRet, 'DirectDrawCreate FAILED');
Exit;
end;
hRet := pDDTemp.QueryInterface(IDirectDraw7, g_pDD);
if hRet <> DD_OK then
begin
Result := InitFail(h_Wnd, hRet, 'QueryInterface FAILED');
Exit;
end;
pDDTemp := nil;

// Get exclusive mode
hRet := g_pDD.SetCooperativeLevel(h_Wnd, DDSCL_EXCLUSIVE or DDSCL_FULLSCREEN);
if hRet <> DD_OK then
begin
Result := InitFail(h_Wnd, hRet, 'SetCooperativeLevel FAILED');
Exit;
end;

// Set the video mode to 640X480x8
hRet := g_pDD.SetDisplayMode(640, 480, 8, 0, 0);
if hRet <> DD_OK then
begin
Result := InitFail(h_Wnd, hRet, 'SetDisplayMode FAILED');
Exit;
end;

// Create the primary surface
FillChar(ddsd, SizeOf(ddsd), 0);
ddsd.dwSize := SizeOf(ddsd);
ddsd.dwFlags := DDSD_CAPS;
ddsd.ddsCaps.dwCaps := DDSCAPS_PRIMARYSURFACE;
hRet := g_pDD.CreateSurface(ddsd, g_pDDSPrimary, nil);
if hRet <> DD_OK then
begin
Result := InitFail(h_Wnd, hRet, 'CreateSurface FAILED');
Exit;
end;

// Create and set the palette
g_pDDPal := DDLoadPalette(g_pDD, szBitmap);
if g_pDDPal = nil then
begin
Result := InitFail(h_Wnd, hRet, 'DDLoadPalette FAILED');
Exit;
end;

//取得调色板条目
g_pDDpal.GetEntries(0, 0, 256, @OrgPalette);

hRet := g_pDDSPrimary.SetPalette(g_pDDPal);
if hRet <> DD_OK then
begin
Result := InitFail(h_Wnd, hRet, 'SetPalette FAILED');
Exit;
end;

// Create the offscreen surface, by loading our bitmap.
g_pDDSBackGround := DDLoadBitmap(g_pDD, szBitmap, 0, 0);
if g_pDDSBackGround = nil then
begin
Result := InitFail(h_Wnd, hRet, 'DDLoadBitmap FAILED');
Exit;
end;

DrawSurface;

SetCursor(0);
FadeIn;

Result := DD_OK;
end;

//-----------------------------------------------------------------------------
// Name: WinMain
// Desc: Initialization, message loop
//-----------------------------------------------------------------------------

type
Screen = array of Word;
var
aMSG: MSG;
begin
if InitApp(GetModuleHandle(nil), SW_SHOW) <> DD_OK then
begin
Exit;
end;

while True do
begin
if PeekMessage(aMsg, 0, 0, 0, PM_NOREMOVE) then
begin
if not GetMessage(aMsg, 0, 0, 0) then
Exit;
TranslateMessage(aMsg);
DispatchMessage(aMsg);
end
else
begin
// Make sure we go to sleep if we have nothing else to do
WaitMessage;
end;
end;

end.

 
这里有源程序:
http://www.playicq.com/dispdoc.php?t=&amp;id=169
 
http://www.ccidnet.com/html/tech/guide/2001/08/21/58_3018.html
 
如果你用的是Win2k,一个简单但不正宗的办法是这样:
-----------------------------------------------------
unit Unit1;

interface

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

Const
WS_EX_LAYERED = $80000;
LWA_ALPHA = 2;

type
TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

function SetLayeredWindowAttributes(Handle: HWND;
COLORKEY: COLORREF; Alpha: BYTE; Flags: DWORD): Boolean; stdcall; external 'USER32.DLL';

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
SetWindowLong(Handle,GWL_EXSTYLE,GetWindowLong(Handle,GWL_EXSTYLE) or WS_EX_LAYERED);
SetLayeredWindowAttributes(Form1.Handle, RGB(255,255,255), tag*40, LWA_ALPHA);
color:= RGB(tag,tag,tag);
tag := tag + 1;
end;

end.
 
zw84611大侠你好,您提供的代码好用,但是缺少控件或着文件,能提供给我吗?
缺少DirectDraw.dcu,DirectDraw是什么东西,是控件吗?在哪里下载?
 
用的是TIME控件
 
我问的是zw84611大侠提供的第一个代码缺少什么控件,没问最后一个!!!
 
不是控件,是单元。
http://kuga.51.net/download/files/directx7.rar
到这里看一下:
http://kuga.51.net/download/index.htm
 
//这段是程序运行时的渐变画面,关闭时同理。
program Mdiapp;
begin
Application.Initialize;
Application.Title := '仪器管理系统 1.0';
{ 创建封面 }
Splash := TSplash.Create(Application);
Splash.Show; // 显示封面
Splash.Update; // 强制更新封面
{ 下面通过定时器来延时}
while Splash.Timer1.Enabled do
Application.ProcessMessages; //让程序循环不断处理消息,直到定时器被禁止为止
Application.CreateForm(TMainForm, MainForm);
{主窗口显示出来后,隐藏并释放封面}
Splash.Hide;
Splash.Free;
Application.Run;
end.

procedure TSplash.Timer1Timer(Sender: TObject);
{延时3秒,以便可以清楚看到封面的内容}
begin
Timer1.Enabled:=False; //延时达到3秒后,禁止定时器
end;
 
用DirectX做最好,也最麻烦,看看DelphiX吧,里面有现成的例子,还可以用调色板动
画来做,这个简单一些,但是效果不好
 
用api: animateWindow, 指定AW_BLEND参数

AnimateWindow
The AnimateWindow function enables you to produce special effects when showing or hiding windows. There are three types of animation: roll, slide, and alpha-blended fade.

BOOL AnimateWindow(
HWND hwnd, // handle to window
DWORD dwTime, // duration of animation
DWORD dwFlags // animation type
);
Parameters
hwnd
[in] Handle to the window to animate. The calling thread must own this window.
dwTime
[in] Specifies how long it takes to play the animation, in milliseconds. Typically, an animation takes 200 milliseconds to play.
dwFlags
[in] Specifies the type of animation. This parameter can be one or more of the following values. Value Description
AW_SLIDE Uses slide animation. By default, roll animation is used. This flag is ignored when used with AW_CENTER.
AW_ACTIVATE Activates the window. Do not use this value with AW_HIDE.
AW_BLEND Uses a fade effect. This flag can be used only if hwnd is a top-level window.
AW_HIDE Hides the window. By default, the window is shown.
AW_CENTER Makes the window appear to collapse inward if AW_HIDE is used or expand outward if the AW_HIDE is not used.
AW_HOR_POSITIVE Animates the window from left to right. This flag can be used with roll or slide animation. It is ignored when used with AW_CENTER or AW_BLEND.
AW_HOR_NEGATIVE Animates the window from right to left. This flag can be used with roll or slide animation. It is ignored when used with AW_CENTER or AW_BLEND.
AW_VER_POSITIVE Animates the window from top to bottom. This flag can be used with roll or slide animation. It is ignored when used with AW_CENTER or AW_BLEND.
AW_VER_NEGATIVE Animates the window from bottom to top. This flag can be used with roll or slide animation. It is ignored when used with AW_CENTER or AW_BLEND.


Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. The function will fail in the following situations:

The window uses the window region.
The window is already visible and you are trying to show the window.
The window is already hidden and you are trying to hide the window.
To get extended error information, call the GetLastError function.

Remarks
You can combine AW_HOR_POSITIVE or AW_HOR_NEGATIVE with AW_VER_POSITIVE or AW_VER_NEGATIVE to animate a window diagonally.

The window procedures for the window and its child windows may need to handle any WM_PRINT or WM_PRINTCLIENT messages. Dialog boxes, controls, and common controls already handle WM_PRINTCLIENT. The default window procedure already handles WM_PRINT.

Requirements
Windows NT/2000 or later: Requires Windows 2000 or later.
Windows 95/98/Me: Requires Windows 98 or later.
Header: Declared in Winuser.h; include Windows.h.
Library: Use User32.lib.

See Also
Windows Overview, Window Functions, WM_PRINT, WM_PRINTCLIENT

 
多人接受答案了。
 
后退
顶部