Newsgroup: it.comp.lang.visual-basic
Titolo: Form sempre in primo piano

Sapete come si fa a fare una Form che rimanga sempre
in primo piano, ma che non sia a scelta obbligatoria.
Ad esempio come quella del Task Manager.
Grazie Ciao
Simone

 in primo piano, ma che non sia a scelta obbligatoria.
Copiata da ........(non ricordo )
'Modale
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal
nCmdShow As Long) As Long
Public Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As
Long
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOW = 5
Public Declare Function SetWindowWord Lib "user32" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal wNewWord As Long) As Long
Public Const SWW_HPARENT = -8
'Modale
Public Sub SetFloating(HwndChild As Long, HwndParent As Long)
    'IMPORTANTE - Richiamare SetNoFloating prima della chiusura della form
    Call SetWindowWord(HwndChild, SWW_HPARENT, HwndParent)
End Sub
'Modale
Public Sub SetNoFloating(hwnd As Long)
    Call SetWindowWord(hwnd, SWW_HPARENT, 0&)
End Sub
'questo l'ho aggiunto io per poterla chiamare da qualsiasi parte
Public Sub formModale(fChild As Form, fParent As Form)
    ShowWindow fChild.hwnd, SW_HIDE
    SetNoFloating fChild.hwnd   'Non indispensabile, Cmq non gli fa male
 
    ShowWindow fChild.hwnd, SW_SHOWNORMAL
    SetFloating fChild.hwnd, fParent.hwnd
 
End Sub
'Situazione:
'Aperta MDI
'Aperta form1.MDIChild=true
'da form1.MDIChild=true apro form2
Private Sub Command1_Click()
    formModale Form2, MDIForm1
End Sub
giuseppeD
-- 
questo articolo e` stato inviato via web dal servizio gratuito 
http://www.newsland.it/news
 segnala gli abusi ad 
ab...@newsland.it

 Ad esempio come quella del Task Manager.
In un modulo:
-------------
Option Explicit
Private 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 Sub AlwaysOnTop(ByRef mvarForm As Object, Optional ByRef
mvarOnTop As Boolean = True)
    'Dimention local variables
    Dim mvarHandle As Long
    Dim mvarFlags As Long
    Dim mvarPosFlag As Long
    'Set local constants
    Const mconSwp_Nosize = &H1
    Const mconSwp_Nomove = &H2
    Const mconSwp_NoActivate = &H10
    Const mconSwp_ShowWindow = &H40
    Const mconHwnd_TopMost = -1
    Const mconHwnd_NoTopMost = -2
    'Assign values to local variable
    mvarHandle = mvarForm.hwnd
    mvarFlags = mconSwp_Nomove Or mconSwp_Nosize Or _
                mconSwp_ShowWindow Or mconSwp_NoActivate
    'Set selected state
    Select Case mvarOnTop
      Case True
        mvarPosFlag = mconHwnd_TopMost
      Case False
        mvarPosFlag = mconHwnd_NoTopMost
    End Select
    'Execute declared function
    SetWindowPos mvarHandle, mvarPosFlag, 0, 0, 0, 0, mvarFlags
End Sub
-------------
Nel metodo/evento che ti interessa del form:
-----
AlwaysOnTop Me, True
-----
oppure
-----
AlwaysOnTop Me, False
-----
Happy Coding =)
Lokar
--
Sito Comune: 
http://www.it-lang-vb.net/
Manifesto: 
http://www.it-lang-vb.net/docs/Manifesto.txt

 in primo piano, ma che non sia a scelta obbligatoria.
in un modulo bas metti queste dichiarazioni:
==========================
Public Const SWP_NOMOVE = 2
Public Const SWP_NOSIZE = 1
Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Declare Function SetWindowPos Lib "User32" _
(ByVal h&, ByVal hb&, ByVal x&, ByVal y&, ByVal cx&, ByVal cy&, ByVal f&) As
Long
===========================
nel form userai:
  ' per farlo restare sempre in primo piano
  success% = SetWindowPos(Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
  ' per farlo tornare normale
  success% = SetWindowPos(Me.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)

Grazie a tutti!