[VB] creer un form
Fermé
santiago69
-
30 oct. 2004 à 13:56
NY-152 Messages postés 115 Date d'inscription mercredi 22 juillet 2009 Statut Membre Dernière intervention 27 février 2021 - 7 août 2009 à 01:11
NY-152 Messages postés 115 Date d'inscription mercredi 22 juillet 2009 Statut Membre Dernière intervention 27 février 2021 - 7 août 2009 à 01:11
A voir également:
- [VB] creer un form
- Créer un compte gmail - Guide
- Créer un compte google - Guide
- Créer un groupe whatsapp - Guide
- Créer un compte instagram sur google - Guide
- Comment creer un pdf - Guide
5 réponses
NY-152
Messages postés
115
Date d'inscription
mercredi 22 juillet 2009
Statut
Membre
Dernière intervention
27 février 2021
24
7 août 2009 à 01:11
7 août 2009 à 01:11
Pour alimenter mon post concernant la création de forms dynamiquement et en en ayant aucune au préalable dans l'exécutable,
créez un projet EXE standard vierge,
supprimez la form qui s'y trouve,
mettez le mode de démarrage sur Sub Main,
Ajoutez un module,
Collez ce code et exécutez le vous verrez ce que l'on peut faire avec les API :)
/!\ Ce n'est qu'un très maigre exemple de ce qui est possible de faire bien sûr :)
Option Explicit
Public Declare Function RegisterClass Lib "user32" Alias "RegisterClassA" (Class As WNDCLASS) As Long
Public Declare Function UnregisterClass Lib "user32" Alias "UnregisterClassA" (ByVal lpClassName As String, ByVal hInstance As Long) As Long
Public Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As Msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Public Declare Function TranslateMessage Lib "user32" (lpMsg As Msg) As Long
Public Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As Msg) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Any) As Long
Public Declare Function LoadIcon Lib "user32" Alias "LoadIconA" (ByVal hInstance As Long, ByVal lpIconName As String) As Long
Public Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Public Declare Sub PostQuitMessage Lib "user32" (ByVal nExitCode As Long)
Public Type WNDCLASS
style As Long
lpfnwndproc As Long
cbClsextra As Long
cbWndExtra2 As Long
hInstance As Long
hIcon As Long
hCursor As Long
hbrBackground As Long
lpszMenuName As String
lpszClassName As String
End Type
Public Type POINTAPI
x As Long
y As Long
End Type
Public Type Msg
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Public Const CS_VREDRAW = &H1
Public Const CS_HREDRAW = &H2
Public Const CW_USEDEFAULT = &H80000000
Public Const ES_MULTILINE = &H4&
Public Const WS_BORDER = &H800000
Public Const WS_CHILD = &H40000000
Public Const WS_OVERLAPPED = &H0&
Public Const WS_CAPTION = &HC00000
Public Const WS_SYSMENU = &H80000
Public Const WS_THICKFRAME = &H40000
Public Const WS_MINIMIZEBOX = &H20000
Public Const WS_MAXIMIZEBOX = &H10000
Public Const WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)
Public Const WS_EX_CLIENTEDGE = &H200&
Public Const COLOR_WINDOW = 5
Public Const WM_DESTROY = &H2
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const IDC_ARROW = 32512&
Public Const IDI_APPLICATION = 32512&
Public Const GWL_WNDPROC = (-4)
Public Const SW_SHOWNORMAL = 1
Public Const MB_OK = &H0&
Public Const MB_ICONEXCLAMATION = &H30&
Public Const gClassName = "MyClassName"
Public Const gAppName = "Creation Form par API"
Public gButOldProc As Long
Public gHwnd As Long, gButtonHwnd As Long, gEditHwnd As Long
Public Sub Main()
Dim wMsg As Msg
If RegisterWindowClass = False Then Exit Sub
If CreateWindows Then
Do While GetMessage(wMsg, 0&, 0&, 0&)
Call TranslateMessage(wMsg)
Call DispatchMessage(wMsg)
Loop
End If
Call UnregisterClass(gClassName$, App.hInstance)
End Sub
Public Function RegisterWindowClass() As Boolean
Dim wc As WNDCLASS
wc.style = CS_HREDRAW Or CS_VREDRAW
wc.lpfnwndproc = GetAddress(AddressOf WndProc)
wc.hInstance = App.hInstance
wc.hIcon = LoadIcon(0&, IDI_APPLICATION)
wc.hCursor = LoadCursor(0&, IDC_ARROW)
wc.hbrBackground = COLOR_WINDOW
wc.lpszClassName = gClassName$
RegisterWindowClass = RegisterClass(wc) <> 0
End Function
Public Function CreateWindows() As Boolean
gHwnd& = CreateWindowEx(0&, gClassName$, gAppName$, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 208, 150, 0&, 0&, App.hInstance, ByVal 0&)
gButtonHwnd& = CreateWindowEx(0&, "Button", "Cliquez ici !", WS_CHILD, 58, 90, 85, 25, gHwnd&, 0&, App.hInstance, 0&)
gEditHwnd& = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "Ceci est une zone de texte." & vbCrLf & "Elle est multi-lignes.", WS_CHILD Or ES_MULTILINE, 0&, 0&, 200, 80, gHwnd&, 0&, App.hInstance, 0&)
Call ShowWindow(gHwnd&, SW_SHOWNORMAL)
Call ShowWindow(gButtonHwnd&, SW_SHOWNORMAL)
Call ShowWindow(gEditHwnd&, SW_SHOWNORMAL)
gButOldProc& = GetWindowLong(gButtonHwnd&, GWL_WNDPROC)
Call SetWindowLong(gButtonHwnd&, GWL_WNDPROC, GetAddress(AddressOf ButtonWndProc))
CreateWindows = (gHwnd& <> 0)
End Function
Public Function WndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim strTemp As String
Select Case uMsg&
Case WM_DESTROY:
Call PostQuitMessage(0&)
End Select
WndProc = DefWindowProc(hwnd&, uMsg&, wParam&, lParam&)
End Function
Public Function ButtonWndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case uMsg&
Case WM_LBUTTONUP:
Call MessageBox(gHwnd&, "Vous avez cliqué sur le bouton :)", App.Title, MB_OK Or MB_ICONEXCLAMATION)
End Select
ButtonWndProc = CallWindowProc(gButOldProc&, hwnd&, uMsg&, wParam&, lParam&)
End Function
Public Function GetAddress(ByVal lngAddr As Long) As Long
GetAddress = lngAddr&
End Function
créez un projet EXE standard vierge,
supprimez la form qui s'y trouve,
mettez le mode de démarrage sur Sub Main,
Ajoutez un module,
Collez ce code et exécutez le vous verrez ce que l'on peut faire avec les API :)
/!\ Ce n'est qu'un très maigre exemple de ce qui est possible de faire bien sûr :)
Option Explicit
Public Declare Function RegisterClass Lib "user32" Alias "RegisterClassA" (Class As WNDCLASS) As Long
Public Declare Function UnregisterClass Lib "user32" Alias "UnregisterClassA" (ByVal lpClassName As String, ByVal hInstance As Long) As Long
Public Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As Msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Public Declare Function TranslateMessage Lib "user32" (lpMsg As Msg) As Long
Public Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As Msg) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Any) As Long
Public Declare Function LoadIcon Lib "user32" Alias "LoadIconA" (ByVal hInstance As Long, ByVal lpIconName As String) As Long
Public Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Public Declare Sub PostQuitMessage Lib "user32" (ByVal nExitCode As Long)
Public Type WNDCLASS
style As Long
lpfnwndproc As Long
cbClsextra As Long
cbWndExtra2 As Long
hInstance As Long
hIcon As Long
hCursor As Long
hbrBackground As Long
lpszMenuName As String
lpszClassName As String
End Type
Public Type POINTAPI
x As Long
y As Long
End Type
Public Type Msg
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Public Const CS_VREDRAW = &H1
Public Const CS_HREDRAW = &H2
Public Const CW_USEDEFAULT = &H80000000
Public Const ES_MULTILINE = &H4&
Public Const WS_BORDER = &H800000
Public Const WS_CHILD = &H40000000
Public Const WS_OVERLAPPED = &H0&
Public Const WS_CAPTION = &HC00000
Public Const WS_SYSMENU = &H80000
Public Const WS_THICKFRAME = &H40000
Public Const WS_MINIMIZEBOX = &H20000
Public Const WS_MAXIMIZEBOX = &H10000
Public Const WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)
Public Const WS_EX_CLIENTEDGE = &H200&
Public Const COLOR_WINDOW = 5
Public Const WM_DESTROY = &H2
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const IDC_ARROW = 32512&
Public Const IDI_APPLICATION = 32512&
Public Const GWL_WNDPROC = (-4)
Public Const SW_SHOWNORMAL = 1
Public Const MB_OK = &H0&
Public Const MB_ICONEXCLAMATION = &H30&
Public Const gClassName = "MyClassName"
Public Const gAppName = "Creation Form par API"
Public gButOldProc As Long
Public gHwnd As Long, gButtonHwnd As Long, gEditHwnd As Long
Public Sub Main()
Dim wMsg As Msg
If RegisterWindowClass = False Then Exit Sub
If CreateWindows Then
Do While GetMessage(wMsg, 0&, 0&, 0&)
Call TranslateMessage(wMsg)
Call DispatchMessage(wMsg)
Loop
End If
Call UnregisterClass(gClassName$, App.hInstance)
End Sub
Public Function RegisterWindowClass() As Boolean
Dim wc As WNDCLASS
wc.style = CS_HREDRAW Or CS_VREDRAW
wc.lpfnwndproc = GetAddress(AddressOf WndProc)
wc.hInstance = App.hInstance
wc.hIcon = LoadIcon(0&, IDI_APPLICATION)
wc.hCursor = LoadCursor(0&, IDC_ARROW)
wc.hbrBackground = COLOR_WINDOW
wc.lpszClassName = gClassName$
RegisterWindowClass = RegisterClass(wc) <> 0
End Function
Public Function CreateWindows() As Boolean
gHwnd& = CreateWindowEx(0&, gClassName$, gAppName$, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 208, 150, 0&, 0&, App.hInstance, ByVal 0&)
gButtonHwnd& = CreateWindowEx(0&, "Button", "Cliquez ici !", WS_CHILD, 58, 90, 85, 25, gHwnd&, 0&, App.hInstance, 0&)
gEditHwnd& = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "Ceci est une zone de texte." & vbCrLf & "Elle est multi-lignes.", WS_CHILD Or ES_MULTILINE, 0&, 0&, 200, 80, gHwnd&, 0&, App.hInstance, 0&)
Call ShowWindow(gHwnd&, SW_SHOWNORMAL)
Call ShowWindow(gButtonHwnd&, SW_SHOWNORMAL)
Call ShowWindow(gEditHwnd&, SW_SHOWNORMAL)
gButOldProc& = GetWindowLong(gButtonHwnd&, GWL_WNDPROC)
Call SetWindowLong(gButtonHwnd&, GWL_WNDPROC, GetAddress(AddressOf ButtonWndProc))
CreateWindows = (gHwnd& <> 0)
End Function
Public Function WndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim strTemp As String
Select Case uMsg&
Case WM_DESTROY:
Call PostQuitMessage(0&)
End Select
WndProc = DefWindowProc(hwnd&, uMsg&, wParam&, lParam&)
End Function
Public Function ButtonWndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case uMsg&
Case WM_LBUTTONUP:
Call MessageBox(gHwnd&, "Vous avez cliqué sur le bouton :)", App.Title, MB_OK Or MB_ICONEXCLAMATION)
End Select
ButtonWndProc = CallWindowProc(gButOldProc&, hwnd&, uMsg&, wParam&, lParam&)
End Function
Public Function GetAddress(ByVal lngAddr As Long) As Long
GetAddress = lngAddr&
End Function
choubaka
Messages postés
39402
Date d'inscription
jeudi 4 avril 2002
Statut
Modérateur
Dernière intervention
28 octobre 2024
2 102
30 oct. 2004 à 15:34
30 oct. 2004 à 15:34
salut
VB s'appuyant sur les bibliothèques graphiques existantes, la réponse est non
Il faut utiliser des langages plus poussés comme C++ ou java pour ça
Chouba,
Pochard d'assaut ..
VB s'appuyant sur les bibliothèques graphiques existantes, la réponse est non
Il faut utiliser des langages plus poussés comme C++ ou java pour ça
Chouba,
Pochard d'assaut ..
santiago69
Messages postés
477
Date d'inscription
mercredi 7 mars 2001
Statut
Membre
Dernière intervention
12 septembre 2016
209
30 oct. 2004 à 17:51
30 oct. 2004 à 17:51
c'est cool, merci pour ta reponse.
pourtant, en VBA sous Access j'arrive a creer des formulaires et des controles.
pour les forms tant pis ;o(( pourrais-je au moins creer des controles ?
Il y a 10 types de personnes dans le monde
Ceux qui comprennent le binaire et les autres.
pourtant, en VBA sous Access j'arrive a creer des formulaires et des controles.
pour les forms tant pis ;o(( pourrais-je au moins creer des controles ?
Il y a 10 types de personnes dans le monde
Ceux qui comprennent le binaire et les autres.
NY-152
Messages postés
115
Date d'inscription
mercredi 22 juillet 2009
Statut
Membre
Dernière intervention
27 février 2021
24
5 août 2009 à 15:15
5 août 2009 à 15:15
Totalement faux on peux céer une form dynamiquement ainsi que tout son contenu. C'est fastidieux et ça donne un code très long mais c'est possible; et ce via les API :)
Bonjour,
Quel est ton besoin réel?
Parce que ce que j'ai fais, j'ai créé un formulaire avec toutes les textbox.
Seulement, en fonction de mes variables, il m'affiche ou non les textbox.
Ainsi si j'ai une vraiable =1 il m'affiche la textbox 1 si j'ai une variable =2 alors il m'affiche la textbox 2.
Et quand je dois le masque tu peux faire userform.hidden.
Quel est ton besoin réel?
Parce que ce que j'ai fais, j'ai créé un formulaire avec toutes les textbox.
Seulement, en fonction de mes variables, il m'affiche ou non les textbox.
Ainsi si j'ai une vraiable =1 il m'affiche la textbox 1 si j'ai une variable =2 alors il m'affiche la textbox 2.
Et quand je dois le masque tu peux faire userform.hidden.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
NY-152
Messages postés
115
Date d'inscription
mercredi 22 juillet 2009
Statut
Membre
Dernière intervention
27 février 2021
24
7 août 2009 à 00:34
7 août 2009 à 00:34
Je ne vois pas le rapport là ...