Dosya açıldığında otomatik olarak "Maximize" olan userfom ?

Katılım
15 Haziran 2006
Mesajlar
3,704
Excel Vers. ve Dili
Excel 2003, 2007, 2010 (TR)
Selamlar

xls dosya açıldığı anda userformu otomatik olarak nasıl maximize edebilirim. Forumdaki birçok örnekte; userformun height ve width özellikleri, application'ın height ve width değerine eşitlenerek userform'un ebatı büyütülmüş. Ama maximized olmamış. API'lerle eklenen Maximize/Minimize butonları ile de ilk form açılışında bu sağlanamamış.

Application.windowstate=xlmaximized gibi bir kodun, userform için de geçerli olanı varmıdır acaba?
 
Katılım
21 Ağustos 2004
Mesajlar
12
Excel Vers. ve Dili
Xl2000, 2003, 2007
Lütfen,bu uğraş .

Kod:
Option Explicit

Private Declare Function ShowWindow _
    Lib "user32" ( _
        ByVal hwnd As Long, _
        ByVal nCmdShow As Long) _
As Long
'//
Private Declare Function SendMessage _
    Lib "user32" _
    Alias "SendMessageA" ( _
    ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) _
As Long

'// Not needed for this ... but if you wanted to
'// you could extract your own.
Private Declare Function ExtractIcon _
    Lib "shell32.dll" _
    Alias "ExtractIconA" ( _
    ByVal hInst As Long, _
    ByVal lpszExeFileName As String, _
    ByVal nIconIndex As Long) _
As Long

'// Define the API's for menu's
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 SetFocus Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function DrawMenuBar _
    Lib "user32" ( _
        ByVal hwnd As Long) _
As Long

Private Declare Function FindWindowA _
    Lib "user32" ( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String) _
As Long

'// Icon constants
Private Const WM_SETICON = &H80
Private Const ICON_SMALL = 0&
Private Const ICON_BIG = 1&


Private Const GWL_EXSTYLE = (-20)              '// Extended Styles
Private Const GWL_STYLE As Long = (-16)        '// Sets a new window style

'// General Windows Styles Bits
Private Const WS_EX_APPWINDOW = &H40000        '// Sets Min Form to task bar
Private Const WS_SYSMENU As Long = &H80000     '// WinStyle Sys Menu
Private Const WS_MINIMIZEBOX As Long = &H20000 '// WinStyle_MaxButton
Private Const WS_MAXIMIZEBOX As Long = &H10000 '// WinStyle_MinButton
Private Const WS_POPUP As Long = &H80000000

Private Const SW_MAXIMIZE As Long = 3

Dim lFrmWndHdl As Long
Dim lStyle As Long
Dim hIcon As Long
Dim blnWinTbar As Boolean

Private Sub UserForm_Activate()
'// ==============================================//
'//  Adds Min/Max to Userform Window              //
'//  Modifications & comments by Ivan F Moala     //
'//  22/07/01                                     //
'//  Amended 9th May 2002 idea from Mark O'Brian  //
'//  FindwindowA use VBnull instead of ClassName  //
'//  negates having to get the class name!        //
'//                                               //
'//  06/09/2003: NB: Set Form to [Modal False]    //
'//  To fix this Tmp done                         //
'//  Really need to use the                       //
'//  WS_POPUP                                     //
'//  Hex 80000000                                 //
'// ==============================================//

''// We need this as it does not work with it set
'blnWinTbar = Application.ShowWindowsInTaskbar
'Application.ShowWindowsInTaskbar = False

lFrmWndHdl = FindWindowA(vbNullString, Me.Caption)

'// The GetWindowLong function retrieves information about the window.
'// The function also retrieves the 32-bit (long) value
'// into the extra window memory of a window.
lStyle = GetWindowLong(lFrmWndHdl, GWL_STYLE)

'// lStyle is the New window style so lets set it up with the following
lStyle = lStyle Or WS_SYSMENU                   '// SystemMenu
'lStyle = lStyle Or WS_MINIMIZEBOX               '// With MinimizeBox
'lStyle = lStyle Or WS_POPUP Or WS_MAXIMIZEBOX   '// and MaximizeBox

'// Now lets set up our New window the SetWindowLong function changes
'// the attributes of the specified window , given as lFrmWndHdl,
'// GWL_STYLE = New windows style, and our Newly defined style = lStyle
SetWindowLong lFrmWndHdl, GWL_STYLE, (lStyle)

lStyle = GetWindowLong(lFrmWndHdl, GWL_EXSTYLE)
lStyle = lStyle Or WS_EX_APPWINDOW

'// Set the extended window style
SetWindowLong lFrmWndHdl, GWL_EXSTYLE, lStyle
    

'// Set Icon to Userform Window
'hIcon = Image1.Picture.Handle
'Call SendMessage(lFrmWndHdl, WM_SETICON, ICON_SMALL, ByVal hIcon)
'Call SendMessage(lFrmWndHdl, WM_SETICON, ICON_BIG, ByVal hIcon)

'// The DrawMenuBar function redraws the menu bar of the specified window.
'// We need this as we have changed the menu bar after Windows has created it.
'// All we need is the Handle, so thats simply enougth
'DrawMenuBar lFrmWndHdl

'// Maximize UF
ShowWindow lFrmWndHdl, 3
'// Need to set this to make the Form Take
'AppActivate ("Microsoft excel")
'SetFocus lFrmWndHdl

End Sub
 
Katılım
15 Haziran 2006
Mesajlar
3,704
Excel Vers. ve Dili
Excel 2003, 2007, 2010 (TR)
Thanks. I will try your codes. Can you speak or understand Turkish? If you can, this is wonderful.

Are you Ivan F Moala really?
 
Katılım
15 Haziran 2006
Mesajlar
3,704
Excel Vers. ve Dili
Excel 2003, 2007, 2010 (TR)
I have no doubt that you're Ivan F Moala. Your codes are working marvellous. Thanks again. Take care

Arkadaşlar, Sayın Moala'nın verdiği kodlarla problemi çözdüm. Ancak aşağıdaki satırların başındaki ' işaretlerini kaldırırsanız, max, min butonlarını da form üzerinde görebilirsiniz.

' lStyle = lStyle Or WS_MINIMIZEBOX '// With MinimizeBox
' lStyle = lStyle Or WS_POPUP Or WS_MAXIMIZEBOX '// and MaximizeBox

İyi çalışmalar
 
Katılım
21 Ağustos 2004
Mesajlar
12
Excel Vers. ve Dili
Xl2000, 2003, 2007
Thanks. I will try your codes. Can you speak or understand Turkish? If you can, this is wonderful.

Are you Ivan F Moala really?
ÜZGÜN, BEN DEĞİL KONUŞTÜRKÇE. . . VE
EVET ,O BENİM İSMİMDİR

Sorry, I cannot speak Turkish ...

And, Yes, that is my name :)
 

Hüseyin

Administrator
Yönetici
Admin
Katılım
2 Haziran 2004
Mesajlar
3,541
Excel Vers. ve Dili
Excel 2010 - Türkçe
Dear Ivan,
thank you for your participation.

There are more english post on this topic then turkish ones, so i'm moving it to the "Questions in English" forum.:)
 
Üst