choseone
Desconectado
Mensajes: 29
|
Hola, tengo un problema, no se me ven los menus en las aplicaciones. Este es uno de los códigos, los archivos son main.cpp, ids.h y ListBox.rc:
main.cpp:
#include <windows.h> #include "ids.h"
/* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); BOOL CALLBACK DlgProc (HWND, UINT, WPARAM, LPARAM);
struct stDatos { char Item[80]; };
/* 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 */ "ListBox", /* 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) { HINSTANCE hInstance; static stDatos Datos; switch (message) /* handle the messages */ { case WM_CREATE: hInstance = ((LPCREATESTRUCT)lParam)->hInstance; //Inicializacion de los datos en la aplicacion strcpy (Datos.Item, "Cadena Nº 3"); return 0; case WM_COMMAND: switch (LOWORD(wParam)) { case CM_DIALOGO: DialogBoxParam(hInstance, "Dialogo", hwnd, DlgProc, (LPARAM)&Datos); MessageBox(hwnd, "Anda", "Anda", MB_OK); } 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) { static stDatos *Datos; UINT indice; switch(msg) { case WM_INITDIALOG: Datos = (stDatos *) lParam; //Añadir cadena, Mensaje LB_ADDSTRING SendDlgItemMessage(hDlg, ID_LISTA, LB_ADDSTRING, 0, (LPARAM)"Cadena Nº 1"); SendDlgItemMessage(hDlg, ID_LISTA, LB_ADDSTRING, 0, (LPARAM)"Cadena Nº 4"); SendDlgItemMessage(hDlg, ID_LISTA, LB_ADDSTRING, 0, (LPARAM)"Cadena Nº 3"); SendDlgItemMessage(hDlg, ID_LISTA, LB_ADDSTRING, 0, (LPARAM)"Cadena Nº 2"); SendDlgItemMessage(hDlg, ID_LISTA, LB_SELECTSTRING, (UINT)-1, (LPARAM)Datos->Item); SetFocus(GetDlgItem(hDlg, ID_LISTA)); return FALSE; case WM_COMMAND: switch(LOWORD(wParam)) { case IDOK: indice = SendDlgItemMessage(hDlg, ID_LISTA, LB_GETCURSEL, 0, 0); SendDlgItemMessage(hDlg, ID_LISTA, LB_GETTEXT, indice, (LPARAM)Datos->Item); EndDialog(hDlg, FALSE); break; case IDCANCEL: EndDialog(hDlg, FALSE); break; } return TRUE; } }
ids.h:
#define CM_DIALOGO 100 #define ID_LISTA 101 #define Menu 102 #define Dialogo 103
ListBox.rc:
#include <windows.h> #include "ids.h"
Menu MENU BEGIN POPUP "&Principal" BEGIN MENUITEM "&Dialogo", CM_DIALOGO END END
Dialogo DIALOG 0, 0, 118, 136 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION CAPTION "Dialogo de prueba" FONT 8, "Helv" BEGIN CONTROL "Lista:", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 8, 9, 28, 8 CONTROL "", ID_LISTA, "LISTBOX", LBS_STANDARD | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 9, 19, 104, 99 CONTROL "Aceptar", IDOK, "BUTTON", BS_DEFPUSHBUTTON | BS_CENTER | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 8, 116, 45, 14 CONTROL "Cancelar", IDCANCEL, "BUTTON", BS_PUSHBUTTON | BS_CENTER | WS_CHILD |WS_VISIBLE | WS_TABSTOP, 61, 116, 45, 14 END
Podrían decirme qué tengo mal en el código que no me muestra el menú, aparte no me tira ningún error, así que si me lo pueden solucionar se los agradecería mucho y sino grax por intentarlo.
|