Aye bagi ini ah..
Skinning with Visual FoxPro 9
Ide ini terlintas ketika saya melihat VFP-Skin 3, hanya saja harus bayar.. Dan.. daripada bayar.. bagus saya rancang gambar dan scripting agar tampilannya tidak kalah dengan VFP-Skin 3. Jadi bagi yang bosan dengan tampilan program yang bentuknya kotak.. bisa coba script ini, dengan tampilan yang lebih 'sexy'
Fitur :
- Lengkap dengan tombol min, max, close yang bisa menyala bila mouse didekatkan
- Title bar yang bisa drag & drop
- Title bar yang bila diklik 2x bisa resize max dan kembali ke normal bila diulangi 2x klik
1. Desain 1 skin yang Anda sukai dan potonglah menjadi 9 bagian file BMP + 3 file BMP
dan 1 skin messagebox
Ps : Semua skin diwarnai background dengan warna kuning RGB(255,255,0)
File tersebut adalah :
a. kiriatas.bmp (115 x 103) = height x width
b. tengahatas.bmp (115 x 5)
c. kananatas.bmp (115 x 103)
- kamin.bmp (file bmp dengan gambar tombol minimize menyala yang ukurannya sama dengan kananatas.bmp)
- kamax.bmp (file bmp dengan gambar tombol maximize menyala yang ukurannya sama dengan kananatas.bmp)
- kaclose.bmp (file bmp dengan gambar tombol close menyala yang ukurannya sama dengan kananatas.bmp)
d. kiri.bmp (5 x 103)
e. tengah.bmp (5 x 5)
f. kanan.bmp (5 x 103)
g. kiribawah.bmp (
i. tengahbawah.bmp
j. kananbawah.bmp
k. msgbox.bmp
2. Buat New Class dengan Base On Form dan Tentukan nama file vcx nya
3. Setelah muncul Form, maka ditambahkan 9 object image dan ditentukan properties picture sesuai nama filenya seperti point a s/d j
4. 9 image tersebut disusun dengan rapi dan dicatat nilai properties top dan left nya
5. Setelah disusun rapi, masukkan 3 object command button yang diset style nya menjadi INVISIBLE dan diatur posisinya di gambar min, max, close
(cmdmin,cmdmax,cmdclose)
6. Masukkan lagi object shape dan label yang diset transparant dan dihilangkan bordernya dan diatur posisinya
7. Setelah selesai, tekan control-A, dan ubah top semua image menjadi 1000000 (biar tidak ketahuan boongnya :p)
8. Tambahkan lagi image baru untuk msgbox.bmp
9. Tambahkan 3 command button (cmd1, cmd2,cmd3)
10.Tambahkan label untuk tampilan isi, logo(kebetulan saya pakai label), dan title messagebox
11. Atur posisi agar kelihatan bagus
12. Form tersebut diset property showwindow = 2 (As Top Level)
13. Tambahkan method(M) dan properties(P) berikut ini :
gantisize(M)
hnormal(P) = 0
initlain(M)
iregular(M)
m_isi(P) = ""
m_jenis(P) = ""
mousedownx(P) =0
mousedowny(P) =0
msgform(P) =.f.
n_button(P) =1
nflags(P) = .f.
wnormal(P) = 0
14. Sebagai contoh dilampirkan Init method dari class myform
this.AutoCenter = .T.
this.BorderStyle= 0
this.Closable = .F.
this.ControlBox = .F.
this.TitleBar = 0
IF this.wnormal=0 AND this.hnormal=0
this.wnormal=this.Width
this.hnormal=this.Height
ELSE
this.wnormal=604
this.hnormal=329
ENDIF
this.BackColor = RGB(255,255,0)
IF DODEFAULT()
TRY
DECLARE INTEGER SetLayeredWindowAttributes IN win32api;
INTEGER HWND, INTEGER crKey, INTEGER bAlpha, INTEGER dwFlags
*These functions get and set a window's attributes
DECLARE INTEGER SetWindowLong IN user32.DLL ;
INTEGER hWnd, INTEGER nIndex, INTEGER dwNewLong
DECLARE INTEGER GetWindowLong IN user32.DLL ;
INTEGER hWnd, INTEGER nIndex
CATCH
MESSAGEBOX("Could not load the required libraries. Make sure you are running Windows 2000 or higher.")
ENDTRY
ENDIF
This.iregular(thisform.HWnd,thisform.BackColor,1)
this.initlain
15. Method Iregular
********************************************************************************
* To create a non-rectangular form, a transparent color needs to be set.
* Anything drawn using this color will be transparent, and any
* mouse clicks in these regions will pass through to the visible form.
*
* This technique only works in Windows 2000/XP but it is much more efficient
* than previous techniques of setting a bounding region for the form.
*
* This can be used to create non-rectangluar forms, to create hovering agents,
* or simply to confuse your coworkers <g>.
*
* Although this function makes a form transparent, the Form must be setup
* accept these changes. First, the ShowWindow property MUST BE set to
* 2 'As Top-Level Form'. Otherwise the window cannot be drawn layered.
* Second, if you want to turn off the window's frame, since it will not be
* drawn transparent, you can set the following properties:
* BorderStyle = 0
* Caption = ""
* Closable = .F.
* ControlBox = .F.
* TitleBar = 0
*
********************************************************************************
*-- Pass in the window handle (Thisform.HWIND) and the color to make transparent.
LPARAMETERS nHWND, nColor, nAction
*Constants for SetLayeredWindowAttributs
#DEFINE LWA_COLORKEY 1
#DEFINE LWA_ALPHA 2
*Constants for SetWindowLong and GetWindowLong
#DEFINE GWL_EXSTYLE -20
#DEFINE WS_EX_LAYERED 0x00080000
LOCAL lnFlags
*The form's window must be set to Layered, so that it is drawn
* in a separate layer.
do case
case nAction = 1 && Make Transparent
lnFlags = GetWindowLong(nHWND, GWL_EXSTYLE) &&Gets the existing flags from the window
thisform.nFlags = lnFlags
lnFlags = BITOR(lnFlags, WS_EX_LAYERED) &&Appends the Layered flag to the existing ones
SetWindowLong(nHWND, GWL_EXSTYLE, lnFlags) &&Sets the new flags to the window
SetLayeredWindowAttributes(nHWND, nColor, 0, LWA_COLORKEY)
case nAction = 2 && Make Opaque
SetWindowLong(nHWND, GWL_EXSTYLE, thisform.nFlags) &&Sets the original flags to the window
SetLayeredWindowAttributes(nHWND, nColor, 0, 0)
endcase
16. Method Gantisize
LOCAL nilx,nily
nilx=this.Width
nily=this.Height
this.AutoCenter=.t.
**Pengaturan Skin Form Yang Statis
*Image
this.plu.Left=8
this.plu.top=8
this.pl.Left=8
this.pl.top=110
this.pc.top=110
this.pc.left=123
this.plb.left=8
this.pu.Top=8
this.pu.left=123
this.pr.top=110
this.pru.Top=8
this.pb.left=123
this.pu.Stretch= 2
this.pl.Stretch= 2
this.pc.Stretch= 2
this.pr.Stretch= 2
this.pb.Stretch= 2
*Title Shape & Label
this.titleshape.Left=8
this.titleshape.Top=33
this.titlename.Left=78
this.titlename.Top=40
*Cmd Min, Max, Close
this.cmdmin.Top=36
this.cmdmax.Top=36
this.cmdclose.Top=36
**Pengaturan Skin Form yang Dinamis
this.pl.Height= nily - (110*2)
this.pr.Height = this.pl.Height
this.pu.Width = nilx -(123*2)
this.pb.Width = this.pu.Width
this.pr.Left=nilx-123
this.plb.Top=nily-110
this.prb.Top=this.plb.Top
this.prb.left=this.pr.Left
this.pb.Top=this.prb.top
this.pc.Height=this.pl.Height
this.pc.Width=this.pu.Width
*Tombol
this.pru.Left=nilx-123
this.cmdmin.left=this.pru.Left + 25
this.cmdmax.left=this.pru.Left + 48
this.cmdclose.left=this.pru.Left + 71
*TitleBar dan TitleName
this.titlename.Width=this.pu.Width-20
this.titleshape.Width=this.pr.left
17. Method Destroy
if this.msgform=.t.
CLEAR EVENTS
endif
18. Titleshape.dblclick
this.Parent.cmdmax.Click
19. Titleshape.mousedown
LPARAMETERS nButton, nShift, nXCoord, nYCoord
IF nButton = 1
this.parent.mousedownx = m.nXCoord
this.parent.mousedownY = m.nYCoord
ENDIF
20. Titleshape.mouseleave
LPARAMETERS nButton, nShift, nXCoord, nYCoord
this.parent.mousedownx = 0
this.parent.mousedownY = 0
21. Titleshape.mousemove
LPARAMETERS nButton, nShift, nXCoord, nYCoord
LOCAL lnDifferenceX, lnDifferenceY
IF nButton = 1 AND (this.parent.mousedownx != 0 OR this.parent.mousedowny != 0)
m.lnDifferenceX = m.nXCoord - this.parent.mousedownx
m.lnDifferenceY = m.nYCoord - this.parent.mousedowny
this.parent.Move(this.parent.LEFT + m.lnDifferenceX, this.parent.TOP + m.lnDifferenceY, this.parent.Width, this.parent.Height)
THIS.MouseDown(nButton, nShift, nXCoord - m.lnDifferenceX, nYCoord - m.lnDifferenceY)
ENDIF
22. Cmdmin.click
this.Parent.WindowState= 1
23. Cmdmin.mouseenter
this.parent.image3.picture="kamin.bmp" &&gambar tombol min menyala
23. Cmdmin.mouseleave
this.parent.image3.picture="kananatas.bmp" &&gambar tombol normal
24. Isi juga cmdmax, cmdclose, tapi dibedakan properties picturenya sesuai dengan jenis tombolnya
25. cmd1.click
nhasil=1
this.parent.release
26. Untuk cmd2, cmd3, diganti nhasil menjadi 2 dan 3
27. Buat suatu file prg
PROCEDURE runpesan()
LPARAMETERS jenis,tombol,isi
if pcount()=3
oForm=newOBJECT("phxform","d:\vfp9\plx\classes\phxclass.vcx")
PUBLIC nhasil
nhasil=0
WITH oForm
.addproperty("Caption","ALOHA")
.addproperty("msgform",.t.)
.addproperty("m_jenis",jenis)
.addproperty("n_button",tombol)
.addproperty("m_isi",isi)
.init()
.show(1)
ENDWITH
READ events
return(MESSAGEBOX(nhasil))
endif
ENDPROC