elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Ingresar Registrarse
07 Septiembre 2008, 07:11  



+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderador: ®®)
| | |-+  Menus c++
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Imprimir
Autor Tema: Menus c++  (Leído 523 veces)
choseone

Desconectado Desconectado

Mensajes: 29



Ver Perfil
Menus c++
« en: 28 Mayo 2008, 05:11 »

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.
En línea
Rozor

Desconectado Desconectado

Mensajes: 232


As I Walk Through The Valley Of The Shadow Of Dead


Ver Perfil WWW
Re: Menus c++
« Respuesta #1 en: 28 Mayo 2008, 05:22 »

/* No menu */ ¿?


"Menu" o como lo hayas nombrado en el rc
En línea

Suck my Dick!!!
choseone

Desconectado Desconectado

Mensajes: 29



Ver Perfil
Re: Menus c++
« Respuesta #2 en: 30 Mayo 2008, 01:12 »

Lo de /* No menu */ es de la plantilla del programa de windows de Devc++, yo al menú lo puse en donde dice SetMenu(hwnd, LoadMenu(hThisInstance, "Menu")); pero = no me muestra el menú  :( y no se porque no lo muestra.

Ya intenté ponerlo así wincl.lpszMenuName = "Menu"; y así
                                wincl.lpszMenuName = MAKEINTRESOURCE(MENU); (cambiando por supuesto el .rc y el ids.h)

De la única forma en que se mostró el menú fue haciendo una función en main.cpp que inserte el menú de la siguiente manera:

void InsertarMenu(HWND hWnd)
{
HMENU hMenu1, hMenu2;
hMenu1 = CreateMenu(); /* Manipulador de la barra de menú */
hMenu2 = CreateMenu(); /* Manipulador para el primer menú pop-up */

AppendMenu(hMenu2, MF_STRING, CM_DIALOGO2, "&Prueba"); /* 1º ítem */

/*Inserción del menú pop-up */
AppendMenu(hMenu1, MF_STRING | MF_POPUP, (UINT)hMenu2, "&Principal");

SetMenu (hWnd, hMenu1); /* Asigna el menú a la ventana hWnd */
}

Y modifiqué:
  ...
  case WM_COMMAND:
             if(LOWORD(wParam) == CM_DIALOGO2)
             {
                 int ret = DialogBoxParam(hInstance, "Dialogo", hwnd, DlgProc,                  (LPARAM)&Datos);
                     
                 if (ret == -1)
                 {
                     MessageBox(hwnd, "Dialogo fallado", "Error", MB_OK | MB_ICONINFORMATION);
                 }
                 break;
             }
             break;
    ...

Siempre me da error el diálogo, o sea siempre DialogBoxParam me devuelve -1.

Cualquier ayuda  ;D que me puedan dar diganmela por favor..

Saludos.
« Última modificación: 30 Mayo 2008, 01:49 por choseone » En línea
Nakp

Conectado Conectado

Mensajes: 2.688


The sound of music ñ_ñ


Ver Perfil WWW
Re: Menus c++
« Respuesta #3 en: 30 Mayo 2008, 05:57 »

en la instrucción
Código
wincl.lpszMenuName = NULL;

cambia a
Código
wincl.lpszMenuName = "NombredemiMenu";

salu2
En línea



Mi blog

you will love ME ;)
choseone

Desconectado Desconectado

Mensajes: 29



Ver Perfil
Re: Menus c++
« Respuesta #4 en: 31 Mayo 2008, 23:32 »

Ok lo del menú lo entendí, pero porque no me muestra el cuadro de diálogo??

Muchas gracias........
En línea
Páginas: [1] Ir Arriba Imprimir 
Ir a:  







Consolas     La Web de Goku     MilW0rm     MundoDivx

Hispabyte     Truzone     TodoReviews     ZonaPhotoshop

hard-h2o modding    Foros de ayuda    Yashira.org    Videojuegos    indetectables.net   

Noticias Informatica    Seguridad Informática    ADSL    Foros en español    eNYe Sec

Todas las webs afiliadas están libres de publicidad engañosa.

Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC