• Lunes 6 de Mayo de 2024, 16:29

Autor Tema:  c++ WINAPI  (Leído 1866 veces)

Garethsoul

  • Nuevo Miembro
  • *
  • Mensajes: 13
    • Ver Perfil
c++ WINAPI
« en: Jueves 18 de Febrero de 2010, 16:24 »
0
&PruebaBuenas estoy aprendiendo a crear ventanas en windows usando c++ y las APis de windows pero eh aqui el problema...
El codigo en si dice que no hay problemas que esta todo en orden pero cuando ejecuto el programa no me aparece el menu... ALGUNA IDEA???

MAIN.cpp
Código: C++
  1. #include <windows.h>
  2. #include "ids.h"
  3.  
  4.  
  5. LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM); // Esto es una funcion
  6. void InsertarMenu(HWND);
  7.  
  8. int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevinstance,
  9.         LPSTR lpszCmdParam, int nCmdShow) {
  10.  
  11.     HWND ventana;//manipulador para la ventana principal de la aplicacion
  12.     MSG mensaje; // es una VARIABLE para manipular los mensajes que lleguen a nuestra aplicacion
  13.     WNDCLASSEX wincl; // declaramos la estructura wincl para registrar la clase particular de ventana a usar
  14.     HMENU hMenu;
  15.  
  16.  
  17.  
  18.  
  19.  
  20.     wincl.hInstance = hThisInstance;
  21.     wincl.lpszClassName = "Mi_clase";
  22.     wincl.lpfnWndProc = WindowProcedure;
  23.     wincl.style = CS_DBLCLKS;
  24.     wincl.cbSize = sizeof(wincl);
  25.     //wincl.lpszMenuName = "MenuID";
  26.  
  27.     //usar icono y puntero por defecto
  28.  
  29.     wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  30.     wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  31.     wincl.hCursor = LoadIcon(NULL, IDC_ARROW);
  32.     wincl.lpszMenuName = NULL;
  33.     wincl.cbClsExtra = 0;
  34.     wincl.cbWndExtra = 0;
  35.     wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  36.  
  37.     //registrar la clase de hwnd si falla salir del programa
  38.     if(!RegisterClassEx(&wincl)) return 0;
  39.  
  40.     ventana = CreateWindowEx(
  41.             0,
  42.             "Mi_clase",
  43.             "Ejemplo 01",
  44.             WS_OVERLAPPEDWINDOW,
  45.             CW_USEDEFAULT,
  46.             CW_USEDEFAULT,
  47.             544,
  48.             375,
  49.             HWND_DESKTOP,
  50.             NULL,//LoadMenu(hThisInstance,"MenuID"),
  51.             hThisInstance,
  52.             NULL);
  53.  
  54.  
  55.     hMenu = LoadMenu(hThisInstance,"MenuID");
  56.         SetMenu(ventana,hMenu);
  57.  
  58.         ShowWindow(ventana,nCmdShow);
  59.     //Bucle de mensajes
  60.     while(TRUE== GetMessage(&mensaje,NULL,0,0))
  61.     {
  62.         TranslateMessage(&mensaje);
  63.  
  64.         DispatchMessage(&mensaje);
  65.  
  66.     }
  67.  
  68.  
  69.     return mensaje.wParam;
  70. }
  71.  
  72.  
  73.  
  74. LRESULT CALLBACK WindowProcedure(HWND ventana, UINT mensaje,WPARAM wParam,LPARAM lParam){
  75.     switch (mensaje)
  76.     {
  77.     case WM_COMMAND:
  78.         switch(LOWORD(wParam)){
  79.         case CM_PRUEBA:
  80.                     MessageBox(ventana,"Comando: Prueba","Mensaje de Menu",MB_OK);break;
  81.         case CM_DIALOGO:
  82.                     MessageBox(ventana,"Habia una rata llamada ratatouille que era francesa","Mensaje de Menu",MB_OK);break;
  83.         case CM_SALIR:
  84.                     MessageBox(ventana,"Comando: Salir","Mensaje de Menu",MB_OK);break;
  85.                     PostQuitMessage(0); break;
  86.         }
  87.         break;
  88.     case WM_DESTROY:
  89.         PostQuitMessage(0);break;
  90.     default:
  91.         return DefWindowProc(ventana,mensaje,wParam,lParam);
  92.     }
  93.     return 0;
  94. }
  95.  
  96.  

IDS.H
Código: C++
  1.  
  2. #define CM_PRUEBA 100
  3. #define CM_SALIR 101
  4. #define CM_PROBANDO 102
  5. #define CM_DIALOGO 103
  6. #define TEXTO 104
  7.  
  8.  

FICHERO DE RECURSOS WIN002.rc
Código: C++
  1. #include <ids.h>
  2.  
  3. MenuID MENUEX
  4. BEGIN
  5.  POPUP "&Principal"
  6.  BEGIN
  7.   MENUITEM "",   CM_PRUEBA
  8.   MENUITEM "" // MFT_SEPARATOR
  9.   MENUITEM "&Dialogo",   CM_DIALOAGO
  10.   MENUITEM "" // MFT_SEPARATOR
  11.   MENUITEM "&Salir", CM_SALIR
  12.  END
  13.  

desde ya muy agradecido porque desde anteayer que estoy renegando con esto....

Si Creo una funcion
 
Código: C++
  1.  
  2. ....InsertarMenu(ventana);
  3. ShowWindow(ventana,SW_SHOWDEFAULT);...
  4.  


Código: C++
  1.  
  2. void InsertarMenu(HWND ventana){
  3.     HMENU hmenu1, hmenu2;
  4.     hmenu1 = CreateMenu();// manipulador de la barra de menu
  5.     hmenu2 = CreateMenu();//Manipulador para el primer menu pop-up
  6.     AppendMenu(hmenu2,MF_STRING,CM_PRUEBA,"&Prueba"); //1` Item
  7.     AppendMenu(hmenu2,MF_SEPARATOR,0,NULL);//2` item como en el tercer espacio hay un 0. este separa
  8.     AppendMenu(hmenu2,MF_STRING,CM_DIALOGO,"&Dialogo");
  9.     AppendMenu(hmenu2,MF_SEPARATOR,0,NULL);
  10.     AppendMenu(hmenu2,MF_STRING,CM_SALIR,"&Salir"); //3` item
  11.     AppendMenu(hmenu1,MF_STRING | MF_POPUP, (UINT)hmenu2,"&Principal");
  12.     SetMenu(ventana,hmenu1); //asigna el menu a la ventana ventana
  13. }
  14.  
  15.  
  16.  

me anda joya PERO quiero aprender a crear menus de la otra forma que es mas facil y aparte lo puedo separar en otro fichero

GRACIAS