choseone
Desconectado
Mensajes: 28
|
Este es main.cpp
#include <windows.h> #include <stdio.h> #include "ids.h"
/* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
typedef struct stDatos { int nCadenas; char Lista[MAX_CADENAS][80]; //Valores de los comboboxes char Item[3][80]; //Opciones elegidas };
/* Make the class name into a global variable */ char szClassName[ ] = "WindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{ HWND hwnd; /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default color as the background of the window */ wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)) return 0;
/* The class is registered, let's create the program*/ hwnd = CreateWindowEx ( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ "ComboBox", /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 544, /* The programs width */ 375, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ );
/* Make the window visible on the screen */ SetMenu(hwnd, LoadMenu(hThisInstance, "Menu")); ShowWindow (hwnd, SW_SHOWDEFAULT);
/* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); }
/* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; }
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HINSTANCE hInstance; static stDatos Datos; int i; switch (message) /* handle the messages */ { case WM_CREATE: hInstance = ((LPCREATESTRUCT)lParam)->hInstance; strcpy(Datos.Item[0], "a"); strcpy(Datos.Item[1], "c"); strcpy(Datos.Item[2], "e"); Datos.nCadenas = 6; for (i = 0;i <6; i++) sprintf(Datos.Lista, "&c) Opcion %c", 'a'+ i, 'A' + i); return 0; case WM_COMMAND: switch(LOWORD(wParam)) { case CM_DIALOGO: DialogBox (hInstance, "Dialogo", hwnd, DlgProc); break; } break; case WM_DESTROY: PostQuitMessage (0); /* send a WM_QUIT to the message queue */ break; default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); }
return 0; }
BOOL CALLBACK DlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { int i; static stDatos *Datos; long indice; LPTSTR resultado; switch (msg) { case WM_INITDIALOG: Datos = (stDatos *)lParam; //Añadir cadenas Mensaje CB_ADDSTRING for (i = 0; i < Datos->nCadenas ; i++) { SendDlgItemMessage (hDlg, ID_COMBOBOX1, CB_ADDSTRING, 0, (LPARAM)Datos->Lista); SendDlgItemMessage (hDlg, ID_COMBOBOX2, CB_ADDSTRING, 0, (LPARAM)Datos->Lista); SendDlgItemMessage (hDlg, ID_COMBOBOX3, CB_ADDSTRING, 0, (LPARAM)Datos->Lista); } SendDlgItemMessage (hDlg, ID_COMBOBOX1, CB_SELECTSTRING, (WPARAM)-1, (LPARAM)Datos->Item[0]); SendDlgItemMessage (hDlg, ID_COMBOBOX2, CB_SELECTSTRING, (WPARAM)-1, (LPARAM)Datos->Item[1]); SendDlgItemMessage (hDlg, ID_COMBOBOX3, CB_SELECTSTRING, (WPARAM)-1, (LPARAM)Datos->Item[2]); SetFocus(GetDlgItem(hDlg, ID_COMBOBOX1)); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: //En el combolist simple usaremos GetDlgItemText(hDlg, ID_COMBOBOX1, Datos->Item[0], 80); if (SendDlgItemMessage(hDlg, ID_COMBOBOX1, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)Datos->Item[0]) == CB_ERR) strcpy(Datos->Lista[Datos->nCadenas++], Datos->Item[0]); //En el combolist dropdown usaremos SendDlgItemMessage(hDlg, ID_COMBOBOX2, WM_GETTEXT, 80, (LPARAM)Datos->Item[1]); if(SendDlgItemMessage(hDlg, ID_COMBOBOX1, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)Datos->Item[1]) == CB_ERR && strcmp(Datos->Item[0], Datos->Item[1])) strcpy(Datos->Lista[Datos->nCadenas++], Datos->Item[1]); //En el combolist dropdownlist usaremos indice = SendDlgItemMessage(hDlg, ID_COMBOBOX3, CB_GETCURSEL, 0, 0); SendDlgItemMessage(hDlg, ID_COMBOBOX3, CB_GETLBTEXT, indice, (LPARAM)Datos->Item[2]); wsprintf(resultado, "%s\n%s\n%s", Datos->Item[0], Datos->Item[1], Datos->Item[2]); MessageBox(hDlg, resultado, "Leido", MB_OK); EndDialog(hDlg, FALSE); return TRUE; case IDCANCEL: EndDialog(hDlg, FALSE); return FALSE; } } }
Este es el "ids.h"
#define CM_DIALOGO 104 #define ID_COMBOBOX1 101 #define ID_COMBOBOX2 102 #define ID_COMBOBOX3 103 #define MAX_CADENAS 100 #define Menu 200 #define CM_SALIR 105
Este es el "combo.rc"
#include <windows.h> #include "ids.h"
Menu MENU BEGIN POPUP "&Principal" BEGIN MENUITEM "&Dialogo", CM_DIALOGO MENUITEM "&Salir", CM_SALIR END END
Dialogo DIALOG 0, 0, 205, 78 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_VISIBLE CAPTION "ComboBoxes" FONT 8, "Helv" BEGIN CONTROL "&Simple", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 8, 2, 60, 8 CONTROL "ComboBox1", ID_COMBOBOX1, "COMBOBOX", CBS_SORT | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 8, 13, 60, 43 CONTROL "&DropDown", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 73, 2, 60, 8 CONTROL "ComboBox2", ID_COMBOBOX2, "COMBOBOX", CBS_DROPDOWN | CBS_SORT | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 72, 13, 60, 103 CONTROL "DropDown &List", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 138, 2, 60, 8 CONTROL "ComboBox3", ID_COMBOBOX3, "COMBOBOX", CBS_DROPDOWNLIST | CBS_SORT | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 136, 13, 60, 103 CONTROL "Aceptar", IDOK, "BUTTON", BS_DEFPUSHBUTTON | BS_CENTER | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 28, 60, 50, 14 CONTROL "Cancelar", IDCANCEL, "BUTTON", BS_PUSHBUTTON | BS_CENTER | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 116, 60, 50, 14 END
Si pueden solucionarmelo, muchisimas gracias y sino gracias por intentarlo.
Nos vemos.
|