|
422
|
Programación / Programación C/C++ / Re: ¿Cómo añadir dos botones al formulario?
|
en: 7 Abril 2018, 18:46 pm
|
Buenas: Me alegro que ya se pueda ver als capturas de pantalla. En todo el proyecto he encontrado el código para redimensionar la ventana aquí. HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
Pisiste el enlace, pero no se parece nada para modificar las coordenadas X, Y, así pongo los valores a 300 x 300. Dios mio, si que es complicado el santo formulario con el Win32. En el ejemplo que diste: HWND hwndButton = CreateWindow( L"BUTTON", // Predefined class; Unicode assumed L"OK", // Button text WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // Styles 10, // x position 10, // y position 100, // Button width 100, // Button height m_hwnd, // Parent window NULL, // No menu. (HINSTANCE)GetWindowLong(m_hwnd, GWL_HINSTANCE), NULL); // Pointer not needed.
Es todo un reto. Saludos.
|
|
|
424
|
Programación / Programación C/C++ / [SOLUCIONADO] ¿Cómo añadir dos botones al formulario?
|
en: 7 Abril 2018, 17:49 pm
|
Hola: He creado un formulario con Windows Form (Win32). Quiero añadir en él dos botones. Por ahora he hecho esto. Paso 1: Paso 2: Pado 3: Se me genera códigos pero no se ve el formulario. Lo que demuestra se un engorro programar así hoy en día, pero hay empresas que si programan así y enseñan en algunas universidades les gusten a los alumnos o no. Paso 4: Aquí lo dejo el formulario como si fuese por defeto 300x300 pero en realidad es muy grande para mi gusto. Quiero hacer dos cosas. Poner el tamaño del formulario a 300 x 300 y introducir 2 botones. Quiero hacer. Un botón se llama: Abrir y el otro Cerrar. ¿Cómo se hace? Saludos. PD: La verdad, no sabía que fuera tan coñazo, pesado, complicado en hacer lo que estoy pidiendo.
|
|
|
425
|
Programación / Programación C/C++ / Re: Corregir este error con Win32
|
en: 7 Abril 2018, 17:44 pm
|
#define _CRT_SECURE_NO_WARNINGS #include "stdafx.h" #include <stdio.h> #include <string.h> int i; int main() { int a = 0; char b[] = "\0"; int c = 0; for (i = 0; i<10; ++i) { strcat(b, "a"); printf("b = %s\n", b); printf("a = %d\nc = %d\n\n", a, c); } //return 0; }
Gravedad Código Descripción Proyecto Archivo Línea Estado suprimido Advertencia C4603 '_CRT_SECURE_NO_WARNINGS': no se ha definido la macro o la definición es diferente después del uso del encabezado precompilado EfectosDesbordamientoBuffer_Consola_Win32 c:\users\usuario\documents\visual studio 2017\projects\efectosdesbordamientobuffer_consola_win32\efectosdesbordamientobuffer_consola_win32\efectosdesbordamientobuffer_consola_win32.cpp 4
Gravedad Código Descripción Proyecto Archivo Línea Estado suprimido Error C4996 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. EfectosDesbordamientoBuffer_Consola_Win32 c:\users\usuario\documents\visual studio 2017\projects\efectosdesbordamientobuffer_consola_win32\efectosdesbordamientobuffer_consola_win32\efectosdesbordamientobuffer_consola_win32.cpp 18
|
|
|
426
|
Programación / Programación C/C++ / Re: Corregir este error con Win32
|
en: 7 Abril 2018, 15:59 pm
|
#include "stdafx.h" #include <stdio.h> #include <string.h> #define _CRT_SECURE_NO_WARNINGS int i; int main() { int a = 0; char b[] = "\0"; int c = 0; for (i = 0; i<10; ++i) { strcat(b, "a"); printf("b = %s\n", b); printf("a = %d\nc = %d\n\n", a, c); } //return 0; }
Gravedad Código Descripción Proyecto Archivo Línea Estado suprimido Error C4996 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. EfectosDesbordamientoBuffer_Consola_Win32 c:\users\usuario\documents\visual studio 2017\projects\efectosdesbordamientobuffer_consola_win32\efectosdesbordamientobuffer_consola_win32\efectosdesbordamientobuffer_consola_win32.cpp 17
|
|
|
427
|
Programación / Programación C/C++ / Re: Corregir este error con Win32
|
en: 7 Abril 2018, 13:24 pm
|
Me salta esto. Gravedad Código Descripción Proyecto Archivo Línea Estado suprimido Error C4996 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. EfectosDesbordamientoBuffer_Consola_Win32 c:\users\usuario\documents\visual studio 2017\projects\efectosdesbordamientobuffer_consola_win32\efectosdesbordamientobuffer_consola_win32\efectosdesbordamientobuffer_consola_win32.cpp 16
|
|
|
428
|
Programación / Programación C/C++ / Re: Corregir este error con Win32
|
en: 7 Abril 2018, 12:35 pm
|
Buenas: Curiosamente he cerrado Visual Studio, lo volví abrir y ya funciona. No aparece ningún error, el programa funciona al 100 %, puedo abrir y cerrar la bandeja. En cuanto a lo del: char entrada[] = "\0";
No provoca ningún error y funciona de mil maravillas. Aún así te escucho por si acaso. Saludos.
|
|
|
429
|
Programación / Programación C/C++ / Corregir este error con Win32
|
en: 7 Abril 2018, 12:04 pm
|
Hola: He hecho un mini programa que abre y cierra la bandeja del lector. Lo que no entiendo a la hora de ejecutar la aplicación me sale este mensaje de error. Gravedad Código Descripción Proyecto Archivo Línea Estado suprimido Error LNK1104 no se puede abrir el archivo 'C:\Users\Usuario\Documents\Visual Studio 2017\Projects\Bandeja_consola_win32_cpp\Debug\Bandeja_consola_win32_cpp.exe' Bandeja_consola_win32_cpp C:\Users\Meta\Documents\Visual Studio 2017\Projects\Bandeja_consola_win32_cpp\Bandeja_consola_win32_cpp\LINK 1
El código es: #include "stdafx.h" #include "Windows.h" #include "iostream" using namespace std; int main() { // Título de la ventana. SetConsoleTitle(L"Consola C++ Win32 2017"); // Variable. char entrada[] = "\0"; // Guarda A, a, C, y c tipo string que introduces desde la consola. while (true) { // Muestra en pantalla textos. cout << "Control bandeja del lector: " << endl << endl; cout << "A - Abrir bandeja." << endl; cout << "C - Cerrar bandeja." << endl; cout << "==========================" << endl; cin >> entrada; // Aquí introduces letras A, a, C, y c. cout << "\n" << endl; // Abrir bandeja. if ((entrada[0] == 'a') || (entrada[0] == 'A')) { cout << "Abriendo..." << endl << endl; // Muestra en pantalla textos. mciSendString(L"set cdaudio door open", nullptr, 0, nullptr); cout << "Abierto." << endl << endl; // Muestra en pantalla textos. } // Cerrar bandeja. else if ((entrada[0] == 'c') || (entrada[0] == 'C')) { cout << "Cerrando..." << endl << endl; // Muestra en pantalla textos. mciSendString(L"set cdaudio door closed", nullptr, 0, nullptr); cout << "Cerrado." << endl << endl; // Muestra en pantalla textos. } // Si haz pulsado otro caracter distinto de A, C, a, y c aparece else { cout << "Solo pulsar A o C." << endl << endl; // este mensaje. } } return EXIT_SUCCESS; }
Antes me funcionaba, actualizo Visual studio y pasa esto. Saludos.
|
|
|
430
|
Programación / .NET (C#, VB.NET, ASP) / Re: Programas de broma
|
en: 5 Abril 2018, 04:29 am
|
Hola: ¿Qué les parece la broma? Todavía queda mucho que pulir, poco a poco se va ampliando y mejorando. Leer los comentarios para entender el código. using Microsoft.Win32; using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Printing; using System.IO; using System.Runtime.InteropServices; using System.Text; using System.Threading; namespace Broma_Consola_05 { class Program { // Importar dll. // Bandeja o lector o unidad de disco. [DllImport("winmm.dll")] public static extern Int32 mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, IntPtr hwndCallback); public static StringBuilder rt = new StringBuilder (127); // Intercambio de botones del ratón. [DllImport("user32.dll")] static extern bool SwapMouseButton(bool fSwap); // Leds del teclado. [DllImport("user32.dll")] internal static extern short GetKeyState(int keyCode); [DllImport("user32.dll")] static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo); static void Main(string[] args) { // Root. const string userRoot = "HKEY_CURRENT_USER"; // Clave. const string subkey = "Metaconta"; // FullName. const string keyName = userRoot + "\\" + subkey; // ValueName. const string valueName = "Contador"; // Variables txt. string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); // Si no existe la Key, dará -1. int contador = Convert.ToInt32(Registry.GetValue(keyName, valueName, -1) ?? -1); // Comprueba si la key, al ser -1 si la key no existe. if (contador >= 0) { // Si el contador es mayor que 0. if (contador > 0) { // Sobre escribe la key con -1 su valor. Registry.SetValue(keyName, valueName, contador -= 1); } // Escribe un nuevo arhivo de texto con su contenido correspondiente. if (contador == 7) { File.WriteAllText(Path.Combine(path, "Hola.txt"), "Hola amigo."); } // Abrir bandeja del lector. if (contador == 6) { mciSendString("set CDAudio door open", rt, 127, IntPtr.Zero); } // Intercambiar botones del ratón (Diestro). if (contador == 5) { SwapMouseButton(false); // Activar . } // Intercambiar botones del ratón (Zurdo). if (contador == 4) { // Activar modo zurdo. // SwapMouseButton(true); o SwapMouseButton(1); // Para volver a modo diestro. // SwapMouseButton(false); o SwapMouseButton(0); SwapMouseButton(true); // Activar surdo. } // Imprimir un folio de la impresora o ficticia. if (contador == 3) { string amigo = @"Hola amigo."; string folio = @"Solo te he gastado un folio."; PrintDocument p = new PrintDocument (); p.PrintPage += delegate (object sender1, PrintPageEventArgs e1) { e1 .Graphics.DrawString(amigo, new Font ("Times New Roman", 100), new SolidBrush (Color .Black), new RectangleF (30, 100, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height)); e1 .Graphics.DrawString(folio, new Font ("Times New Roman", 12), new SolidBrush (Color .Black), new RectangleF (530, 270, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height)); }; try { p.Print(); } catch (Exception ex) { throw new Exception ("Excepción ocurrida durante la impresión.", ex ); } } // Parpadean los Led del teclado. if (contador == 2) { while (true) { //No se el orden porque no tengo un teclado mecanico para ver los 3 pilotos juntos PressKeyboardButton(VirtualKeyStates.BloqMayus); Thread.Sleep(100); //Ajusta estos tiempos a como te interese PressKeyboardButton(VirtualKeyStates.BloqNum); Thread.Sleep(100); PressKeyboardButton(VirtualKeyStates.BloqDespl); Thread.Sleep(100); } void PressKeyboardButton(VirtualKeyStates keyCode) { const int KEYEVENTF_EXTENDEDKEY = 0x1; const int KEYEVENTF_KEYUP = 0x2; keybd_event((byte)keyCode, 0x45, KEYEVENTF_EXTENDEDKEY, 0); keybd_event((byte)keyCode, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); } } // Crea archivo bat, borra .exe y .cmd. Fin de la broma. if (contador == 1) { try { // Variables. string strFileFullName = @"archivo.cmd"; // Nombre del archivo. //string ruta = Environment.GetFolderPath(Environment.SpecialFolder.Startup); // Ruta en Inico de Windwos. string ruta = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); // Ruta en el inicio de Windows. string ficheroAGrabar = Path.Combine(ruta, strFileFullName); // Concatenar ruta. // Muestra la ruta en pantalla. Console.WriteLine(ruta); // C:\Users\Usuario\Desktop // Si no existe el archivo. if (!File.Exists(ficheroAGrabar)) { // Crea el contenido al archivo de texto. File.WriteAllText(ficheroAGrabar, @"@echo off TIMEOUT /T 1 DEL /S Broma_Consola_05.exe DEL /S archivo.cmd EXIT"); } else // Si existe... { // Codigo a ejecutar si existe... // Console.WriteLine("El archivo existe, así que no se sustituirá."); } // Ejecutar archivo.cmd. ProcessStartInfo psi = new ProcessStartInfo (); psi.UseShellExecute = false; psi.CreateNoWindow = true; psi.WindowStyle = ProcessWindowStyle.Hidden; psi.FileName = strFileFullName; // archivo.cmd. Process.Start(psi); // Cerrar aplicación C#. Environment.Exit(-1); } catch (Win32Exception) { // No mostrar nada. // Cerrar aplicación C#. //Environment.Exit(-1); } } // Entonces. else { // Escribe en el registro el valor. Registry.SetValue(keyName, valueName, 10); } } } public enum VirtualKeyStates : int { BloqMayus = 0x14, // 20 BloqNum = 0x90, //144 BloqDespl = 0x91, //145 } } }
Saludos.
|
|
|
|
|
|
|