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

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Problema con WINAPI
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Problema con WINAPI  (Leído 3,456 veces)
..:ALT3RD:..

Desconectado Desconectado

Mensajes: 205


C++ Programmer


Ver Perfil
Problema con WINAPI
« en: 25 Agosto 2011, 15:27 pm »

Bueno,

pues hoy empeze con la WINAPI (un rollazo por cierto  :xD) y tengo un error al copilar un sencillo menu en CODE::BLOCKS. No se donde esta el error asi que agradecería que me lo dijesen.

Código:
#include <windows.h>
const int MENSAJE = 1000;
/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "CodeBlocksWindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    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 colour 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 */
           "Pruebas tranquiiilo",       /* 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 */
    ShowWindow (hwnd, nCmdShow);

    /* 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)
{
    switch (message)                  /* handle the messages */
    {
        case WM_CREATE:

        HMENU menu1,menu2;

        menu1= CreateMenu();
        menu2= CreateMenu();

        AppendMenu (menu2, MF_STRING, MENSAJE, "mensaje");

        AppendMenu (menu1, MF_STRING | MF_POPUP| (UINT) menu2, "menu");

        SetMenu (hwnd, menu1);

        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;
}


Ese es el codigo entero, y la parte donde me falla es esta:ç


Código:
   switch (message)                  /* handle the messages */
    {
        case WM_CREATE:

        HMENU menu1,menu2;

        menu1= CreateMenu();
        menu2= CreateMenu();

        AppendMenu (menu2, MF_STRING, MENSAJE, "mensaje");

        AppendMenu (menu1, MF_STRING | MF_POPUP| (UINT) menu2, "menu");

        SetMenu (hwnd, menu1);

        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;


Y la verdad no encuentro el error, espero que vosotros me lo digais. Gracias y Un salu2!


Por cierto el error que me da es este:

Código:
C:\Users\Celia\Pictures\iPod Photo Cache\GUI\main.cpp||In function 'LRESULT WindowProcedure(HWND__*, UINT, WPARAM, LPARAM)':|
C:\Users\Celia\Pictures\iPod Photo Cache\GUI\main.cpp|87|error: invalid conversion from 'const char*' to 'UINT_PTR'|
C:\Users\Celia\Pictures\iPod Photo Cache\GUI\main.cpp|87|error: too few arguments to function 'BOOL AppendMenuA(HMENU__*, UINT, UINT_PTR, const CHAR*)'|
c:\mingw\bin\..\lib\gcc\mingw32\4.5.2\..\..\..\..\include\winuser.h|3462|note: declared here|
||=== Build finished: 3 errors, 0 warnings ===|


« Última modificación: 25 Agosto 2011, 15:37 pm por ..:ALT3RD:.. » En línea

"Mañana sabrás que hoy no sabes nada"
Eternal Idol
Kernel coder
Moderador
***
Desconectado Desconectado

Mensajes: 5.935


Israel nunca torturó niños, ni lo volverá a hacer.


Ver Perfil WWW
Re: Problema con WINAPI
« Respuesta #1 en: 26 Agosto 2011, 13:01 pm »

Aca parece que cambiaste una coma por un or:

AppendMenu (menu1, MF_STRING | MF_POPUP| (UINT) menu2, "menu");

AppendMenu (menu1, MF_STRING | MF_POPUP, (UINT) menu2, "menu");

PD. Lo dice todo en el output del compilador y eso que no sabia cual era la linea 87.


En línea

La economía nunca ha sido libre: o la controla el Estado en beneficio del Pueblo o lo hacen los grandes consorcios en perjuicio de éste.
Juan Domingo Perón
..:ALT3RD:..

Desconectado Desconectado

Mensajes: 205


C++ Programmer


Ver Perfil
Re: Problema con WINAPI
« Respuesta #2 en: 26 Agosto 2011, 13:13 pm »

Vaya error mas tonto, Gracias!  ;D
En línea

"Mañana sabrás que hoy no sabes nada"
Eternal Idol
Kernel coder
Moderador
***
Desconectado Desconectado

Mensajes: 5.935


Israel nunca torturó niños, ni lo volverá a hacer.


Ver Perfil WWW
Re: Problema con WINAPI
« Respuesta #3 en: 26 Agosto 2011, 14:25 pm »

De nadas  ::)
En línea

La economía nunca ha sido libre: o la controla el Estado en beneficio del Pueblo o lo hacen los grandes consorcios en perjuicio de éste.
Juan Domingo Perón
Alien-Z

Desconectado Desconectado

Mensajes: 177


C++ Programmer


Ver Perfil
Re: Problema con WINAPI
« Respuesta #4 en: 26 Agosto 2011, 20:23 pm »

Estoy haciendo un ejemplo similar y ami me da error en esta parte (señalo en rojo):

Citar
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
       case WM_CREATE:
            HMENU menu1 = CreateMenu();
            HMENU menu2 = CreateMenu();
            AppendMenu(menu2, MF_STRING, MN_MENSAJE, "&Mensaje");
            AppendMenu(menu2, MF_STRING, MN_SALIR, "&Salir");
            AppendMenu(menu1, MF_STRING | MF_POPUP, (UINT)menu2, "&MiMenu");
            SetMenu (hwnd, menu1);
            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;
}

Este es el código completo:

Código
  1. #include <windows.h>
  2.  
  3. const int MN_MENSAJE=1025;
  4. const int MN_SALIR=1026;
  5. //poner el nombre que quieran
  6. /*  Declare Windows procedure  */
  7. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  8.  
  9. /*  Make the class name into a global variable  */
  10. char szClassName[ ] = "CodeBlocksWindowsAp p";
  11.  
  12. int WINAPI WinMain (HINSTANCE hThisInstance,
  13.                     HINSTANCE hPrevInstance,
  14.                     LPSTR lpszArgument,
  15.                     int nCmdShow)
  16. {
  17.    HWND hwnd;               /* This is the handle for our window */
  18.    MSG messages;            /* Here messages to the application are saved */
  19.    WNDCLASSEX wincl;        /* Data structure for the windowclass */
  20.  
  21.    /* The Window structure */
  22.    wincl.hInstance = hThisInstance;
  23.    wincl.lpszClassName = szClassName;
  24.    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
  25.    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
  26.    wincl.cbSize = sizeof (WNDCLASSEX);
  27.  
  28.    /* Use default icon and mouse-pointer */
  29.    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  30.    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  31.    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  32.    wincl.lpszMenuName = NULL;                 /* No menu */
  33.    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
  34.    wincl.cbWndExtra = 0;                      /* structure or the window instance */
  35.    /* Use Windows's default colour as the background of the window */
  36.    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  37.  
  38.    /* Register the window class, and if it fails quit the program */
  39.    if (!RegisterClassEx (&wincl))
  40.        return 0;
  41.  
  42.    /* The class is registered, let's create the program*/
  43.    hwnd = CreateWindowEx (
  44.           0,                   /* Extended possibilites for variation */
  45.           szClassName,         /* Classname */
  46.           "Code::Blocks Template Windows App",       /* Title Text */
  47.           WS_OVERLAPPEDWINDOW, /* default window */
  48.           CW_USEDEFAULT,       /* Windows decides the position */
  49.           CW_USEDEFAULT,       /* where the window ends up on the screen */
  50.           544,                 /* The programs width */
  51.           375,                 /* and height in pixels */
  52.           HWND_DESKTOP,        /* The window is a child-window to desktop */
  53.           NULL,                /* No menu */
  54.           hThisInstance,       /* Program Instance handler */
  55.           NULL                 /* No Window Creation data */
  56.           );
  57.  
  58.    /* Make the window visible on the screen */
  59.    ShowWindow (hwnd, nCmdShow);
  60.  
  61.    /* Run the message loop. It will run until GetMessage() returns 0 */
  62.    while (GetMessage (&messages, NULL, 0, 0))
  63.    {
  64.        /* Translate virtual-key messages into character messages */
  65.        TranslateMessage(&messages);
  66.        /* Send message to WindowProcedure */
  67.        DispatchMessage(&messages);
  68.    }
  69.  
  70.    /* The program return-value is 0 - The value that PostQuitMessage() gave */
  71.    return messages.wParam;
  72. }
  73.  
  74.  
  75. /*  This function is called by the Windows function DispatchMessage()  */
  76.  
  77. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  78. {
  79.    switch (message)                  /* handle the messages */
  80.    {
  81.       case WM_CREATE:
  82.            HMENU menu1 = CreateMenu();
  83.            HMENU menu2 = CreateMenu();
  84.            AppendMenu(menu2, MF_STRING, MN_MENSAJE, "&Mensaje");
  85.            AppendMenu(menu2, MF_STRING, MN_SALIR, "&Salir");
  86.            AppendMenu(menu1, MF_STRING | MF_POPUP, (UINT)menu2, "&MiMenu");
  87.            SetMenu (hwnd, menu1);
  88.            break;
  89.        case WM_DESTROY:
  90.            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
  91.            break;
  92.        default:                      /* for messages that we don't deal with */
  93.            return DefWindowProc (hwnd, message, wParam, lParam);
  94.    }
  95.  
  96.    return 0;
  97. }
  98.  


A ver si alguien puede decirme dónde está el fallo. Saludos.
« Última modificación: 26 Agosto 2011, 20:26 pm por Alien-Z » En línea

Queta

Desconectado Desconectado

Mensajes: 267



Ver Perfil
Re: Problema con WINAPI
« Respuesta #5 en: 26 Agosto 2011, 20:55 pm »

Código
  1. switch(message)
  2. {
  3. case WM_CREATE:
  4. {
  5. HMENU menu1 = CreateMenu();
  6. HMENU menu2 = CreateMenu();
  7.  
  8. AppendMenu(menu2, MF_STRING, MN_MENSAJE, "&Mensaje");
  9.  
  10. AppendMenu(menu2, MF_STRING, MN_SALIR, "&Salir");
  11.  
  12. AppendMenu(menu1, MF_STRING | MF_POPUP, (UINT)menu2, "&MiMenu");
  13.  
  14. SetMenu(hwnd, menu1);
  15.  
  16. break;
  17. }
  18.  
  19. case WM_DESTROY:
  20. PostQuitMessage(0);      
  21.  
  22. break;
  23.  
  24. default:                      
  25. return DefWindowProc(hwnd, message, wParam, lParam);
  26. }

Haz esto.
« Última modificación: 26 Agosto 2011, 20:56 pm por Queta » En línea

"Intenta no volverte un hombre de éxito, sino volverte un hombre de valor." Albert Einstein.
Alien-Z

Desconectado Desconectado

Mensajes: 177


C++ Programmer


Ver Perfil
Re: Problema con WINAPI
« Respuesta #6 en: 26 Agosto 2011, 21:00 pm »

Vaya la leche! las llaves! Es lo que tiene estar concentrado en comprender los nuevos códigos, te acabas olvidando de detalles tontos que has usado 4543 veces.

Gracias Queta. Saludos.
« Última modificación: 26 Agosto 2011, 23:11 pm por Alien-Z » En línea

Queta

Desconectado Desconectado

Mensajes: 267



Ver Perfil
Re: Problema con WINAPI
« Respuesta #7 en: 26 Agosto 2011, 21:35 pm »

De nada. Realmente, switch no necesita llaves, pero sí en este caso en particular.
En línea

"Intenta no volverte un hombre de éxito, sino volverte un hombre de valor." Albert Einstein.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Equivalencia de función WINAPI unsigned int WINAPI myRun en Windows con Ubuntu
Programación C/C++
bertamax 2 2,841 Último mensaje 7 Agosto 2010, 16:27 pm
por bertamax
Problemas con WinApi
Programación C/C++
Nobody12 0 2,936 Último mensaje 10 Enero 2011, 21:47 pm
por Nobody12
Añadir sockets en winapi
Programación C/C++
d00ze13 2 2,583 Último mensaje 30 Noviembre 2011, 20:00 pm
por d00ze13
c++ winapi microfono
Programación C/C++
shiro51 0 1,755 Último mensaje 16 Abril 2013, 01:59 am
por shiro51
[C/C++] WinAPI -> Problema con SetWinEventHook
Programación C/C++
someRandomCode 0 1,358 Último mensaje 7 Noviembre 2014, 15:53 pm
por someRandomCode
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines