用delphi製作由小到大的動畫窗體!

2021-04-01 21:55:51 字數 2804 閱讀 3125

vb 製作由小到大的窗體是很容易的,在load事件中,改變其form的大小就可以了。大體上的**如下:

private declare function getwindowrect lib "user32" (byval hwnd as long, lprect as rect) as long

private declare function getdc lib "user32" (byval hwnd as long) as long

private declare function rectangle lib "gdi32" (byval hdc as long, byval x1 as long, byval y1 as long, byval x2 as long, byval y2 as long) as long

private declare function deletedc lib "gdi32" (byval hdc as long) as long

private type rect

left as long

top as long

right as long

bottom as long

end type

private sub explode(newform as form, increment as integer)

dim size as rect ' setup form as rect type

getwindowrect newform.hwnd, size

dim formwidth, formheight as integer ' establish dimension variables

formwidth = (size.right - size.left)

formheight = (size.bottom - size.top)

dim tempdc

tempdc = getdc(byval 0&) ' obtain memory dc for resizing

dim count, leftpoint, toppoint, nwidth, nheight as integer ' establish resizing variables

for count = 1 to increment ' loop to new sizes

nwidth = formwidth * (count / increment)

nheight = formheight * (count / increment)

leftpoint = size.left + (formwidth - nwidth) / 2

toppoint = size.top + (formheight - nheight) / 2

rectangle tempdc, leftpoint, toppoint, leftpoint + nwidth, toppoint + nheight ' draw rectangles to build form

next count

deletedc (tempdc) ' release memory resource

end sub

private sub form_load()

explode me, 1000 ' open this form by number of desired increment

end sub

本來vb也不過是在呼叫api,所以這樣的**完全可以遷移到delphi中,可是遷移到delphi 後,用這樣的**在

oncreate或者onshow時間中都不起作用,由於現在忙還沒搞清楚怎麼回事,但是可以在onactive時間中先讓

form 隱藏了,再作這個效果,是可以的,方法是showwindow(form.handle,sw_hide), 不過這樣不太好,換一種方法,我是這麼做的:

procedure explodeform (form:tform;increment:real);

var rect:trect;

formheight:real;

formwidth:real;

i,:integer;

rgn:hrgn;

centerpoint:tpoint;

begin

getwindowrect(form.handle,rect);

formheight:=rect.bottom -rect.top;

formwidth:=rect.right -rect.left;

centerpoint.x:=round(formwidth/2);

centerpoint.y:=round(formheight/2);

for i:=1 to round(increment) do

begin

nwidth:=round(formwidth*i/increment);

rgn:=createrectrgn(centerpoint.x-nwidth,centerpoint.y-nwidth,centerpoint.x+nwidth,centerpoint.y +nwidth);

setwindowrgn(form.handle,rgn,true);

showwindow(form.handle,sw_show);

deleteobject(rgn);

end;

end;

然後在oncreate事件中呼叫就好了:explodeform(form1,60); 比vb那個效果好一點,當然這格**放在vc的

oninitdialog事件中,照樣實現vc的窗體由小到大!

至於rectangle為啥沒起作用,我還得查查,先交了活!

用Delphi製作動態選單

所謂動態選單是指選單項隨著程式的操作變化而變化。現在,我們用delphi來實現這一功能,具體步驟如下 1 首先,確定動態選單的資料 即要確定動態選單標題是來自windows的系統登錄檔,還是來自一個資料庫,或者是來自一個子目錄,主要由程式的功能而定。這裡假設主視窗名為mainform,上面已有主選單...

用Delphi製作DLL的方法

用delphi製作dll的方法 一 dll的製作一般步驟 二 引數傳遞 三 dll的初始化和退出清理 如果需要初始化和退出清理 四 全域性變數的使用 五 呼叫靜態載入 六 呼叫動態載入 七 在dll建立一個tform 八 在dll中建立一個 ichildform 九 示例 十 delphi製作的dl...

用Delphi製作DLL的方法

用delphi製作dll的方法 一 dll的製作一般步驟 二 引數傳遞 三 dll的初始化和退出清理 如果需要初始化和退出清理 四 全域性變數的使用 五 呼叫靜態載入 六 呼叫動態載入 七 在dll建立一個tform 八 在dll中建立一個 ichildform 九 示例 十 delphi製作的dl...

用delphi製作OCX庫檔案(二)

開發步驟 1 建立activex library工程。2 建立com object。3 建立type library,並建立相應介面。4 建立介面對應的函式和實現。具體如下 1 建立com object。new other activex com object 在class name 本例裡類名裡填...

用delphi製作新聞採集程式(二)

在前一篇文章裡,我們討論了新聞採集程式的原理。今天要來具體實現了。首先,程式將用到 控制元件 在 indy clients 面板 關於該控制元件的詳細文件,e文好的朋友可以登陸這裡檢視 本程式用到的 get方法在第 53頁。網上關於 indy 的幫助文件也整理了不少,可是我一直沒找到中文的。在本程式...