Dodanie menu

0

Chce dodać menu. Jednak mam błędy dopiero zaczynam więc proszę o pomoc :) Nie wiem gdzie mam włożyć menu.

'Nazwa_menu' dosean`t a type

#include <windows.h>


/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  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_WINLOGO);
    wincl.hCursor = LoadCursor (NULL, IDC_HAND);
    wincl.lpszMenuName = "Nazwa_menu";                 /* 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 */
           "Windows App",       /* 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, nFunsterStil);

    /* 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);
    }
    
    
    
    
  INT a;
  a=MessageBox(HWND_DESKTOP,"Jaki przycisk chcesz nacisnąć?",":>",MB_YESNOCANCEL|MB_ICONQUESTION);
  if(a==6) MessageBox(HWND_DESKTOP,"Nacisnąłeś przycisk TAK","Tak",MB_OK);
  if(a==7) MessageBox(HWND_DESKTOP,"Nacisnąłeś przycisk NIE","Nie",MB_OK);
  if(a==2) MessageBox(HWND_DESKTOP,"Nacisnąłeś przycisk ANULUJ","Anuluj",MB_OK); /* 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_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;
}


   Nazwa_menu MENU
   
      {
  
      POPUP "File"
  
      {
   
      MENUITEM "E&xit", 1
  
      }
 
      POPUP "Help"
 
      {
  
      MENUITEM "&About", 2
  
      }
 
      }

Gdzie powinienem włożyć to?

Nazwa_menu MENU
   
      {
  
      POPUP "File"
  
      {
   
      MENUITEM "E&xit", 1
  
      }
 
      POPUP "Help"
 
      {
  
      MENUITEM "&About", 2
  
      }
 
      }
0

musisz to umieścić w pliku z zasobami (rozszerzenie *.rc) w twoim projekcie...

0
nobody napisał(a)

musisz to umieścić w pliku z zasobami (rozszerzenie *.rc) w twoim projekcie...

Ten sam błąd :)

#include <windows.h>
#include "cos.rc"  
   

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  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_WINLOGO);
    wincl.hCursor = LoadCursor (NULL, IDC_HAND);
    wincl.lpszMenuName = "Nazwa_menu";                 /* 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 */
           "Windows App",       /* 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, nFunsterStil);

    /* 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);
    }
    
    
    
    
  INT a;
  a=MessageBox(HWND_DESKTOP,"Jaki przycisk chcesz nacisnąć?",":>",MB_YESNOCANCEL|MB_ICONQUESTION);
  if(a==6) MessageBox(HWND_DESKTOP,"Nacisnąłeś przycisk TAK","Tak",MB_OK);
  if(a==7) MessageBox(HWND_DESKTOP,"Nacisnąłeś przycisk NIE","Nie",MB_OK);
  if(a==2) MessageBox(HWND_DESKTOP,"Nacisnąłeś przycisk ANULUJ","Anuluj",MB_OK); /* 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_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;
}

Tutaj cos.rc


   Nazwa_menu MENU
   
      {
  
      POPUP "File"
  
      {
   
      MENUITEM "E&xit", 1
  
      }
 
      POPUP "Help"
 
      {
  
      MENUITEM "&About", 2
  
      }
 
      }

In file included from main.cpp

'Nazwa_menu' does not name a type

[Build Error] [main.o] error 1

0

To co trzeba zrobić by menu działało pod dev?

0

o.0
wy*eb to: #include "cos.rc" z kodu cpp
dołączając go z powrotem to tak jakbyś nic nie zrobił...

0

Mam już dział :D

#include <windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void AddMenus(HWND);

#define IDM_FILE_NEW 1
#define IDM_FILE_OPEN 2
#define IDM_FILE_QUIT 3

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
			LPSTR lpCmdLine, int nCmdShow )
{
  MSG  msg ;    
  WNDCLASS wc = {0};
  wc.lpszClassName = "Menu" ;
  wc.hInstance     = hInstance ;
  wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  wc.lpfnWndProc   = WndProc ;
  wc.hCursor       = LoadCursor(0, IDC_ARROW);
 
  RegisterClass(&wc);
  CreateWindow( wc.lpszClassName, "Menu",
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                100, 100, 200, 150, 0, 0, hInstance, 0);  

  while( GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return (int) msg.wParam;
}

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{   
  switch(msg)  
  {
      case WM_CREATE:
          AddMenus(hwnd);
          break;
    
      case WM_COMMAND:
          switch(LOWORD(wParam)) {
              case IDM_FILE_NEW:
              case IDM_FILE_OPEN:
                  Beep(50, 100);
                  break;
              case IDM_FILE_QUIT:
                  SendMessage(hwnd, WM_CLOSE, 0, 0);
                  break;
           }
           break;

      case WM_DESTROY:
          PostQuitMessage(0);
          break;

  }
  return DefWindowProc(hwnd, msg, wParam, lParam);
}


void AddMenus(HWND hwnd) {
  HMENU hMenubar;
  HMENU hMenu;

  hMenubar = CreateMenu();
  hMenu = CreateMenu();

  AppendMenu(hMenu, MF_STRING, IDM_FILE_NEW, "&New");
  AppendMenu(hMenu, MF_STRING, IDM_FILE_OPEN, "&Open");
  AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
  AppendMenu(hMenu, MF_STRING, IDM_FILE_QUIT, "&Quit");

  AppendMenu(hMenubar, MF_POPUP, (UINT_PTR)hMenu, "&File");
  SetMenu(hwnd, hMenubar);
}
0

można i w te strone..

1 użytkowników online, w tym zalogowanych: 0, gości: 1