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

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  [SOLUCIONADO] ¿Cómo añadir dos botones al formulario?
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 2 [3] Ir Abajo Respuesta Imprimir
Autor Tema: [SOLUCIONADO] ¿Cómo añadir dos botones al formulario?  (Leído 10,570 veces)
Meta


Desconectado Desconectado

Mensajes: 3.438



Ver Perfil WWW
Re: ¿Cómo añadir dos botones al formulario?
« Respuesta #20 en: 8 Abril 2018, 22:11 pm »

Editado, volver a leer el post anterior donde pone Edito:.

Falta este donde encajarlo bien.
Código
  1. HWND btnOK = CreateWindowW(
  2. L"BUTTON", // clase del control
  3. L"OK",
  4. WS_CHILD | WS_PUSBUTTON | WS_VISIBLE, // estilo del control. La clase button puede ser checkbox, radio, etc.
  5. 5, 5, // posición respecto del client area del parent
  6. 40, 20,  // dimensiones del control
  7. hWnd,   // --> este es el handle de tu ventana principal
  8. 1, // este es el identificador de tu control. De modo predefinido 1 = IDOK, 2 = IDCANCEL
  9. hInstance,
  10. nullptr);


En línea

srWhiteSkull


Desconectado Desconectado

Mensajes: 444



Ver Perfil WWW
Re: ¿Cómo añadir dos botones al formulario?
« Respuesta #21 en: 8 Abril 2018, 22:17 pm »

Vale, ahí lo puedes hacer también, pero con la función que te cité te sirve para cualquier componente, incluso ventanas y puedes usarla en cualquier parte del programa, por ejemplo en un evento, ya que la programación en Win32 es así, a base de eventos o mensajes.


En línea

srWhiteSkull


Desconectado Desconectado

Mensajes: 444



Ver Perfil WWW
Re: ¿Cómo añadir dos botones al formulario?
« Respuesta #22 en: 8 Abril 2018, 22:26 pm »

https://en.wikipedia.org/wiki/Message_loop_in_Microsoft_Windows
En línea

Meta


Desconectado Desconectado

Mensajes: 3.438



Ver Perfil WWW
Re: ¿Cómo añadir dos botones al formulario?
« Respuesta #23 en: 8 Abril 2018, 23:56 pm »

Buenas:

Por fin.

Código
  1. case WM_CREATE:
  2. {
  3. HWND btnOK = CreateWindowW(
  4. L"BUTTON", // Clase del control.
  5. L"Abrir", // Etiqueta del botón.
  6. WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, // Estilo del control. La clase button puede ser checkbox, radio, etc.
  7. 45, 135, // Posición respecto del client area del parent.
  8. 75, 23, // Dimensiones del control.
  9. hWnd, // --> Este es el handle de la ventana principal.
  10. (HMENU)101, // Este es el identificador del control. De modo predefinido 1 = IDOK, 2 = IDCANCEL
  11. hInst,
  12. nullptr);
  13.  
  14. HWND btnOK2 = CreateWindowW(
  15. L"BUTTON", // Clase del control.
  16. L"Cerrar", // Etiqueta del botón.
  17. WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, // Estilo del control. La clase button puede ser checkbox, radio, etc.
  18. 165, 135, // Posición respecto del client area del parent.
  19. 75, 23, // Dimensiones del control.
  20. hWnd, // --> Este es el handle de la ventana principal.
  21. (HMENU)102, // Este es el identificador del control. De modo predefinido 1 = IDOK, 2 = IDCANCEL
  22. hInst,
  23. nullptr);
  24. }

Me falta detallitos como centrar el formulario en el centro de la pantalla.

Ahora voy a por los comandos para abrir y cerrar la bandeja del lector.

Abrir:
Código
  1. mciSendString("set CDAudio door open", rt, 127, IntPtr::Zero);

Cerrar:
Código
  1. mciSendString("set CDAudio door closed", rt, 127, IntPtr::Zero);

Para que funcione, antes hacer esto:




En el lenguaje C++ del CLR, este es su código.
Código
  1. private: System::Void button_Abrir_Click(System::Object^  sender, System::EventArgs^  e) {
  2. label_Mensaje->Text = "Abriendo...";
  3. Application::DoEvents();
  4. mciSendString("set CDAudio door open", rt, 127, IntPtr::Zero);
  5. label_Mensaje->Text = "Abierto.";
  6. }
Para que funcione bien los eventos del Abriendo... y Abierto.

Sigo investigando.

Saludos y muchas gracias por todo a tod@s.
En línea

Meta


Desconectado Desconectado

Mensajes: 3.438



Ver Perfil WWW
Re: ¿Cómo añadir dos botones al formulario?
« Respuesta #24 en: 9 Abril 2018, 17:43 pm »

Buenas de nuevo:

Teniendo el código completo que ya y por fin puse un label y dos botones gracias a estos enlaces y ayudas de ustedes.

https://msdn.microsoft.com/es-es/library/windows/desktop/ms632679(v=vs.85).aspx
https://msdn.microsoft.com/es-es/library/windows/desktop/bb775951(v=vs.85).aspx



Código commpleto.
Código
  1. #include "stdafx.h"
  2. #include "Bandeja_Form_Win32_cpp.h"
  3. #include "mmsystem.h" // No olvidar.
  4.  
  5. #define MAX_LOADSTRING 100
  6.  
  7. // Variables globales:
  8. HINSTANCE hInst;                                // Instancia actual
  9. WCHAR szTitle[MAX_LOADSTRING];                  // Texto de la barra de título
  10. WCHAR szWindowClass[MAX_LOADSTRING];            // nombre de clase de la ventana principal
  11.  
  12. // Declaraciones de funciones adelantadas incluidas en este módulo de código:
  13. ATOM                MyRegisterClass(HINSTANCE hInstance);
  14. BOOL                InitInstance(HINSTANCE, int);
  15. LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  16. INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  17.  
  18. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  19.                     _In_opt_ HINSTANCE hPrevInstance,
  20.                     _In_ LPWSTR    lpCmdLine,
  21.                     _In_ int       nCmdShow)
  22. {
  23.    UNREFERENCED_PARAMETER(hPrevInstance);
  24.    UNREFERENCED_PARAMETER(lpCmdLine);
  25.  
  26.    // TODO: colocar código aquí.
  27.  
  28.    // Inicializar cadenas globales
  29.    LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  30.    LoadStringW(hInstance, IDC_BANDEJAFORMWIN32CPP, szWindowClass, MAX_LOADSTRING);
  31.    MyRegisterClass(hInstance);
  32.  
  33.    // Realizar la inicialización de la aplicación:
  34.    if (!InitInstance (hInstance, nCmdShow))
  35.    {
  36.        return FALSE;
  37.    }
  38.  
  39.    HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_BANDEJAFORMWIN32CPP));
  40.  
  41.    MSG msg;
  42.  
  43.    // Bucle principal de mensajes:
  44.    while (GetMessage(&msg, nullptr, 0, 0))
  45.    {
  46.        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  47.        {
  48.            TranslateMessage(&msg);
  49.            DispatchMessage(&msg);
  50.        }
  51.    }
  52.  
  53.    return (int) msg.wParam;
  54. }
  55.  
  56.  
  57.  
  58. //
  59. //  FUNCIÓN: MyRegisterClass()
  60. //
  61. //  PROPÓSITO: registrar la clase de ventana.
  62. //
  63. ATOM MyRegisterClass(HINSTANCE hInstance)
  64. {
  65.    WNDCLASSEXW wcex;
  66.  
  67.    wcex.cbSize = sizeof(WNDCLASSEX);
  68.  
  69.    wcex.style          = CS_HREDRAW | CS_VREDRAW;
  70.    wcex.lpfnWndProc    = WndProc;
  71.    wcex.cbClsExtra     = 0;
  72.    wcex.cbWndExtra     = 0;
  73.    wcex.hInstance      = hInstance;
  74.    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_BANDEJAFORMWIN32CPP));
  75.    wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
  76.    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  77.    wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_BANDEJAFORMWIN32CPP);
  78.    wcex.lpszClassName  = szWindowClass;
  79.    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  80.  
  81.    return RegisterClassExW(&wcex);
  82. }
  83.  
  84. //
  85. //   FUNCIÓN: InitInstance(HINSTANCE, int)
  86. //
  87. //   PROPÓSITO: guardar el identificador de instancia y crear la ventana principal
  88. //
  89. //   COMENTARIOS:
  90. //
  91. //        En esta función, se guarda el identificador de instancia en una variable común y
  92. //        se crea y muestra la ventana principal del programa.
  93. //
  94. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  95. {
  96.   hInst = hInstance; // Almacenar identificador de instancia en una variable global
  97.  
  98.   // #######################################################################
  99.   // Redimensionar formulario a 300 x 300.
  100.   HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  101.      CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, nullptr, nullptr, hInstance, nullptr);
  102.   // #######################################################################
  103.  
  104.   if (!hWnd)
  105.   {
  106.      return FALSE;
  107.   }
  108.  
  109.   ShowWindow(hWnd, nCmdShow);
  110.   UpdateWindow(hWnd);
  111.  
  112.   return TRUE;
  113. }
  114.  
  115. //
  116. //  FUNCIÓN: WndProc(HWND, UINT, WPARAM, LPARAM)
  117. //
  118. //  PROPÓSITO:  procesar mensajes de la ventana principal.
  119. //
  120. //  WM_COMMAND  - procesar el menú de aplicaciones
  121. //  WM_PAINT    - Pintar la ventana principal
  122. //  WM_DESTROY  - publicar un mensaje de salida y volver
  123. //
  124. //
  125. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  126. {
  127.    switch (message)
  128.    {
  129. // #######################################################################
  130. // Crear botones Abrir y Cerrar.
  131. case WM_CREATE:
  132. {
  133. HWND btnOK = CreateWindowW(
  134. L"BUTTON", // Clase del control.
  135. L"Abrir", // Etiqueta del botón.
  136. WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, // Estilo del control. La clase button puede ser checkbox, radio, etc.
  137. 45, 135, // Posición respecto del client area del parent.
  138. 75, 23, // Dimensiones del control.
  139. hWnd, // --> Este es el handle de la ventana principal.
  140. (HMENU)101, // Este es el identificador del control. De modo predefinido 1 = IDOK, 2 = IDCANCEL
  141. hInst,
  142. nullptr);
  143.  
  144. HWND btnOK2 = CreateWindowW(
  145. L"BUTTON", // Clase del control.
  146. L"Cerrar", // Etiqueta del botón.
  147. WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, // Estilo del control. La clase button puede ser checkbox, radio, etc.
  148. 165, 135, // Posición respecto del client area del parent.
  149. 75, 23, // Dimensiones del control.
  150. hWnd, // --> Este es el handle de la ventana principal.
  151. (HMENU)102, // Este es el identificador del control. De modo predefinido 1 = IDOK, 2 = IDCANCEL
  152. hInst,
  153. nullptr);
  154.  
  155. // Label o etiqueta.
  156. HWND edit = CreateWindowW(
  157. L"STATIC", // Clase del control.
  158. L"Hola.", // Etiqueta del botón.
  159. WS_CHILD | SS_SIMPLE | WS_VISIBLE, // Estilo del control. La clase button puede ser checkbox, radio, etc.
  160. 125, 55, // Posición respecto del client area del parent.
  161. 75, 23, // Dimensiones del control.
  162. hWnd, // --> Este es el handle de la ventana principal.
  163. (HMENU)103, // Este es el identificador del control. De modo predefinido 1 = IDOK, 2 = IDCANCEL
  164. hInst,
  165. nullptr);
  166. }
  167.  
  168. break;
  169. // #######################################################################
  170.  
  171.    case WM_COMMAND:
  172.        {
  173.            int wmId = LOWORD(wParam);
  174.            // Analizar las selecciones de menú:
  175.            switch (wmId)
  176.            {
  177.            case IDM_ABOUT:
  178.                DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  179.                break;
  180.            case IDM_EXIT:
  181.                DestroyWindow(hWnd);
  182.                break;
  183.            default:
  184.                return DefWindowProc(hWnd, message, wParam, lParam);
  185.            }
  186.        }
  187.        break;
  188.    case WM_PAINT:
  189.        {
  190.            PAINTSTRUCT ps;
  191.            HDC hdc = BeginPaint(hWnd, &ps);
  192.            // TODO: Agregar cualquier código de dibujo que use hDC aquí...
  193.            EndPaint(hWnd, &ps);
  194.        }
  195.        break;
  196.    case WM_DESTROY:
  197.        PostQuitMessage(0);
  198.        break;
  199.    default:
  200.        return DefWindowProc(hWnd, message, wParam, lParam);
  201.    }
  202.    return 0;
  203. }
  204.  
  205. // Controlador de mensajes del cuadro Acerca de.
  206. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  207. {
  208.    UNREFERENCED_PARAMETER(lParam);
  209.    switch (message)
  210.    {
  211.    case WM_INITDIALOG:
  212.        return (INT_PTR)TRUE;
  213.  
  214.    case WM_COMMAND:
  215.        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  216.        {
  217.            EndDialog(hDlg, LOWORD(wParam));
  218.            return (INT_PTR)TRUE;
  219.        }
  220.        break;
  221.    }
  222.    return (INT_PTR)FALSE;
  223. }

Ahora mismo, debo introducir comandos a los botones y no tengo idea como hacerlo.

En el botón Abrir:
Código
  1. mciSendString("set CDAudio door open", rt, 127, IntPtr::Zero);


En el botón Cerrar:

Código
  1. mciSendString("set CDAudio door closed", rt, 127, IntPtr::Zero);


Si todo marcha bien, habremos acabado.
« Última modificación: 9 Abril 2018, 17:52 pm por Meta » En línea

Meta


Desconectado Desconectado

Mensajes: 3.438



Ver Perfil WWW
Re: ¿Cómo añadir dos botones al formulario?
« Respuesta #25 en: 10 Abril 2018, 16:33 pm »

Gracias.

He puesto este código. Lee los mensajes si o si de forma muy correcta. Probé este código de abajo para abrir la bandeja y da error al compilar.
Código:
// #################################################################### Begin.
case IDC_BUTTON_1:
// MessageBox(hWnd, L"Botón 1 pulsado", L"Ejemplo", MB_OK | MB_ICONINFORMATION);
// Mostrar mensaje.
SetWindowText(GetDlgItem(hWnd, IDC_STATIC_1), L"Abriendo...  ");

// Abrir bandeja del lector.
mciSendString("set CDAudio door open", nullptr, 0, nullptr);

// Mostrar mensaje Abierto. Que es cuando ya finalizó.
SetWindowText(GetDlgItem(hWnd, IDC_STATIC_1), L"Abierto.     ");
break;
case IDC_BUTTON_2:
// Mostrar mensaje.
SetWindowText(GetDlgItem(hWnd, IDC_STATIC_1), L"Cerrando...  ");
// Cerrar bandeja del lector.
// mciSendString("set CDAudio closed open", nullptr, 0, nullptr);
// Mostrar mensaje.
SetWindowText(GetDlgItem(hWnd, IDC_STATIC_1), L"Cerrado.     ");
break;
// #################################################################### End.

Errores:
Gravedad   Código   Descripción   Proyecto   Archivo   Línea   Estado suprimido
Error (activo)   E0167   un argumento de tipo "const char *" no es compatible con un parámetro de tipo "LPCWSTR"   Bandeja_Form_Win32_cpp   c:\Users\usuario\Documents\Visual Studio 2017\Projects\Bandeja_Form_Win32_cpp\Bandeja_Form_Win32_cpp\Bandeja_Form_Win32_cpp.cpp   201   


Gravedad   Código   Descripción   Proyecto   Archivo   Línea   Estado suprimido
Error   C2664   'MCIERROR mciSendStringW(LPCWSTR,LPWSTR,UINT,HWND)': el argumento 1 no puede convertirse de 'const char [22]' a 'LPCWSTR'   Bandeja_Form_Win32_cpp   c:\users\usuario\documents\visual studio 2017\projects\bandeja_form_win32_cpp\bandeja_form_win32_cpp\bandeja_form_win32_cpp.cpp   201
En línea

Meta


Desconectado Desconectado

Mensajes: 3.438



Ver Perfil WWW
Re: ¿Cómo añadir dos botones al formulario?
« Respuesta #26 en: 10 Abril 2018, 21:04 pm »

Buenas:

Ya funciona al 100 %. Solo falta pulir algunas cosas como iniciar el formulario en el centro de la pantalla y cambiar el tamaño del texto de la etiqueta STATIC.

Dejo el código completo aquí por si alguien lo necesita o solo le pica la curiosidad.

Código
  1. #include "stdafx.h"
  2. #include "Bandeja_Form_Win32_cpp.h"
  3. #include "mmsystem.h" // No olvidar.
  4.  
  5. #define MAX_LOADSTRING 100
  6. #define IDC_BUTTON_1 201 // No olvidar.
  7. #define IDC_BUTTON_2 202 // No olvidar.
  8. #define IDC_STATIC_1 303 // No olvidar.
  9.  
  10. // Variables globales:
  11. HINSTANCE hInst;                                // Instancia actual
  12. WCHAR szTitle[MAX_LOADSTRING];                  // Texto de la barra de título
  13. WCHAR szWindowClass[MAX_LOADSTRING];            // nombre de clase de la ventana principal
  14.  
  15. // Declaraciones de funciones adelantadas incluidas en este módulo de código:
  16. ATOM                MyRegisterClass(HINSTANCE hInstance);
  17. BOOL                InitInstance(HINSTANCE, int);
  18. LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  19. INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  20.  
  21. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  22.                     _In_opt_ HINSTANCE hPrevInstance,
  23.                     _In_ LPWSTR    lpCmdLine,
  24.                     _In_ int       nCmdShow)
  25. {
  26.    UNREFERENCED_PARAMETER(hPrevInstance);
  27.    UNREFERENCED_PARAMETER(lpCmdLine);
  28.  
  29.    // TODO: colocar código aquí.
  30.  
  31.    // Inicializar cadenas globales
  32.    LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  33.    LoadStringW(hInstance, IDC_BANDEJAFORMWIN32CPP, szWindowClass, MAX_LOADSTRING);
  34.    MyRegisterClass(hInstance);
  35.  
  36.    // Realizar la inicialización de la aplicación:
  37.    if (!InitInstance (hInstance, nCmdShow))
  38.    {
  39.        return FALSE;
  40.    }
  41.  
  42.    HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_BANDEJAFORMWIN32CPP));
  43.  
  44.    MSG msg;
  45.  
  46.    // Bucle principal de mensajes:
  47.    while (GetMessage(&msg, nullptr, 0, 0))
  48.    {
  49.        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  50.        {
  51.            TranslateMessage(&msg);
  52.            DispatchMessage(&msg);
  53.        }
  54.    }
  55.  
  56.    return (int) msg.wParam;
  57. }
  58.  
  59.  
  60.  
  61. //
  62. //  FUNCIÓN: MyRegisterClass()
  63. //
  64. //  PROPÓSITO: registrar la clase de ventana.
  65. //
  66. ATOM MyRegisterClass(HINSTANCE hInstance)
  67. {
  68.    WNDCLASSEXW wcex;
  69.  
  70.    wcex.cbSize = sizeof(WNDCLASSEX);
  71.  
  72.    wcex.style          = CS_HREDRAW | CS_VREDRAW;
  73.    wcex.lpfnWndProc    = WndProc;
  74.    wcex.cbClsExtra     = 0;
  75.    wcex.cbWndExtra     = 0;
  76.    wcex.hInstance      = hInstance;
  77.    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_BANDEJAFORMWIN32CPP));
  78.    wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
  79.    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  80.    wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_BANDEJAFORMWIN32CPP);
  81.    wcex.lpszClassName  = szWindowClass;
  82.    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  83.  
  84.    return RegisterClassExW(&wcex);
  85. }
  86.  
  87. //
  88. //   FUNCIÓN: InitInstance(HINSTANCE, int)
  89. //
  90. //   PROPÓSITO: guardar el identificador de instancia y crear la ventana principal
  91. //
  92. //   COMENTARIOS:
  93. //
  94. //        En esta función, se guarda el identificador de instancia en una variable común y
  95. //        se crea y muestra la ventana principal del programa.
  96. //
  97. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  98. {
  99.   hInst = hInstance; // Almacenar identificador de instancia en una variable global
  100.  
  101.   // ################################################################### Begin.
  102.   // Redimensionar formulario a 300 x 300.
  103.   HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  104.      CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, nullptr, nullptr, hInstance, nullptr);
  105.   // #################################################################### End.
  106.  
  107.   if (!hWnd)
  108.   {
  109.      return FALSE;
  110.   }
  111.  
  112.   ShowWindow(hWnd, nCmdShow);
  113.   UpdateWindow(hWnd);
  114.  
  115.   return TRUE;
  116. }
  117.  
  118. //
  119. //  FUNCIÓN: WndProc(HWND, UINT, WPARAM, LPARAM)
  120. //
  121. //  PROPÓSITO:  procesar mensajes de la ventana principal.
  122. //
  123. //  WM_COMMAND  - procesar el menú de aplicaciones
  124. //  WM_PAINT    - Pintar la ventana principal
  125. //  WM_DESTROY  - publicar un mensaje de salida y volver
  126. //
  127. //
  128. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  129. {
  130.    switch (message)
  131.    {
  132. // ################################################################### Begin.
  133. // Crear botones Abrir, Cerrar y mostrar mensajes.
  134. case WM_CREATE:
  135. {
  136. HWND btnOK = CreateWindowW(
  137. L"BUTTON", // Clase del control.
  138. L"Abrir", // Etiqueta del botón.
  139. WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, // Estilo del control. La clase button puede ser checkbox, radio, etc.
  140. 45, 135, // Posición respecto del client area del parent.
  141. 75, 23, // Dimensiones del control.
  142. hWnd, // --> Este es el handle de la ventana principal.
  143. (HMENU)201, // Este es el identificador del control. De modo predefinido 1 = IDOK, 2 = IDCANCEL
  144. hInst,
  145. nullptr);
  146.  
  147. HWND btnOK2 = CreateWindowW(
  148. L"BUTTON", // Clase del control.
  149. L"Cerrar", // Etiqueta del botón.
  150. WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, // Estilo del control. La clase button puede ser checkbox, radio, etc.
  151. 165, 135, // Posición respecto del client area del parent.
  152. 75, 23, // Dimensiones del control.
  153. hWnd, // --> Este es el handle de la ventana principal.
  154. (HMENU)202, // Este es el identificador del control. De modo predefinido 1 = IDOK, 2 = IDCANCEL
  155. hInst,
  156. nullptr);
  157.  
  158. // Label o etiqueta.
  159. HWND edit = CreateWindowW(
  160. L"STATIC", // Clase del control.
  161. L"Hola.", // Etiqueta del botón.
  162. WS_CHILD | SS_SIMPLE | WS_VISIBLE, // Estilo del control. La clase button puede ser checkbox, radio, etc.
  163. 125, 55, // Posición respecto del client area del parent.
  164. 75, 23, // Dimensiones del control.
  165. hWnd, // --> Este es el handle de la ventana principal.
  166. (HMENU)303, // Este es el identificador del control. De modo predefinido 1 = IDOK, 2 = IDCANCEL
  167. hInst,
  168. nullptr);
  169. }
  170.  
  171. break;
  172. // #################################################################### End.
  173.  
  174.    case WM_COMMAND:
  175.        {
  176.            int wmId = LOWORD(wParam);
  177.            // Analizar las selecciones de menú:
  178.            switch (wmId)
  179.            {
  180. // #################################################################### Begin.
  181. case IDC_BUTTON_1:
  182. // MessageBox(hWnd, L"Botón 1 pulsado", L"Ejemplo", MB_OK | MB_ICONINFORMATION);
  183. // Mostrar mensaje.
  184. SetWindowText(GetDlgItem(hWnd, IDC_STATIC_1), L"Abriendo...  ");
  185.  
  186. // Abrir bandeja del lector.
  187. mciSendString(L"set CDAudio door open", nullptr, 0, nullptr);
  188.  
  189. // Mostrar mensaje Abierto. Que es cuando ya finalizó.
  190. SetWindowText(GetDlgItem(hWnd, IDC_STATIC_1), L"Abierto.     ");
  191. break;
  192. case IDC_BUTTON_2:
  193. // Mostrar mensaje.
  194. SetWindowText(GetDlgItem(hWnd, IDC_STATIC_1), L"Cerrando...  ");
  195. // Cerrar bandeja del lector.
  196. mciSendString(L"set CDAudio door closed", nullptr, 0, nullptr);
  197. // Mostrar mensaje.
  198. SetWindowText(GetDlgItem(hWnd, IDC_STATIC_1), L"Cerrado.     ");
  199. break;
  200. // #################################################################### End.
  201.            case IDM_ABOUT:
  202.                DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  203.                break;
  204.            case IDM_EXIT:
  205.                DestroyWindow(hWnd);
  206.                break;
  207.            default:
  208.                return DefWindowProc(hWnd, message, wParam, lParam);
  209.            }
  210.        }
  211.        break;
  212.    case WM_PAINT:
  213.        {
  214.            PAINTSTRUCT ps;
  215.            HDC hdc = BeginPaint(hWnd, &ps);
  216.            // TODO: Agregar cualquier código de dibujo que use hDC aquí...
  217.            EndPaint(hWnd, &ps);
  218.        }
  219.        break;
  220.    case WM_DESTROY:
  221.        PostQuitMessage(0);
  222.        break;
  223.    default:
  224.        return DefWindowProc(hWnd, message, wParam, lParam);
  225.    }
  226.    return 0;
  227. }
  228.  
  229. // Controlador de mensajes del cuadro Acerca de.
  230. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  231. {
  232.    UNREFERENCED_PARAMETER(lParam);
  233.    switch (message)
  234.    {
  235.    case WM_INITDIALOG:
  236.        return (INT_PTR)TRUE;
  237.  
  238.    case WM_COMMAND:
  239.        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  240.        {
  241.            EndDialog(hDlg, LOWORD(wParam));
  242.            return (INT_PTR)TRUE;
  243.        }
  244.        break;
  245.    }
  246.    return (INT_PTR)FALSE;
  247. }

Saludos camaradas. ;)
En línea

Páginas: 1 2 [3] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines