begin process at 2010 09 03 06:17:33
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Trucs & Astuces

 > ACCESS : CACHER LA FENÊTRE PRINCIPALE DE L'APPLICATION

ACCESS : CACHER LA FENÊTRE PRINCIPALE DE L'APPLICATION


 Information sur la source

Note :
8 / 10 - par 3 personnes
8,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Trucs & Astuces Niveau :Débutant Date de création :28/11/2003 Date de mise à jour :05/12/2003 09:31:03 Vu / téléchargé :11 322 / 766

Auteur : ClickPouf

Ecrire un message privé
Commentaire sur cette source (6)
Ajouter un commentaire et/ou une note

 Description

Comment cacher la fenêtre principale d'Access ???
J'ai trouvé une solution par hasard...
C'est une bidouille, c'est pas beau, ça utilise certainement une erreur de chez microsoft... mais ça marche !

Déclarer les API suivantes dans un module (ApiWindows)
Ecrire les deux fonctions HideApplicationForm et ShowApplicationForm (dans un autre module par ex).

Appeler HideApplicationForm dans l'Open du formulaire de démarrage.
Appeler ShowApplicationForm à partir d'un bouton ou d'un code touche pour faire réapparaître la fenêtre principale (sinon plus d'accès aux menus Access).

Source

  • '********************************************************************************************
  • '* ApiWindows : Déclaration des API Windows *
  • '********************************************************************************************
  • Option Compare Database
  • Option Explicit
  • ' GetDesktopWindow : Donne le pointeur de la fenêtre du bureau
  • Public Declare Function GetDesktopWindow Lib "user32" ( _
  • ) As Long
  • ' GetParent : Donne le pointeur de la fenêtre parent
  • Public Declare Function GetParent Lib "user32" _
  • (ByVal hwnd As Long _
  • ) As Long
  • ' GetWindow : Donne le pointeur d'une fenêtre
  • Public Declare Function GetWindow Lib "user32" _
  • (ByVal hwnd As Long _
  • , ByVal wCmd As Long _
  • ) As Long
  • Public Const GW_HWNDFIRST = 0 ' Pointeur de la première fenêtre
  • Public Const GW_HWNDNext = 2 ' Pointeur de la fenêtre suivante
  • ' GetWindowRect : Donne le rectangle d'affichage de la fenêtre
  • Public Declare Function GetWindowRect Lib "user32" _
  • (ByVal hwnd As Long _
  • , lpRect As RECT _
  • ) As Long
  • Public Type RECT ' Rectangle d'affichage de la fenêtre
  • left As Long
  • top As Long
  • right As Long
  • bottom As Long
  • End Type
  • ' MoveWindow : Positionne et dimensionne la fenêtre
  • Public Declare Function MoveWindow Lib "user32" _
  • (ByVal hwnd As Long _
  • , ByVal x As Long _
  • , ByVal y As Long _
  • , ByVal nWidth As Long _
  • , ByVal nHeight As Long _
  • , ByVal bRepaint As Long _
  • ) As Long
  • ' ShowWindow : Défini le mode d'affichage de la fenêtre
  • Public Declare Function ShowWindow Lib "user32" _
  • (ByVal hwnd As Long _
  • , ByVal nCmdShow As Long _
  • ) As Long
  • '********************************************************************************************
  • '* CommonFunctions : Fonctions communes du projet *
  • '********************************************************************************************
  • Option Compare Database
  • Option Explicit
  • '===== HideApplicationForm : Cacher la fenêtre application ==================================
  • Function HideApplicationForm(FormId As Form)
  • On Error GoTo Err_HideApplicationForm
  • Dim hwndApplication As Long ' Fenêtre de l'application
  • Dim lRect As RECT ' Dimension du bureau
  • Dim wWidth As Long ' Largeur du formulaire
  • Dim wHeight As Long ' Hauteur du formulaire
  • ' Stocker le pointeur de le fenêtre principale
  • '---------------------------------------------
  • Application.Echo False
  • hwndApplication = GetParent(GetParent(GetWindow(FormId.hwnd, GW_HWNDFIRST)))
  • ' Maximiser la fenêtre principale
  • '--------------------------------
  • ShowWindow hwndApplication, 3
  • ' Restore du formulaire
  • '-----------------------
  • DoCmd.Restore
  • ' Stocker les dimensions du formulaire
  • '-------------------------------------
  • wWidth = FormId.WindowWidth
  • wHeight = FormId.WindowHeight
  • ' Cacher puis restorer la fenêtre principale
  • '-------------------------------------------
  • ShowWindow hwndApplication, 0
  • ShowWindow hwndApplication, 1
  • ' Stocker les dimensions du bureau
  • '---------------------------------
  • GetWindowRect GetDesktopWindow, lRect
  • ' Dimensionner et centrer la fenêtre principale
  • '----------------------------------------------
  • If CurrentDb.Properties("StartUpShowStatusBar") = False Then
  • MoveWindow hwndApplication _
  • , (lRect.right - (wWidth / 15)) / 2 _
  • , (lRect.bottom - (wHeight / 15)) / 2 _
  • , wWidth / 15, wHeight / 15 _
  • , 1
  • Else
  • MoveWindow hwndApplication _
  • , (lRect.right - (wWidth / 15)) / 2 _
  • , (lRect.bottom - (wHeight / 15)) / 2 _
  • , (wWidth / 15), 20 + (wHeight / 15) _
  • , 1
  • End If
  • ' Maximiser le formulaire
  • '------------------------
  • DoCmd.Maximize
  • ' Sortie et Gestion des Erreurs
  • '------------------------------
  • Exit_HideApplicationForm:
  • Application.Echo True
  • Exit Function
  • Err_HideApplicationForm:
  • Select Case Err.Number
  • Case Else
  • MsgBox Err.Number & " " & "CommonFunctions" & " " _
  • & "HideApplicationForm" & " :" & vbLf _
  • & Nz(Err.Description, "") & vbLf _
  • & "Values : " & FormId.Name
  • End Select
  • Resume Exit_HideApplicationForm
  • End Function
  • '===== ShowApplicationForm : Rétablir la fenêtre application =================================
  • Function ShowApplicationForm(FormId As Form)
  • On Error GoTo Err_ShowApplicationForm
  • Dim hwndApplication As Long ' Fenêtre de l'application
  • ' Stocker le pointeur de le fenêtre principale
  • '---------------------------------------------
  • Application.Echo False
  • hwndApplication = GetParent(GetParent(GetWindow(FormId.hwnd, GW_HWNDFIRST)))
  • ' Cacher, afficher puis maximiser la fenêtre principale
  • '------------------------------------------------------
  • ShowWindow hwndApplication, 0
  • ShowWindow hwndApplication, 1
  • ShowWindow hwndApplication, 3
  • ' Restore du formulaire
  • '-----------------------
  • DoCmd.Restore
  • ' Sortie et Gestion des Erreurs
  • '------------------------------
  • Exit_ShowApplicationForm:
  • Application.Echo True
  • Exit Function
  • Err_ShowApplicationForm:
  • Select Case Err.Number
  • Case Else
  • MsgBox Err.Number & " " & "CommonFunctions" & " " _
  • & "ShowApplicationForm" & " :" & vbLf _
  • & Nz(Err.Description, "") & vbLf _
  • & "Values : " & FormId.Name
  • End Select
  • Resume Exit_ShowApplicationForm
  • End Function
  • '===== Form_Open : Ouverture du formulaire ==================================================
  • Private Sub Form_Open(Cancel As Integer)
  • On Error GoTo Err_Form_Open
  • ' Cacher la fenêtre de l'application
  • '-----------------------------------
  • HideApplicationForm Me.Form
  • Exit_Form_Open:
  • Exit Sub
  • Err_Form_Open:
  • Select Case Err.Number
  • Case Else
  • MsgBox "Form_Open : Erreur n° " & Err.Number & " > " & Err.Description
  • End Select
  • Resume Exit_Form_Open
  • End Sub
  • '===== Form_KeyDown : Touche appuyée ========================================================
  • Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  • On Error GoTo Err_Form_KeyDown
  • ' CTRL A : Restorer la fenêtre de l'application
  • '----------------------------------------------
  • If KeyCode = vbKeyA And (Shift And acCtrlMask) > 0 Then
  • ShowApplicationForm Me.Form
  • KeyCode = 0
  • GoTo Exit_Form_KeyDown
  • End If
  • Exit_Form_KeyDown:
  • Exit Sub
  • Err_Form_KeyDown:
  • Select Case Err.Number
  • Case Else
  • MsgBox "Form_KeyDown : Erreur n° " & Err.Number & " > " & Err.Description
  • End Select
  • Resume Exit_Form_KeyDown
  • End Sub
'********************************************************************************************
'* ApiWindows : Déclaration des API Windows *
'********************************************************************************************
Option Compare Database
Option Explicit

' GetDesktopWindow : Donne le pointeur de la fenêtre du bureau
Public Declare Function GetDesktopWindow Lib "user32" ( _
) As Long

' GetParent : Donne le pointeur de la fenêtre parent
Public Declare Function GetParent Lib "user32" _
(ByVal hwnd As Long _
) As Long

' GetWindow : Donne le pointeur d'une fenêtre
Public Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long _
, ByVal wCmd As Long _
) As Long
Public Const GW_HWNDFIRST = 0 ' Pointeur de la première fenêtre
Public Const GW_HWNDNext = 2 ' Pointeur de la fenêtre suivante

' GetWindowRect : Donne le rectangle d'affichage de la fenêtre
Public Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Long _
, lpRect As RECT _
) As Long
Public Type RECT ' Rectangle d'affichage de la fenêtre
left As Long
top As Long
right As Long
bottom As Long
End Type

' MoveWindow : Positionne et dimensionne la fenêtre
Public Declare Function MoveWindow Lib "user32" _
(ByVal hwnd As Long _
, ByVal x As Long _
, ByVal y As Long _
, ByVal nWidth As Long _
, ByVal nHeight As Long _
, ByVal bRepaint As Long _
) As Long

' ShowWindow : Défini le mode d'affichage de la fenêtre
Public Declare Function ShowWindow Lib "user32" _
(ByVal hwnd As Long _
, ByVal nCmdShow As Long _
) As Long

'********************************************************************************************
'* CommonFunctions : Fonctions communes du projet *
'********************************************************************************************
Option Compare Database
Option Explicit

'===== HideApplicationForm : Cacher la fenêtre application ==================================
Function HideApplicationForm(FormId As Form)
On Error GoTo Err_HideApplicationForm
Dim hwndApplication As Long ' Fenêtre de l'application
Dim lRect As RECT ' Dimension du bureau
Dim wWidth As Long ' Largeur du formulaire
Dim wHeight As Long ' Hauteur du formulaire

' Stocker le pointeur de le fenêtre principale
'---------------------------------------------
Application.Echo False
hwndApplication = GetParent(GetParent(GetWindow(FormId.hwnd, GW_HWNDFIRST)))

' Maximiser la fenêtre principale
'--------------------------------
ShowWindow hwndApplication, 3

' Restore du formulaire
'-----------------------
DoCmd.Restore

' Stocker les dimensions du formulaire
'-------------------------------------
wWidth = FormId.WindowWidth
wHeight = FormId.WindowHeight

' Cacher puis restorer la fenêtre principale
'-------------------------------------------
ShowWindow hwndApplication, 0
ShowWindow hwndApplication, 1

' Stocker les dimensions du bureau
'---------------------------------
GetWindowRect GetDesktopWindow, lRect

' Dimensionner et centrer la fenêtre principale
'----------------------------------------------
If CurrentDb.Properties("StartUpShowStatusBar") = False Then
MoveWindow hwndApplication _
, (lRect.right - (wWidth / 15)) / 2 _
, (lRect.bottom - (wHeight / 15)) / 2 _
, wWidth / 15, wHeight / 15 _
, 1
Else
MoveWindow hwndApplication _
, (lRect.right - (wWidth / 15)) / 2 _
, (lRect.bottom - (wHeight / 15)) / 2 _
, (wWidth / 15), 20 + (wHeight / 15) _
, 1
End If

' Maximiser le formulaire
'------------------------
DoCmd.Maximize

' Sortie et Gestion des Erreurs
'------------------------------
Exit_HideApplicationForm:
Application.Echo True
Exit Function
Err_HideApplicationForm:
Select Case Err.Number
Case Else
MsgBox Err.Number & " " & "CommonFunctions" & " " _
& "HideApplicationForm" & " :" & vbLf _
& Nz(Err.Description, "") & vbLf _
& "Values : " & FormId.Name
End Select
Resume Exit_HideApplicationForm
End Function

'===== ShowApplicationForm : Rétablir la fenêtre application =================================
Function ShowApplicationForm(FormId As Form)
On Error GoTo Err_ShowApplicationForm
Dim hwndApplication As Long ' Fenêtre de l'application

' Stocker le pointeur de le fenêtre principale
'---------------------------------------------
Application.Echo False
hwndApplication = GetParent(GetParent(GetWindow(FormId.hwnd, GW_HWNDFIRST)))

' Cacher, afficher puis maximiser la fenêtre principale
'------------------------------------------------------
ShowWindow hwndApplication, 0
ShowWindow hwndApplication, 1
ShowWindow hwndApplication, 3

' Restore du formulaire
'-----------------------
DoCmd.Restore

' Sortie et Gestion des Erreurs
'------------------------------
Exit_ShowApplicationForm:
Application.Echo True
Exit Function
Err_ShowApplicationForm:
Select Case Err.Number
Case Else
MsgBox Err.Number & " " & "CommonFunctions" & " " _
& "ShowApplicationForm" & " :" & vbLf _
& Nz(Err.Description, "") & vbLf _
& "Values : " & FormId.Name
End Select
Resume Exit_ShowApplicationForm
End Function

'===== Form_Open : Ouverture du formulaire ==================================================
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

' Cacher la fenêtre de l'application
'-----------------------------------
HideApplicationForm Me.Form

Exit_Form_Open:
    Exit Sub
Err_Form_Open:
    Select Case Err.Number
        Case Else
            MsgBox "Form_Open : Erreur n° " & Err.Number & " > " & Err.Description
    End Select
    Resume Exit_Form_Open
End Sub

'===== Form_KeyDown : Touche appuyée ========================================================
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo Err_Form_KeyDown

' CTRL A : Restorer la fenêtre de l'application
'----------------------------------------------
If KeyCode = vbKeyA And (Shift And acCtrlMask) > 0 Then
    ShowApplicationForm Me.Form
    KeyCode = 0
    GoTo Exit_Form_KeyDown
End If

Exit_Form_KeyDown:
    Exit Sub
Err_Form_KeyDown:
    Select Case Err.Number
        Case Else
            MsgBox "Form_KeyDown : Erreur n° " & Err.Number & " > " & Err.Description
    End Select
    Resume Exit_Form_KeyDown
End Sub

 Conclusion

Vu les remarques et messages reçus, je joins un zip contenant un mdb exemple très simple qui je pense sera assez explicite sur la façon de déclarer les fonctions décrites.
En créant cet exemple, j'ai remarqué qu'il y avait des disfonctionnements lorsque le style de bordure du formulaire n'est pas de type fixe (trait simple fixe ou trait double fixe).

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  • Exemple.mdbTélécharger ce fichier [Réservé aux membres club]180 224 octets

Télécharger le zip


 Sources de la même categorie

Source avec Zip Source avec une capture Source .NET (Dotnet) TABLEAU ASCII - RETROUVER FACILEMENT LE CODE ASCII D'UN CARA... par raffika
Source avec Zip Source .NET (Dotnet) SCREENPRO - CHANGER DE FOND D'ÉCRAN AUTOMATIQUEMENT par raffika
Source avec Zip POINTEUR INTELLIGENT par DrMckey
Source avec Zip Source avec une capture RENDRE TRANSPARENT VOS FEUILLE -- OPACITE par zulrigh
Source avec Zip Source avec une capture CODAGE ET DÉCODAGE DE NOMBRE OU DE CHIFFRE par zulrigh

Commentaires et avis

Commentaire de TITOUN le 30/11/2003 15:57:05

Idée très astucieuse, qui existe de manière différente sous excel.
mais si on se met dans la peau d'un novice, il serait bien d'expliquer, comment tu déclare hideapplicationform au démarrage du formulaire.

Encore bravo pour l'astuce
TITOUN

Commentaire de elchico le 18/12/2003 23:08:25

Bien joué ClickPouf !
Pratique et astucieux, c'est le moins que l'on puisse dire !
Je te colle un "petit" 9, ca devrait te dire quelque chose :)

Commentaire de KiWin le 13/06/2004 08:34:06

Ton code est bien trop compliqué pour moi, et quelle tartine !! ;-)

Je fais pareil sous Excel avec simplement :

ActiveWorkbook.Parent.Visible = False

qui doit fonctionner sous Access avec un truc du genre :

ActiveForm.Parent.Visible = False

Commentaire de BELLIV le 20/07/2004 15:05:06

Je rajouterais juste un truc, pour la ligne :
If CurrentDb.Properties("StartUpShowStatusBar") = False Then

si la propriété "afficher barre d'état" n'a jamais été définie dans outils/démarrage, ça plante. il faut rajouter les 3 lignes de codes ci dessous juste avant le if :

Set Prp = CurrentDb.CreateProperty("StartUpShowStatusBar", dbBoolean, False)
CurrentDb.Properties.Append Prp
CurrentDb.Properties("StartUpShowStatusBar") = False

(source http://www.info-3000.com/access/daosaufrecordsets.htm)

sinon ça tourne nickel :)

Commentaire de BELLIV le 20/07/2004 15:14:22

suite au post précédent : les 3 lignes de codes ne sont à exécuter qu'une seule fois, en fait il est aussi simple d'aller dans outlis/démarrage et de cocher/décocher la case  ;)

on peut également remplacer
hwndApplication = GetParent(GetParent(GetWindow(FormId.hwnd, GW_HWNDFIRST)))
par
hwndApplication =application.hWndAccessApp

ce qui permet de s'affranchir de l'api getparent

Commentaire de Scarlett06 le 27/04/2005 11:59:56

J'ai mis ce code dans mon formulaire mais le problème c'est que je suis en automation et quand je quitte la fenetre j'ai access qui tourne quand meme dans mon gestionnaire de tache.

Ce que je voulais c'était d'enlever totalement la barre d'access mais comment faire?

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Septembre 2010
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
27282930   

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,468 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales