|
-
Jul 5th, 2010, 01:01 AM
#1
Thread Starter
Fanatic Member
Have one form shown behind another form? how?
I cant get one form to show up behind another one... How would i do this with code? I have them both as borderstyle = none... can i not have this?
-
Jul 5th, 2010, 01:26 AM
#2
Re: Have one form shown behind another form? how?
What are you talking about? What are you trying to accomplish?
Software I use and highly recommend: Opera, Miranda IM, Peerblock, Winamp, Unlocker Assistant, JoyToKey, Virtual CloneDrive, Secunia PSI, ExplorerXP, GOM Player, Real Alternative, Quicktime Alternative,Sumatra PDF, and non-freeware: Photoshop and VB6( ).
My codebank: AllRGB, Rounded Rectangle(math), Binary Server, Buddy Paint, LoadPictureGDI+, System GUID/Volume Serial, HexToAsc, List all processes and their paths, quasiString matching
Strings(search, extraction, retrieval etc): Retrieve BBCode Link from HTML, RemoveBetween ()'s, strFindBetween(str1,str2), Insert text in HTML, HTML - GetSpanByID
-
Jul 5th, 2010, 06:56 AM
#3
Frenzied Member
Re: Have one form shown behind another form? how?
It is easier to have one form appear in front of another form as normal drawing is from the back to the front... However, you could try the API with SetWindowPos and HWND_BOTTOMMOST const...
Good Luck
Option Explicit should not be an Option!
-
Jul 5th, 2010, 08:59 AM
#4
Re: Have one form shown behind another form? how?
As vb5prgrmr has said you can use the SetWindowPos API. Since you are subclassing in this example, make sure you close the form properly.
in a module
Code:
Option Explicit
Public Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" _
Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, ByVal x As Long, _
ByVal y As Long, ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As Long) As Long
Public Const GWL_WNDPROC = (-4)
Public Const WM_PAINT = &HF
Public Const WM_ACTIVATE = &H6
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const HWND_BOTTOM = 1
Public winProc As Long
Public Function WindowProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lFlags As Long
lFlags = SWP_NOSIZE Or SWP_NOMOVE
Select Case wMsg
Case WM_ACTIVATE
SetWindowPos hwnd, HWND_BOTTOM, 0, 0, 0, 0, lFlags
Case Else
WindowProc = CallWindowProc(winProc, hwnd, wMsg, wParam, lParam)
Exit Function
End Select
End Function
Public Sub SubClass(hwnd As Long)
On Error Resume Next
winProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnSubClass(hwnd As Long)
If winProc Then
SetWindowLong hwnd, GWL_WNDPROC, winProc
winProc = 0
End If
End Sub
and in your form
Code:
Option Explicit
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Load()
SubClass Me.hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubClass Me.hwnd
End Sub
-
Jul 5th, 2010, 10:25 AM
#5
Re: Have one form shown behind another form? how?
No subclassing required.
In a code module:
Code:
Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const GWL_EXSTYLE = (-20)
'Requires Windows 2000 or later:
Private Const WS_EX_LAYERED = &H80000
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Declare Function GetLayeredwindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Public Sub MakeWindowTransparent(ByVal hWnd As Long, ByVal alphaAmount As Byte)
Dim lStyle As Long
lStyle = GetWindowLong(hWnd, GWL_EXSTYLE)
lStyle = lStyle Or WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, lStyle
SetLayeredWindowAttributes hWnd, 0, alphaAmount, LWA_ALPHA
End Sub
In the transparent form:
Code:
Option Explicit
Private Sub Command1_Click()
frmOpaque.Move Me.Left + 100
frmOpaque.Show
End Sub
Private Sub Form_Load()
MakeWindowTransparent Me.hWnd, 100 'Can be 0 to 255
Me.Show
End Sub
-
Jul 5th, 2010, 10:40 AM
#6
Re: Have one form shown behind another form? how?
Game
I cant get one form to show up behind another one... How would i do this with code?
If you have 2 forms, and
Form2 is in front of Form1, then
will place Form2 at the back of the z-order.
Is that what you want to do?
Spoo
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|