Fixar User form na ...
 
Notifications
Clear all

Fixar User form na tela

4 Posts
1 Usuários
0 Reactions
1,899 Visualizações
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Amigos,

gostaria de saber se é possível fixar o User form em um local especifico da tela para que ele não se mova. Ou que não permita a sua movimentação.

Coloquei em anexo uma agende de contato que estou desenvolvendo. Porem nem todos os usuários da agenda terão habilidade para restabelecer a posição caso ele seja movimentado de lugar. É possível estabelecer uma localização fixa dentro do Workbook?

Antemão agradeço.

 
Postado : 03/07/2012 8:49 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Bom dia!!

Não olhei seu anexo, mas tente uma adaptação.

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _ 
ByVal lpClassName As String, _ 
ByVal lpWindowName As String) As Long 
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 Declare Function GetSystemMenu Lib "user32" ( _ 
ByVal hWnd As Long, _ 
ByVal bRevert As Long) As Long 
Private Declare Function DeleteMenu Lib "user32" ( _ 
ByVal hMenu As Long, _ 
ByVal nPosition As Long, _ 
ByVal wFlags As Long) As Long 
Private Declare Function ShowWindow Lib "user32" ( _ 
ByVal hWnd As Long, _ 
ByVal nCmdShow As Long) As Long 
Private Declare Function EnableWindow Lib "user32" ( _ 
ByVal hWnd As Long, _ 
ByVal fEnable As Long) As Long 
Private Declare Function DrawMenuBar Lib "user32" ( _ 
ByVal hWnd As Long) As Long 
Private Declare Function SetFocus Lib "user32" ( _ 
ByVal hWnd As Long) As Long 
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" ( _ 
ByVal hInst As Long, _ 
ByVal lpszExeFileName As String, _ 
ByVal nIconIndex As Long) As Long 
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _ 
ByVal hWnd As Long, _ 
ByVal wMsg As Long, _ 
ByVal wParam As Integer, _ 
ByVal lParam As Long) As Long 
Private Declare Function LockWindowUpdate Lib "user32" ( _ 
ByVal hWndLock As Long) As Long 
 
 'Window styles
Private Const GWL_STYLE As Long = (-16) 
Private Const GWL_EXSTYLE As Long = (-20) 
Private Const WS_CAPTION As Long = &HC00000 
Private Const WS_EX_APPWINDOW As Long = &H40000 
Private Const WS_EX_TOOLWINDOW As Long = &H80 
 
Private hWnd As Long 
 
Private Sub UserForm_Activate() 
    Dim lStyle As Long, hMenu As Long 
     
    hWnd = FindWindow("ThunderDFrame", Me.Caption) 
     
    If hWnd = 0 Then Exit Sub 
     
    lStyle = GetWindowLong(hWnd, GWL_STYLE) 
     
    lStyle = lStyle And Not WS_CAPTION 
    SetWindowLong hWnd, GWL_STYLE, lStyle 
    lStyle = GetWindowLong(hWnd, GWL_EXSTYLE) 
    lStyle = lStyle And Not WS_EX_APPWINDOW 
    lStyle = lStyle And Not WS_EX_TOOLWINDOW 
    SetWindowLong hWnd, GWL_EXSTYLE, lStyle 
    DrawMenuBar hWnd 
    SetFocus hWnd 
     
End Sub 

Ou....

'Written: MArch 03,1020
'Author:  Leith Ross
'Summary: Locks a UserForm so it can not be resized or moved.

Public Declare Function GetForegroundWindow Lib "user32.dll" () As Long

 Private Declare Function GetSystemMenu _
   Lib "user32.dll" _
    (ByVal hwnd As Long, _
     ByVal bRevert As Long) As Long
 
 Private Declare Function DrawMenuBar _
   Lib "user32.dll" _
     (ByVal hwnd As Long) As Long
    
 Private Declare Function DeleteMenu _
   Lib "user32.dll" _
     (ByVal hwnd As Long, _
      ByVal nPosition As Long, _
      ByVal uflags As Long) As Long

Sub LockForm()

  Dim hMenu As Long
  Dim hwnd As Long
  Dim RetVal As Long
  
  Const MF_BYCOMMAND As Long = &H0&
  Const SC_MOVE As Long = &HF010
  
    hwnd = GetForegroundWindow()
    hMenu = GetSystemMenu(hwnd, 0&)
    
    RetVal = DeleteMenu(hMenu, SC_MOVE, MF_BYCOMMAND)
    RetVal = DrawMenuBar(hwnd)

End Sub
Private Sub UserForm_Activate()
  Call LockForm
End Sub
 
Postado : 04/07/2012 6:05 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

:shock: :D Obrigado Amigo. Mais num sei nem onde usar os códigos.

Pode me ajudar?

Desculpa a minha falta de qualificação, mas não tenho todo esse conhecimento...

Um abraço!

 
Postado : 05/07/2012 6:05 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Boa noite!!

Veja se é isso.

Depois marque seu tópico como resolvido e click na mãozinha!!!

Veja como em:
viewtopic.php?f=7&t=3784

obs: Ação somente no formulário (Agenda Telefônica)
Att

 
Postado : 05/07/2012 6:21 pm