Discussione:
Come inserire riduci ad icona per una Form
(troppo vecchio per rispondere)
Thommino
2006-06-08 09:55:20 UTC
Permalink
Altra domanda spero non troppo idiota e nemmeno troppo complessa.
E' possibile inserire ad una interfaccia grafica di una Form oltre che alla
tradizionale X di chiusura anche un altro simbolo per ridurre ad icona
l'interfaccia?
Grazie
Due di Picche
2006-06-08 11:05:58 UTC
Permalink
Un giorno, inconsapevole delle conseguenze, "Thommino"
Post by Thommino
Altra domanda spero non troppo idiota e nemmeno troppo complessa.
E' possibile inserire ad una interfaccia grafica di una Form oltre che alla
tradizionale X di chiusura anche un altro simbolo per ridurre ad icona
l'interfaccia?
Cosa intendi? La form non dispone già del pulsante riduci ad icona?
In ogni caso da codice:

tuaform.windowstate=vbMinimized
--
IBM: Infernal Biggest Mistake
News 2000 [v 2.06] - http://www.akapulce.net/socket2000
Thommino
2006-06-08 12:13:29 UTC
Permalink
Post by Due di Picche
Un giorno, inconsapevole delle conseguenze, "Thommino"
[cut]
Post by Due di Picche
tuaform.windowstate=vbMinimized
No sto programmando in VBA e sto usando la "Casella degli strumenti" che mi
propone già installata Visual Basic Editor. Quando gli ho detto di crearmi
una Form, mi ha predisposto la finestra per inserirci i vari oggetti, e mi
ha solamente messo in alto a destra la X. Come aggiungo anche il tasto per
ridurre ad icona?

Dove va messo tuaform.windowstate=vbMinimized io non ho un codice che crea
la form (me la crea in automatico )in vista,ma solamente il codice che ho
creato io.
Thommino
2006-06-08 13:01:43 UTC
Permalink
"Thommino" <***@fastwebnet.it> ha scritto nel messaggio news:OvUhg.14121$***@tornado.fastwebnet.it...
[cut]
Post by Thommino
Dove va messo tuaform.windowstate=vbMinimized io non ho un codice che crea
la form (me la crea in automatico )in vista,ma solamente il codice che ho
creato io.
Ho provato con
Private Sub UserForm_Resize()
UserForm.WindowState = vbMinimized
End Sub

Ma non compare nulla di diverso!
Melchiade Bedrosian Baol
2006-06-08 13:03:36 UTC
Permalink
Post by Thommino
Ho provato con
Private Sub UserForm_Resize()
UserForm.WindowState = vbMinimized
End Sub
Ma non compare nulla di diverso!
Non vi state capendo :-)
--
Salutoni
Sergio

C'è il giorno in cui nasci e quello in cui scegli di vivere

questo articolo e` stato inviato via web dal servizio gratuito
http://www.newsland.it/news segnala gli abusi ad ***@newsland.it
Thommino
2006-06-08 13:28:24 UTC
Permalink
"Melchiade Bedrosian Baol" <***@cssoft2001.com> ha scritto nel
messaggio news:e69778$tre$***@news.newsland.it...
[cut]
Post by Melchiade Bedrosian Baol
Non vi state capendo :-)
Probabile sta di fatto che non ho capito come inserire il tasto in alto a
destra del riduci a icona.
Eventualmente se è possibile anche un tasto che _click mandi la finestra
risotta ad icona!
Melchiade Bedrosian Baol
2006-06-08 13:41:35 UTC
Permalink
Post by Thommino
Probabile sta di fatto che non ho capito come inserire il tasto in alto a
destra del riduci a icona.
Non saprei dirti... Nel tuo ambiente di sviluppo, hai la possibilità di
gestire il borderstyle della tua form?
Post by Thommino
Eventualmente se è possibile anche un tasto che _click mandi la finestra
risotta ad icona!
Se sai come mettere un tasto nella form, e come utilizzare il suo evento
click, basta che tu metta in quella routine di evento il codice che ti è
stato suggerito (che è il codice per "iconizzare" una form, non per fare
apparire il tastino di riduzione a icona)

Ma dopo, come faresti a ripristinarla?
--
Salutoni
Sergio

C'è il giorno in cui nasci e quello in cui scegli di vivere

questo articolo e` stato inviato via web dal servizio gratuito
http://www.newsland.it/news segnala gli abusi ad ***@newsland.it
Fabio
2006-06-08 13:57:11 UTC
Permalink
"Thommino" <***@fastwebnet.it> ha scritto nel messaggio
news:1CVhg.14288
Post by Thommino
Probabile sta di fatto che non ho capito come inserire il tasto in alto a
destra del riduci a icona.
Eventualmente se è possibile anche un tasto che _click mandi la finestra
risotta ad icona!
Non vorrei dire una boiata, ma mi pare che le form di VBA siano di tipo
toolbox, quindi senza possibilità di riduzione o massimizzazione.

Ciao
Thommino
2006-06-08 14:09:33 UTC
Permalink
Post by Fabio
news:1CVhg.14288
Probabile sta di fatto che non ho capito come inserire il [cut]
toolbox, quindi senza possibilità di riduzione o massimizzazione.
In altri Form (fatti da altri) ho trovato la possibilità di riduzione ad
icona. Credo che prima vada caricato il menu' di ingrandisci, Riduci a
icona,Esci e poi vada inserito se quel tasto è attivo oppure no. Ma non
riesco proprio a capire come fare.
Anche aggiungendo un tasto da un'altra parte del codice ricevo errore quando
gli passo la stringa indicatami!
Fabio
2006-06-08 14:14:51 UTC
Permalink
"Thommino" <***@fastwebnet.it> ha scritto nel messaggio
news:DcWhg.14387
Post by Thommino
In altri Form (fatti da altri) ho trovato la possibilità di riduzione ad
icona. Credo che prima vada caricato il menu' di ingrandisci, Riduci a
icona,Esci e poi vada inserito se quel tasto è attivo oppure no. Ma non
riesco proprio a capire come fare.
Anche aggiungendo un tasto da un'altra parte del codice ricevo errore
quando gli passo la stringa indicatami!
Dovresti provare a postare in un NG che parla di VBA o di Excel (se stai
usando Ecel).

Ciao
Alessandro Baraldi
2006-06-11 10:30:21 UTC
Permalink
Post by Fabio
news:1CVhg.14288
Post by Thommino
Probabile sta di fatto che non ho capito come inserire il tasto in alto a
destra del riduci a icona.
Eventualmente se è possibile anche un tasto che _click mandi la finestra
risotta ad icona!
Non vorrei dire una boiata, ma mi pare che le form di VBA siano di tipo
toolbox, quindi senza possibilità di riduzione o massimizzazione.
Ciao
Si possono minimizzare, ma sono sempre interne alla MDI ovviamente, il
problema
è che poi si rischia di non vederle....!
Personalmente non adotterei mai una soluzione simile in VBA.

@Alex
Due di Picche
2006-06-08 16:56:32 UTC
Permalink
Pestando alacremente sulla tastiera "Thommino"
Post by Thommino
Ho provato con
Private Sub UserForm_Resize()
UserForm.WindowState = vbMinimized
End Sub
Ma non compare nulla di diverso!
Lo dovresti mettere nell'evento click di un pulsante, come ti è stato
detto da altri. Però se parli di VBA non saprei dirti se ciò è
possibile.
--
Who Cares where Carmen Sandiego is?
News 2002 [v 2.07] / StopDialer / PopDuster - http://www.socket2000.com
Akapulce portal: http://www.akapulce.net
Seth1982
2006-06-09 09:12:03 UTC
Permalink
Ho provato velocemente a fare un form in VBA ma non esiste né
WindowState né le classiche proprietà MinButton, MaxButton...

Gli unici BorderStyle che ho visto sono None e Single.

Quindi, niente minimizzazione!

Ciao,
Seth1982
Thommino
2006-06-09 09:34:16 UTC
Permalink
"Seth1982" <***@gmail.com> ha scritto nel messaggio news:***@i40g2000cwc.googlegroups.com...
[cut]
<Quindi, niente minimizzazione!
<Ciao,
<Seth1982

Eppure questa Form permette anche la minimizzazione:

FORM:

'***************************************************************************
'*
'* MODULE NAME: SIZEABLE USERFORM
'* AUTHOR: STEPHEN BULLEN, Business Modelling Solutions Ltd.
'* TIM CLEM
'*
'* CONTACT: ***@BMSLtd.co.uk
'* WEB SITE: http://www.BMSLtd.co.uk
'*
'* DESCRIPTION: Makes a userform resizeable and reacts to the form being
resized
'*
'* THIS MODULE: Handles the userform's resizing
'*
'* PROCEDURES:
'* UserForm_Activate Instantiates a class module to make the form
sizeable
'* UserForm_Resize Sizes and positions the controls on the form when
resized
'* btnOK_Click Closes the form when the OK button is clicked
'*
'* Adapted to ArcMap from Excel by Kirk Kuykendall ***@ambergis.com
'* http://www.ambergis.com
'***************************************************************************

Option Explicit
Option Compare Text

'Declare a new instance of our form changer
Dim oFormChanger As New CFormChanger

Private Sub btnChangeIcon_Click()
Dim vFile As Variant

Dim pGetStringDialog As IGetStringDialog
Set pGetStringDialog = New GetStringDialog
If Not pGetStringDialog.DoModal("Enter a file that has icons
(.ico,.exe,.dll)", "File:", "", 0) Then
Debug.Print "canceled"
Exit Sub
Else
vFile = pGetStringDialog.Value
End If

If Dir(vFile) = "" Then
MsgBox "file not found: " & vFile
Exit Sub
End If

'vFile = Application.GetOpenFilename("Icon files
(*.ico;*.exe;*.dll),*.ico;*.exe;*.dll", 0, "Open Icon File", "Open", False)

'Showing dialog sets the form modeless, so check it
oFormChanger.Modal = cbModal

If vFile = False Then Exit Sub

oFormChanger.IconPath = vFile

End Sub

Private Sub UserForm_Activate()

'Initialise everything to show
cbModal.Value = True
cbCaption.Value = True
cbCloseBtn.Value = True
cbIcon.Value = True
cbMaximize.Value = True
cbMinimize.Value = True
cbSizeable.Value = True
cbSysmenu.Value = True
cbTaskBar.Value = False
cbSmallCaption.Value = False

'Set the form changer to change this userform
Set oFormChanger.Form = Me

'Make sure everything is in the right place to start with
UserForm_Resize

End Sub

Private Sub UserForm_Resize()

Dim dFrameCols As Double, dFrameRows As Double, dFrameHeight As Double
Dim i As Integer, j As Integer

'Standard control gap of 6pts
Const dGAP As Integer = 6

'Exit the sub if we've been minimized
If Me.InsideWidth = 0 Then Exit Sub

'Set controls that don't move/size
With lblMessage 'The position of the "Message" label
.Top = dGAP
.Left = dGAP
End With

With tbMessage 'The position of the message box (the size changes,
not the position)
.Top = dGAP + lblMessage.Height + dGAP
.Left = dGAP
End With

fraStyle.Left = dGAP

'Don't let the form get less than a certain height - must have at least
the message and button
If Me.InsideHeight < lblMessage.Height + btnOK.Height + fraStyle.Height
+ dGAP * 5 Then

'Reset the height, allowing for the form's border (Height -
InsideHeight)
Me.Height = lblMessage.Height + btnOK.Height + fraStyle.Height +
dGAP * 5 + Me.Height - Me.InsideHeight
End If

'Don't let the form get less than a certain width - must be as wide as
the biggest check box, plus the standard gap
If Me.InsideWidth < cbMaximize.Width + fraStyle.Width -
fraStyle.InsideWidth + dGAP * 4 Then

'Reset the width, allowing for the form's border (Width -
InsideWidth)
Me.Width = cbMaximize.Width + fraStyle.Width - fraStyle.InsideWidth
+ dGAP * 4
End If

'Work out the new dimensions of the frame (as the check boxes move
within the frame)
With fraStyle
If (Me.InsideWidth - dGAP * 3 - (.Width - .InsideWidth)) \
(cbMaximize.Width + dGAP) > 1 Then
dFrameCols = (Me.InsideWidth - dGAP * 3 - (.Width -
.InsideWidth)) \ (cbMaximize.Width + dGAP)
Else
dFrameCols = 1
End If
dFrameRows = .Controls.Count / dFrameCols

If dFrameRows <> Int(dFrameRows) Then dFrameRows = Int(dFrameRows) +
1
dFrameHeight = dFrameRows * cbMaximize.Height + dGAP + .Height -
.InsideHeight
End With

'Don't allow the form width to decrease so that there's no room for the
checkboxes
'i.e. decreasing the width causes the check boxes to require an extra
row, which doesn't fit.
If Me.InsideHeight <= btnOK.Height + lblMessage.Height + dFrameHeight +
dGAP * 5 Then

'Reset the width, allowing for the form's border (Width -
InsideWidth)
Me.Width = fraStyle.Width + dGAP * 2 + Me.Width - Me.InsideWidth

'Recalculate the frame's dimensions with the changed form's width
With fraStyle
If (Me.InsideWidth - dGAP * 3 - (.Width - .InsideWidth)) \
(cbMaximize.Width + dGAP) > 1 Then
dFrameCols = (Me.InsideWidth - dGAP * 3 - (.Width -
.InsideWidth)) \ (cbMaximize.Width + dGAP)
Else
dFrameCols = 1
End If
dFrameRows = .Controls.Count / dFrameCols

If dFrameRows <> Int(dFrameRows) Then dFrameRows =
Int(dFrameRows) + 1
dFrameHeight = dFrameRows * cbMaximize.Height + dGAP + .Height -
.InsideHeight
End With

End If

'Set the OK button to be in the middle at the bottom
With btnOK
.Left = (Me.InsideWidth - btnOK.Width) / 2
.Top = Me.InsideHeight - btnOK.Height - dGAP
End With

'Set the frame to be as wide as the box and move the check boxes in it
to fit
With fraStyle
.Width = Me.InsideWidth - dGAP * 2
.Height = dFrameHeight

'Reposition the controls in the frame, according to their tab order
For i = 0 To .Controls.Count - 1
For j = 0 To .Controls.Count - 1
With .Controls(j)
If .TabIndex = i Then
.Left = (i Mod dFrameCols) * (cbMaximize.Width +
dGAP) + dGAP
.Top = Int(i / dFrameCols) * cbMaximize.Height +
dGAP
End If
End With
Next
Next

.Top = btnOK.Top - dGAP - .Height
End With

'Userform is big enough, so set the message box's height and width to
fill it
With tbMessage
.Width = Me.InsideWidth - dGAP * 2

'Don't allow the height to go negative
If (fraStyle.Top - .Top - dGAP) > 0 Then
.Height = fraStyle.Top - .Top - dGAP
Else
.Height = 0
End If
End With

End Sub

Private Sub cbModal_Change()
oFormChanger.Modal = cbModal.Value
CheckEnabled
End Sub

Private Sub cbSizeable_Change()
oFormChanger.Sizeable = cbSizeable.Value

CheckBorderStyle
End Sub

Private Sub cbCaption_Change()
oFormChanger.ShowCaption = cbCaption.Value

CheckBorderStyle
CheckEnabled
End Sub

Private Sub cbSysmenu_Change()
oFormChanger.ShowSysMenu = cbSysmenu.Value
CheckEnabled
End Sub

Private Sub cbTaskBar_Change()
oFormChanger.ShowTaskBarIcon = cbTaskBar.Value
CheckEnabled
End Sub

Private Sub cbSmallCaption_Change()
oFormChanger.SmallCaption = cbSmallCaption.Value
CheckEnabled
End Sub

Private Sub cbIcon_Change()
oFormChanger.ShowIcon = cbIcon.Value
CheckEnabled
End Sub

Private Sub cbCloseBtn_Change()
oFormChanger.ShowCloseBtn = cbCloseBtn.Value
CheckEnabled
End Sub

Private Sub cbMaximize_Change()
oFormChanger.ShowMaximizeBtn = cbMaximize.Value
CheckEnabled
End Sub

Private Sub cbMinimize_Change()
oFormChanger.ShowMinimizeBtn = cbMinimize.Value
CheckEnabled
End Sub

Private Sub btnOK_Click()
Unload Me
End Sub

Private Sub CheckBorderStyle()

'If the useform is not sizeable and doesn't have a caption,
'Windows draws it without a border, and we need to apply our
'own 3D effect.
If Not (cbSizeable Or cbCaption) Then
Me.SpecialEffect = fmSpecialEffectRaised
Else
Me.SpecialEffect = fmSpecialEffectFlat
End If

End Sub

Private Sub CheckEnabled()

'Without a system menu, we can't have the close, max or min buttons
cbSysmenu.Enabled = cbCaption
cbCloseBtn.Enabled = cbSysmenu And cbCaption
cbIcon.Enabled = cbSysmenu And cbCaption And Not cbSmallCaption
cbMaximize.Enabled = cbSysmenu And cbCaption
cbMinimize.Enabled = cbSysmenu And cbCaption

btnChangeIcon.Enabled = cbIcon

End Sub


MODULO CLASSE:

Option Explicit

'Windows API calls to do all the dirty work!
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

'Lots of window styles for us to play with!
Private Const GWL_STYLE As Long = (-16) 'The offset of a window's
style
Private Const GWL_EXSTYLE As Long = (-20) 'The offset of a window's
extended style
Private Const WS_CAPTION As Long = &HC00000 'Style to add a titlebar
Private Const WS_SYSMENU As Long = &H80000 'Style to add a system
menu
Private Const WS_THICKFRAME As Long = &H40000 'Style to add a sizable
frame
Private Const WS_MINIMIZEBOX As Long = &H20000 'Style to add a Minimize
box on the title bar
Private Const WS_MAXIMIZEBOX As Long = &H10000 'Style to add a Maximize
box to the title bar
Private Const WS_POPUP As Long = &H80000000 'Standard option, cleared
when showing a task bar icon
Private Const WS_VISIBLE As Long = &H10000000 'Standard option, cleared
when showing a task bar icon

Private Const WS_EX_DLGMODALFRAME As Long = &H1 'Controls if the window
has an icon
Private Const WS_EX_APPWINDOW As Long = &H40000 'Application Window: shown
on taskbar
Private Const WS_EX_TOOLWINDOW As Long = &H80 'Tool Window: small
titlebar

'Constant to identify the Close menu item
Private Const SC_CLOSE As Long = &HF060

'Constants for hide or show a window
Private Const SW_HIDE As Long = 0
Private Const SW_SHOW As Long = 5

'Constants for Windows messages
Private Const WM_SETICON = &H80

'Variables to store the various selections/options
Dim hWndForm As Long, mbSizeable As Boolean, mbCaption As Boolean, mbIcon As
Boolean, miModal As Integer
Dim mbMaximize As Boolean, mbMinimize As Boolean, mbSysMenu As Boolean,
mbCloseBtn As Boolean
Dim mbAppWindow As Boolean, mbToolWindow As Boolean, msIconPath As String
Dim moForm As Object

Public Property Set Form(oForm As Object)

'Get the userform's window handle
' If Val(Application.Version) < 9 Then
' hWndForm = FindWindow("ThunderXFrame", oForm.Caption) 'XL97
' Else
hWndForm = FindWindow("ThunderDFrame", oForm.Caption) 'XL2000 (and
ArcMap too)
' End If

'Remember the form for later
Set moForm = oForm

'Set the form's style
SetFormStyle

'Update the form's icon
ChangeIcon

End Property

'Property procedure to get and set the form's window styles
Public Property Let Sizeable(bSizeable As Boolean)
mbSizeable = bSizeable
SetFormStyle
End Property

Public Property Get Sizeable() As Boolean
Sizeable = mbSizeable
End Property

Public Property Let ShowCaption(bCaption As Boolean)
mbCaption = bCaption
SetFormStyle
End Property

Public Property Get ShowCaption() As Boolean
ShowCaption = mbCaption
End Property

Public Property Let Modal(bModal As Boolean)
miModal = Abs(CInt(Not bModal))

'Make the form modal or modeless by enabling/disabling Excel itself
EnableWindow FindWindow("XLMAIN", Application.Caption), miModal
End Property

Public Property Get Modal() As Boolean
Modal = (miModal <> 1)
End Property

Public Property Let ShowIcon(bIcon As Boolean)
mbIcon = Not bIcon
ChangeIcon
SetFormStyle
End Property

Public Property Get ShowIcon() As Boolean
ShowIcon = (mbIcon <> 1)
End Property

Public Property Let IconPath(sNewPath As String)
msIconPath = sNewPath
ChangeIcon
End Property

Public Property Get IconPath() As String
IconPath = msIconPath
End Property

Public Property Let ShowMaximizeBtn(bMaximize As Boolean)
mbMaximize = bMaximize
SetFormStyle
End Property

Public Property Get ShowMaximizeBtn() As Boolean
ShowMaximizeBtn = mbMaximize
End Property

Public Property Let ShowMinimizeBtn(bMinimize As Boolean)
mbMinimize = bMinimize
SetFormStyle
End Property

Public Property Get ShowMinimizeBtn() As Boolean
ShowMinimizeBtn = mbMinimize
End Property

Public Property Let ShowSysMenu(bSysMenu As Boolean)
mbSysMenu = bSysMenu
SetFormStyle
End Property

Public Property Get ShowSysMenu() As Boolean
ShowSysMenu = mbSysMenu
End Property

Public Property Let ShowCloseBtn(bCloseBtn As Boolean)
mbCloseBtn = bCloseBtn
SetFormStyle
End Property

Public Property Get ShowCloseBtn() As Boolean
ShowCloseBtn = mbCloseBtn
End Property

Public Property Let ShowTaskBarIcon(bAppWindow As Boolean)

'If changing from showing an icon to not showing it, hide the window to
remove the icon
If hWndForm <> 0 And mbAppWindow And Not bAppWindow Then
'Enable the Excel window, so we don't lose focus
EnableWindow FindWindow("XLMAIN", Application.Caption), True
ShowWindow hWndForm, SW_HIDE
End If

mbAppWindow = bAppWindow

SetFormStyle

'Repaint the userform, to ensure everything is updated correctly
moForm.Repaint

'Set the Excel window's enablement to the correct choice
EnableWindow FindWindow("XLMAIN", Application.Caption), miModal
End Property

Public Property Get ShowTaskBarIcon() As Boolean
ShowTaskBarIcon = mbAppWindow
End Property

Public Property Let SmallCaption(bToolWindow As Boolean)
mbToolWindow = bToolWindow
SetFormStyle
End Property

Public Property Get SmallCaption() As Boolean
SmallCaption = mbToolWindow
End Property

'Routine to set the form's window style
Private Sub SetFormStyle()

Dim iStyle As Long, hMenu As Long, hID As Long, iItems As Integer

'Have we got a form to set?
If hWndForm = 0 Then Exit Sub

iStyle = GetWindowLong(hWndForm, GWL_STYLE)

'Build up the basic window style flags for the form
If mbCaption Then iStyle = iStyle Or WS_CAPTION Else iStyle = iStyle And
Not WS_CAPTION
If mbSysMenu Then iStyle = iStyle Or WS_SYSMENU Else iStyle = iStyle And
Not WS_SYSMENU
If mbSizeable Then iStyle = iStyle Or WS_THICKFRAME Else iStyle = iStyle
And Not WS_THICKFRAME
If mbMinimize Then iStyle = iStyle Or WS_MINIMIZEBOX Else iStyle =
iStyle And Not WS_MINIMIZEBOX
If mbMaximize Then iStyle = iStyle Or WS_MAXIMIZEBOX Else iStyle =
iStyle And Not WS_MAXIMIZEBOX
If mbAppWindow Then iStyle = iStyle And Not WS_VISIBLE And Not WS_POPUP
Else iStyle = iStyle Or WS_VISIBLE Or WS_POPUP

'Set the basic window styles
SetWindowLong hWndForm, GWL_STYLE, iStyle

iStyle = GetWindowLong(hWndForm, GWL_EXSTYLE)

'Build up and set the extended window style
If mbIcon Then iStyle = iStyle Or WS_EX_DLGMODALFRAME Else iStyle =
iStyle And Not WS_EX_DLGMODALFRAME
If mbAppWindow Then iStyle = iStyle Or WS_EX_APPWINDOW Else iStyle =
iStyle And Not WS_EX_APPWINDOW
If mbToolWindow Then iStyle = iStyle Or WS_EX_TOOLWINDOW Else iStyle =
iStyle And Not WS_EX_TOOLWINDOW

SetWindowLong hWndForm, GWL_EXSTYLE, iStyle

'Handle the close button differently
If mbCloseBtn Then
'We want it, so reset the control menu
hMenu = GetSystemMenu(hWndForm, 1)
Else
'We don't want it, so delete it from the control menu
hMenu = GetSystemMenu(hWndForm, 0)
DeleteMenu hMenu, SC_CLOSE, 0&
End If

'Show the window with the changes
ShowWindow hWndForm, SW_SHOW
DrawMenuBar hWndForm
SetFocus hWndForm

End Sub

Private Sub ChangeIcon()

Dim hIcon As Long

On Error Resume Next

If hWndForm <> 0 Then

Err.Clear
If msIconPath = "" Then
hIcon = 0
ElseIf Dir(msIconPath) = "" Then
hIcon = 0
ElseIf Err.Number <> 0 Then
hIcon = 0
ElseIf Not mbIcon Then
'Get the icon from the source
hIcon = ExtractIcon(0, msIconPath, 0)
Else
hIcon = 0
End If

'Set the big (32x32) and small (16x16) icons
SendMessage hWndForm, WM_SETICON, True, hIcon
SendMessage hWndForm, WM_SETICON, False, hIcon
End If

End Sub
Seth1982
2006-06-09 10:28:37 UTC
Permalink
Sì, infatti è stata creata una classe ad hoc per permettere
minimizzazione e resize dinamico.
L'autore della classe usa le API user32 e shell32 per modificare la
userform (se ho ben capito trova l'handle della form e gli applica
delle modifiche a runtime).

Quindi, la soluzione l'hai già trovata: ti basta inserire la classe
CFormChanger nel tuo progetto VBA, avendo cura di fare queste
dichiarazioni nel tuo UserForm:

Dim oFormChanger As New CFormChanger

e nell'evento UserForm_Activate metti:

Set oFormChanger.Form = Me

e poi sbizzarrisciti con le proprietà della classe.


Spero di esserti stato utile.


Ciao,
Seth1982
Thommino
2006-06-09 12:02:38 UTC
Permalink
[cut]

<Quindi, la soluzione l'hai già trovata: ti basta inserire la classe
<CFormChanger nel tuo progetto VBA,

Ok la ho inserita.

<avendo cura di fare queste
<dichiarazioni nel tuo UserForm:

<Dim oFormChanger As New CFormChanger


Questa dichiarazione dove va inserita?

<e nell'evento UserForm_Activate metti:

<Set oFormChanger.Form = Me

<e poi sbizzarrisciti con le proprietà della classe.

E poi per caricare il Bottone per minimizzare come faccio?
Seth1982
2006-06-09 12:36:25 UTC
Permalink
Post by Thommino
Questa dichiarazione dove va inserita?
E poi per caricare il Bottone per minimizzare come faccio?
Copia quanto segue nel codice del tuo form, otterrai una form con
icona, caption, minimizza, massimizza e chiudi, ridimensionabile.
Per sapere quali sono le proprietà e i metodi della classe
CFormChanger basta che ne scorri il codice.
-------------------------------------------------------------------------------------------------------------
Option Explicit
Option Compare Text

'Dichiara una nuova istanza di CFormChanger
Dim oFormChanger As New CFormChanger

Private Sub UserForm_Activate()

Set oFormChanger.Form = Me
UserForm_Resize

End Sub

Private Sub UserForm_Resize()
oFormChanger.ShowCaption = True
oFormChanger.ShowSysMenu = True
oFormChanger.ShowCloseBtn = True
oFormChanger.ShowIcon = True
oFormChanger.ShowMaximizeBtn = True
oFormChanger.ShowMinimizeBtn = True
oFormChanger.Sizeable = True
End Sub
-------------------------------------------------------------------------------------------------------------

Ciao,
Seth1982.
Thommino
2006-06-09 12:38:41 UTC
Permalink
Post by Thommino
Questa dichiarazione dove va inserita?
E poi per caricare il Bottone per minimizzare come faccio?
Copia quanto segue nel codice del tuo form, otterrai una form con
icona, caption, minimizza, massimizza e chiudi, ridimensionabile.
Per sapere quali sono le proprietà e i metodi della classe
CFormChanger basta che ne scorri il codice.
-------------------------------------------------------------------------------------------------------------
Option Explicit
Option Compare Text

Questa parte del codice va scritta all'inizio inizio vero?
Perche se la inserisco lì poi nel proseguio del codice mi da errore sulle
variabili vbChecked
Sai per caso perchè?
Seth1982
2006-06-09 13:02:44 UTC
Permalink
Post by Thommino
Option Explicit
Option Compare Text
Questa parte del codice va scritta all'inizio inizio vero?
Perche se la inserisco lì poi nel proseguio del codice mi da errore sulle
variabili vbChecked
Le Option si mettono sempre all'inizio del modulo o della form.


Ciao,
Seth1982
Thommino
2006-06-09 13:23:30 UTC
Permalink
Post by Thommino
Option Explicit
Option Compare Text
Questa parte del codice va scritta all'inizio inizio vero?
Perche se la inserisco lì poi nel proseguio del codice mi da errore sulle
variabili vbChecked
Le Option si mettono sempre all'inizio del modulo o della form.


Se le metto lì poi mi dice variabile non dichiarata quando uso la vbChecked!
Se invece tolgo la scritta
Option Explicit
Option Compare Text
Non ricevo errori ma non compare nulla
Seth1982
2006-06-09 13:35:44 UTC
Permalink
Post by Thommino
Se le metto lì poi mi dice variabile non dichiarata quando uso la vbChecked!
Probabilmente c'è qualcosa nel tuo codice che non gli piace.
Posteresti tutto il codice del tuo form (oltre a quello che ti ho dato
io?)
Così gli dò un occhio.

In ogni caso, se tu crei una UserForm con dentro SOLO (fai clic col
tastro destro sul form, scegli visualizza codice, cancelli tutto e copi
solo il codice seguente):

-------------------------------------------------------------------------------------------------------------
Option Explicit
Option Compare Text

'Dichiara una nuova istanza di CFormChanger
Dim oFormChanger As New CFormChanger

Private Sub UserForm_Activate()

Set oFormChanger.Form = Me
UserForm_Resize

End Sub

Private Sub UserForm_Resize()
oFormChanger.ShowCaption = True
oFormChanger.ShowSysMenu = True
oFormChanger.ShowCloseBtn = True
oFormChanger.ShowIcon = True
oFormChanger.ShowMaximizeBtn = True
oFormChanger.ShowMinimizeBtn = True
oFormChanger.Sizeable = True
End Sub
-------------------------------------------------------------------------------------------------------------


Dovresti vedere quello che ti ho detto.

Fammi sapere.

Ciao,
Seth1982
Thommino
2006-06-09 13:50:14 UTC
Permalink
Post by Thommino
Se le metto lì poi mi dice variabile non dichiarata quando uso la vbChecked!
[cut]
Dovresti vedere quello che ti ho detto.

In effetti è vero se faccio un Form soltanto con quello che mi hai scritto
funziona.
Secondo me il problema nasce da:
Option Explicit
Option Compare Text
che considera errore tutte le variabili che non sono state dichiarate.
vbChecked è una di default e quindi non è definita
Seth1982
2006-06-09 14:18:03 UTC
Permalink
Post by Thommino
Option Explicit
Option Compare Text
che considera errore tutte le variabili che non sono state dichiarate.
vbChecked è una di default e quindi non è definita
Sicuramente la colpa è di Option Explicit
Prova ad usare 1 al posto di vbChecked e 0 al posto di vbUnchecked.

Fammi sapere se va.

Ciao,
Seth1982
Thommino
2006-06-09 15:11:43 UTC
Permalink
"Seth1982" <***@gmail.com> ha scritto nel messaggio news:***@g10g2000cwb.googlegroups.com...
[cut]
Sicuramente la colpa è di Option Explicit
Prova ad usare 1 al posto di vbChecked e 0 al posto di vbUnchecked.

Ok sostituito. Ho messo:

Option Explicit
Option Compare Text
Dim oFormChanger As New CFormChanger
Private Type Struttura
nome As String
valore As Single
End Type
Dim ordinato() As Struttura
Private Sub ComboBox1_C()
....
Private Sub UserForm_Active()
Set oFormChanger.Form = Me
UserForm_Resize
End Sub
Private Sub UserForm_Resize()
oFormChanger.ShowCaption = True
oFormChanger.ShowSysMenu = True
oFormChanger.ShowCloseBtn = True
oFormChanger.ShowIcon = True
oFormChanger.ShowMaximizeBtn = True
oFormChanger.ShowMinimizeBtn = True
oFormChanger.Sizeable = True
End Sub

Purtroppo pero' anche se non ricevo più errori di compilazione, non mi
carica per nulla le icone per la riduzione :-(
Seth1982
2006-06-09 15:15:46 UTC
Permalink
Post by Thommino
Purtroppo pero' anche se non ricevo più errori di compilazione, non mi
carica per nulla le icone per la riduzione :-(
A questo punto io mi arrendo... non so più che pesci pigliare.

Ciao,
Seth1982
Thommino
2006-06-09 15:45:25 UTC
Permalink
Post by Thommino
Purtroppo pero' anche se non ricevo più errori di compilazione, non mi
carica per nulla le icone per la riduzione :-(
A questo punto io mi arrendo... non so più che pesci pigliare.
Peccato pero'.
Grazie lo stesso.
Fabio
2006-06-10 07:24:19 UTC
Permalink
Post by Seth1982
Post by Thommino
Purtroppo pero' anche se non ricevo più errori di compilazione, non mi
carica per nulla le icone per la riduzione :-(
A questo punto io mi arrendo... non so più che pesci pigliare.
Io mi sarei arreso alle considerazioni sull'option explicit.

Prima di fare esperimenti strampalati occorrerebbe perlomeno conoscere l'ABC
di VB.

Ciao
Thommino
2006-06-10 11:53:31 UTC
Permalink
Post by Fabio
Prima di fare esperimenti strampalati occorrerebbe perlomeno conoscere
l'ABC di VB.
Beh se conosci tu una soluzione, più facile e semplice, siamo qui per
ascoltarti!
Fabio
2006-06-10 12:17:20 UTC
Permalink
"Thommino" <***@fastwebnet.it> ha scritto nel messaggio
news:6pyig.1972
Post by Thommino
Beh se conosci tu una soluzione, più facile e semplice, siamo qui per
ascoltarti!
1) se VBA non mette a disposizione questa possibilità o non è lo strumento
adatto ai tuoi scopi o accetti i suoi limiti.

2) Chi deve mettere in pratica una soluzione deve essere in grado di fare 2
prove in croce per conto suo, altrimenti è solo una perdita di tempo.

Non basta fare il copia-incolla delle soluzioni: bisogna anche capirle per
farle funzionare.

Ciao
Thommino
2006-06-10 14:18:40 UTC
Permalink
Post by Fabio
news:6pyig.1972
Post by Thommino
Beh se conosci tu una soluzione, più facile e semplice, siamo qui per
ascoltarti!
1) se VBA non mette a disposizione questa possibilità o non è lo strumento
adatto ai tuoi scopi o accetti i suoi limiti.
Lavorando dentro ArcView 9.x non ho possibilità di utilizzare altro. Devi
usare per forza VBA
Post by Fabio
2) Chi deve mettere in pratica una soluzione deve essere in grado di fare
2 prove in croce per conto suo, altrimenti è solo una perdita di tempo.
Io trovo che la collaborazione sia fondamentale.
Post by Fabio
Non basta fare il copia-incolla delle soluzioni: bisogna anche capirle per
farle funzionare.
Ciao
Tutto aiuta!
Grazie lo stesso.
Seth1982
2006-06-12 08:21:18 UTC
Permalink
Post by Fabio
Io mi sarei arreso alle considerazioni sull'option explicit.
Prima di fare esperimenti strampalati occorrerebbe perlomeno conoscere l'ABC
di VB.
Che io sappia i newsgroup hanno lo scopo di aiutare le persone a
trovare le soluzioni, anche se non sono proprio ferrate in materia.
Se la politica dei newsgroup, invece, è quella di sparare a zero sugli
errori o sui tentativi di conoscenza altrui, beh, evidentemente c'è
qualcosa che non funziona!
Nessuno nasce "imparato"... se i "saputelli" continuano a ridicolizzare
chi ne sa meno di loro, anziché aiutare a capire, tanto vale che certe
persone non si intromettano nemmeno nelle discussioni.

Bye,
Seth1982
Fabio
2006-06-12 15:17:27 UTC
Permalink
Post by Seth1982
Nessuno nasce "imparato"... se i "saputelli" continuano a ridicolizzare
chi ne sa meno di loro, anziché aiutare a capire, tanto vale che certe
persone non si intromettano nemmeno nelle discussioni.
E tu alora cosa ti sei intromesso a fare, il solito flame?
Non mi sono mai tirato indietro nel trovare soluzioni per il NG (sono uno
dei membri più attivi dal 97 in questo), ma ci devono essere le basi su cui
lavorare.

Se mi si dice "io l'option explicit non lo metto perchè sennò ho un mucchio
d'errori" io ti dico, beh, allora arrangiati, è inutile suggerire soluzioni
estrose e complesse per problemi marginali a chi non ha le basi per metterle
in pratica.

Tutto il resto su chi dovrebbe o non dovrebbe rispondere al lasciano il
tempo che trovano.
Il NG è pubblico e se uno non rompe le scatole o non inulta ha tutto il
diritto di rispondere come e a chi crede.

Ciao
Thommino
2006-06-12 10:18:48 UTC
Permalink
Post by Thommino
Purtroppo pero' anche se non ricevo più errori di compilazione, non mi
carica per nulla le icone per la riduzione :-(
A questo punto io mi arrendo... non so più che pesci pigliare.

Forse ho capito dove sta il problema.
Come mi hai detto tu ho inserito:

Option Explicit
Option Compare Text
'Dichiara una nuova istanza di CFormChanger
Dim oFormChanger As New CFormChanger
...
Private Sub UserForm_Activate()
Set oFormChanger.Form = Me
UserForm_Resize
End Sub
Private Sub UserForm_Resize()
oFormChanger.ShowCaption = True
oFormChanger.ShowSysMenu = True
oFormChanger.ShowCloseBtn = True
oFormChanger.ShowMinimizeBtn = True
End Sub

Mi sono accorto che se clicco su Run, dopo aver fatto doppio click sulla
Form i bottoni vengono visualizzati correttamente.

Io pero' per comodità per far partire la macro ho aggiunto alla Toolbar un
bottone (con la sua icona) che la va chiamare. A questo punto se faccio
partire quella macro dal pulsanti il tasto riduzione non c'è più. Secondo te
come posso fare per farlo visualizzare anche fancendo partire la macro da
pulsante?
Ti elenco il codice del pulsante che ho aggiunto alla toolbar

Public Sub Pulsante_Click()

Dim StudioAmbientaleForm As New StudioAmbForm
StudioAmbientaleForm.Show (False)

End Sub
Thommino
2006-06-12 10:22:58 UTC
Permalink
[cut]> Forse ho capito dove sta il problema.
Post by Thommino
Option Explicit
Option Compare Text
[cut]

Contrordine. Adesso improvvisamente si è messo a funzionare correttamente
anche cliccando, quel pulsante che vi dicevo. Meglio, così. Tutto risolto e
come sempre un grazie a tutti!
Alexandro
2006-06-12 16:03:52 UTC
Permalink
Thommino ha scritto:

<cut>
<cut>
Post by Thommino
'Exit the sub if we've been minimized
If Me.InsideWidth = 0 Then Exit Sub
<cut>


Non sono pratico di VBA specialmente usato in excel, ma per logica
guardando il codice che dici funzionare, suppongo che, nel guardando il
pezzettino riportato e il relativo commento, se la sub termina alla
minimizzazione la condizione di controllo da esaminare è

Me.InsideWidth = 0

Prova a vedere se InsideWidth è una proprietà read only o meno, e nel
caso non lo sia.... voila... imposti Me.InsideWidth = 0 e il form
dovrebbe iconizzarsi.

Alex

Continua a leggere su narkive:
Loading...