elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: AIO elhacker.NET 2021 Compilación herramientas análisis y desinfección malware


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  crear form con codigo
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: crear form con codigo  (Leído 1,852 veces)
Zeroql


Desconectado Desconectado

Mensajes: 957


Todo lo k sucede sucede por una razon


Ver Perfil WWW
crear form con codigo
« en: 28 Noviembre 2006, 23:42 pm »

si esa es la pregunta como hago para crear un form por codigo
ejm:
tengo un submain y por este quiero krear un form

sub Main()
 codigo...
end sub
como lo hago?


En línea

Dime y lo olvido, enseñame y lo recuerdo, involucrame y lo aprendo.
/.-ZEROQL.-\   -----  #937675#

CeLaYa


Desconectado Desconectado

Mensajes: 543



Ver Perfil
Re: crear form con codigo
« Respuesta #1 en: 1 Diciembre 2006, 18:17 pm »

 lo que puedes hacer es crear una instancia de un form

Código:
Sub Main()
    Dim x As Form
    Set x = New Form1
    x.Show
end sub


en este caso el proyecto tiene un form "Form1" y lo que hago es crear una nueva instancia de ese form


En línea

"La soledad es el elemento de los grandes talentos".
Cristina de Suecia (1626-1689) Reina de Suecia.
Zeroql


Desconectado Desconectado

Mensajes: 957


Todo lo k sucede sucede por una razon


Ver Perfil WWW
Re: crear form con codigo
« Respuesta #2 en: 1 Diciembre 2006, 18:30 pm »

CeLaYa te agradezco mucho pero eso es para duplicar un form, lo que necesito es crear el form desde 0
En línea

Dime y lo olvido, enseñame y lo recuerdo, involucrame y lo aprendo.
/.-ZEROQL.-\   -----  #937675#

IP3

Desconectado Desconectado

Mensajes: 73


Ver Perfil
Re: crear form con codigo
« Respuesta #3 en: 1 Diciembre 2006, 19:50 pm »

Eso es bastante facil, mira, te explico, el secreto esta en los modulos, presta atencion!

Crear un modulo, la referencia es de win32.

Citar
Public Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Public Declare Function LoadCursorFromFile Lib "user32" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long
Public Declare Sub PostQuitMessage Lib "user32" (ByVal nExitCode As Long)
Public Declare Function ValidateRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Public Declare Function BeginPaint Lib "user32" (ByVal hwnd As Long, lpPaint As PAINTSTRUCT) As Long
Public Declare Function EndPaint Lib "user32" (ByVal hwnd As Long, lpPaint As PAINTSTRUCT) As Long
Public Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Public Type PAINTSTRUCT
        hdc As Long
        fErase As Long
        rcPaint As RECT
        fRestore As Long
        fIncUpdate As Long
        rgbReserved(32) As Byte
End Type

Public Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Public Declare Function GetWindowDC Lib "user32" (ByVal hwnd 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 Const CS_CLASSDC = &H40
Public Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long

Public Declare Function UnregisterClass Lib "user32" Alias "UnregisterClassA" (ByVal lpClassName As String, ByVal hInstance As Long) As Long
Public Declare Function RegisterClassEx Lib "user32" Alias "RegisterClassExA" (pcWndClassEx As WNDCLASSEX) As Integer
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 GetDesktopWindow Lib "user32" () As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Const SW_SHOW = 5
Public Declare Function UpdateWindow Lib "user32" (ByVal hwnd 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 Const CS_OWNDC = &H20
Public Const CS_HREDRAW = &H2
Public Const CS_VREDRAW = &H1
Public Const COLOR_APPWORKSPACE = 12

Public Const WS_BORDER = &H800000
Public Const WS_CAPTION = &HC00000                  '  WS_BORDER Or WS_DLGFRAME
Public Const WS_CHILD = &H40000000
Public Const WS_CHILDWINDOW = (WS_CHILD)
Public Const WS_CLIPCHILDREN = &H2000000
Public Const WS_CLIPSIBLINGS = &H4000000
Public Const WS_DISABLED = &H8000000
Public Const WS_DLGFRAME = &H400000
Public Const WS_EX_ACCEPTFILES = &H10&
Public Const WS_EX_DLGMODALFRAME = &H1&
Public Const WS_EX_NOPARENTNOTIFY = &H4&
Public Const WS_EX_TOPMOST = &H8&
Public Const WS_EX_TRANSPARENT = &H20&
Public Const WS_GROUP = &H20000
Public Const WS_HSCROLL = &H100000
Public Const WS_MINIMIZE = &H20000000
Public Const WS_ICONIC = WS_MINIMIZE
Public Const WS_MAXIMIZE = &H1000000
Public Const WS_MAXIMIZEBOX = &H10000
Public Const WS_SYSMENU = &H80000
Public Const WS_MINIMIZEBOX = &H20000
Public Const WS_OVERLAPPED = &H0&
Public Const WS_THICKFRAME = &H40000
Public Const WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)
Public Const WS_POPUP = &H80000000
Public Const WS_POPUPWINDOW = (WS_POPUP Or WS_BORDER Or WS_SYSMENU)
Public Const WS_SIZEBOX = WS_THICKFRAME

Public Const WS_TABSTOP = &H10000

Public Const WS_TILED = WS_OVERLAPPED
Public Const WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW
Public Const WS_VISIBLE = &H10000000
Public Const WS_VSCROLL = &H200000


' Window Messages
Public Const WM_NULL = &H0
Public Const WM_CREATE = &H1
Public Const WM_DESTROY = &H2
Const WM_MOVE = &H3
Const WM_SIZE = &H5

Const WM_ACTIVATE = &H6
'
'  WM_ACTIVATE state values

Const WA_INACTIVE = 0
Const WA_ACTIVE = 1
Const WA_CLICKACTIVE = 2

Const WM_SETFOCUS = &H7
Const WM_KILLFOCUS = &H8
Const WM_ENABLE = &HA
Const WM_SETREDRAW = &HB
Const WM_SETTEXT = &HC
Const WM_GETTEXT = &HD
Const WM_GETTEXTLENGTH = &HE
Public Const WM_PAINT = &HF
Const WM_CLOSE = &H10
Const WM_QUERYENDSESSION = &H11
Const WM_QUIT = &H12
Const WM_QUERYOPEN = &H13
Const WM_ERASEBKGND = &H14
Const WM_SYSCOLORCHANGE = &H15
Const WM_ENDSESSION = &H16
Const WM_SHOWWINDOW = &H18
Const WM_WININICHANGE = &H1A
Const WM_DEVMODECHANGE = &H1B
Const WM_ACTIVATEAPP = &H1C
Const WM_FONTCHANGE = &H1D
Const WM_TIMECHANGE = &H1E
Const WM_CANCELMODE = &H1F
Const WM_SETCURSOR = &H20
Const WM_MOUSEACTIVATE = &H21
Const WM_CHILDACTIVATE = &H22
Const WM_QUEUESYNC = &H23

Const WM_GETMINMAXINFO = &H24

Public Type WNDCLASSEX
    cbSize As Long
    style As Long
    lpfnWndProc As Long
    cbClsExtra As Long
    cbWndExtra As Long
    hInstance As Long
    hIcon As Long
    hCursor As Long
    hbrBackground As Long
    lpszMenuName As String
    lpszClassName As String
    hIconSm As Long
End Type


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 msg
    hwnd As Long
    message As Long
    wParam As Long
    lParam As Long
    time As Long
'    pt As POINTAPI
End Type


Bueno, procedamos ahora a crear el formulario

Citar
im hwnd As Long



Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Select Case uMsg
    Case WM_DESTROY
        PostQuitMessage (0)
    Case WM_PAINT
        Dim hdc As Long
        Dim pt As PAINTSTRUCT
        Dim rc As RECT
       
        hdc = BeginPaint(hwnd, pt)
       
        GetClientRect hwnd, rc
        rc.Top = rc.Bottom / 2
        DrawText hdc, "This is a window, without VB forms!!!", 37, rc, 1
       
        EndPaint hwnd, pt
    Case Else
        WindowProc = DefWindowProc(hwnd, uMsg, wParam, lParam)
  End Select
End Function


Sub Main()
   
    Dim classinfo As WNDCLASSEX
   
    classinfo.style = 0
    classinfo.lpfnWndProc = FarProc(AddressOf WindowProc)
    classinfo.cbClsExtra = 0
    classinfo.cbWndExtra = 0
    classinfo.hInstance = App.hInstance
    classinfo.hbrBackground = COLOR_APPWORKSPACE
    classinfo.lpszMenuName = ""
    classinfo.lpszClassName = "NoForms"
    classinfo.cbSize = Len(classinfo)

     
   
     RegisterClassEx classinfo
   
   
   
    hwnd = CreateWindowEx(WS_EX_DLGMODALFRAME, "NoForms", "Look No Forms!", WS_OVERLAPPEDWINDOW, 300, 300, 300, 300, GetDesktopWindow(), 0, App.hInstance, 0)
       
   
    ShowWindow hwnd, SW_SHOW
    UpdateWindow hwnd
   
    Dim msg As msg
    Do While GetMessage(msg, 0, 0, 0)
        TranslateMessage msg
        DispatchMessage msg
    Loop

    UnregisterClass "NOMBRE FORMULARIO", App.hInstance
   
End Sub


Public Function FarProc(lpProcName As Long) As Long
    FarProc = lpProcName
End Function


Digo que es facil por que cuando lo vi, dije, buah!! que tonto soy, no me di cuenta!!

Fuente: Google

Suerte con tu proyecto ;)
En línea

Zeroql


Desconectado Desconectado

Mensajes: 957


Todo lo k sucede sucede por una razon


Ver Perfil WWW
Re: crear form con codigo
« Respuesta #4 en: 2 Diciembre 2006, 16:50 pm »

IP3 muchas gracias. pero si esta bastabte facil. no se me hubiera ocurrido llamar a las apis para eso.y bastante que buske en google, peron no la buske para que me diera con apis. pense que  para krear este form habia codigo en visual que hiciara eso....
pero oye es lo mismo que krear un form en C++ asi de facil.
Aun asi muchas gracias.

Segun esto podemos dar el tema por Cerrado
En línea

Dime y lo olvido, enseñame y lo recuerdo, involucrame y lo aprendo.
/.-ZEROQL.-\   -----  #937675#

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Crear un Form Propio C
Programación General
Riki_89D 3 3,708 Último mensaje 6 Mayo 2011, 10:34 am
por d(-_-)b
Como crear un exe en un windows form
.NET (C#, VB.NET, ASP)
Devilboy.Devil 0 1,787 Último mensaje 20 Noviembre 2013, 16:42 pm
por Devilboy.Devil
¿Cómo crear un Windows Form? « 1 2 »
Programación C/C++
Meta 15 7,419 Último mensaje 17 Marzo 2014, 22:22 pm
por BloodSharp
¿Diferencia al crear formulario Windwos Form CLR con MFC?
Programación C/C++
Meta 2 2,230 Último mensaje 9 Diciembre 2015, 20:43 pm
por Meta
Crear 5 form y que aparezcan en forma aleatoria. con vb 2012 « 1 2 »
.NET (C#, VB.NET, ASP)
Edierb 17 8,772 Último mensaje 31 Marzo 2017, 17:49 pm
por Edierb
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines