Some confusion with resources.

This is a discussion on Some confusion with resources. within the C++ Programming forums, part of the General Programming Boards category; Having a few problems with resources. Im just getting the basics on Windows programming and I want to get the ...

  1. #1
    *s*T*i*X*
    Join Date
    Jul 2005
    Location
    LA
    Posts
    2

    Some confusion with resources.

    Having a few problems with resources. Im just getting the basics on Windows programming and I want to get the resources to work to see if im understand this any better. I have some code below, and a compiler error. I was hoping anyone could tell me how to fix this, or help in fixing it? Example :

    Code:
    #include <windows.h>
    #include "resources.h"
    #include "resources.rc"
    
    
    const char gzWindow[] = "WinApp";
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
            switch(msg)
            {
             case WM_LBUTTONDOWN:
             {
                  char szFileName[MAX_PATH];
                  HINSTANCE hInstance = GetModuleHandle(NULL);
                  
                  GetModuleFileName(hInstance, szFileName, MAX_PATH);
                  MessageBox(hwnd, szFileName, "This program is: ", MB_OK | MB_ICONINFORMATION);
                  }
             break;
             case WM_RBUTTONDOWN:
             {
                  char szFname[MAX_PATH];
                  HINSTANCE hInstance = GetModuleHandle(NULL);
                  
                  GetModuleFileName(hInstance, szFname, MAX_PATH);
                  MessageBox(hwnd, szFname, "This program is: ", MB_OK | MB_ICONINFORMATION);
                  }
             break;
             case WM_CLOSE:
             DestroyWindow(hwnd);
             break;
             case WM_DESTROY:
             PostQuitMessage(0);
             break;
             default:
                     return DefWindowProc(hwnd, msg, wParam, lParam);
                     }
                     return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
     LPSTR lpCmdLine, int nCmdShow)
     {
           WNDCLASSEX wc;
           HWND hwnd;
           MSG Msg;
           
           wc.cbSize = sizeof(WNDCLASSEX);
           wc.style = 0;
           wc.hInstance = hInstance;
           wc.lpfnWndProc = WndProc;
           wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
           wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
           wc.hCursor = LoadCursor(NULL, IDC_ARROW);
           wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
           wc.cbClsExtra = 0;
           wc.cbWndExtra = 0;
           wc.lpszMenuName = LoadMenu(hInstance,    MAKEINTRESOURCE(IDR_MYMENU)); // is this right?
           wc.lpszClassName = gzWindow;
           
           if (!RegisterClassEx(&wc))
           {
             MessageBox(NULL, "windows reg error", "win reg error",
             MB_OK | MB_ICONEXCLAMATION);
             return 0;
             }
             
             hwnd = CreateWindowEx(
             WS_EX_CLIENTEDGE,
             gzWindow,
             "Test",
             WS_OVERLAPPEDWINDOW,
             CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
             NULL, NULL, hInstance, NULL);
             
             if (hwnd == NULL)
             {
               MessageBox(NULL, "wincreate error", "wincreate error",
               MB_OK | MB_ICONEXCLAMATION);
               return 0;
               }
             ShowWindow(hwnd, nCmdShow);
             UpdateWindow(hwnd);
             
             while(GetMessage(&Msg, NULL, 0, 0) > 0)
             {
               TranslateMessage(&Msg);
               DispatchMessage(&Msg);
               }
               return Msg.wParam;
    }
    I have the resource info below also, but im wondering where should I declare my menu itself in there, if where I have it is not correct also.

    I also get a 'gzWindow undeclared', error, when it's obvious it's declared as a constant global at the begining of the program.
    And a 'IDR_MYMENU', undeclared when it is included at the begnning of the program in "resources.rc", also.

    Code:
    #include "resources.h"
    
    IDR_MYMENU MENU
    BEGIN
        POPUP "&FILE!"
        BEGIN
           MENUITEM "C&LOSE!", ID_FILE_EXIT
        END
    END
    And that's my resource file, but I also get a compiler error saying that 'IDR_MYMENU', does not name a type.

    And that's about it, (I hope someone even felt like reading this :P)
    if you can take some time, to glance through it and explain where I went wrong, and how to fix it id be very appreciated. Thanks, Hitachi.

  2. #2
    *this
    Join Date
    Mar 2005
    Posts
    498
    Post this in the windows forum, this isnt c++

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Resources in Dev C++
    By JJFMJR in forum Windows Programming
    Replies: 7
    Last Post: 08-27-2007, 05:14 AM
  2. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 04:35 PM
  3. accessing a DLL's resources...
    By dug in forum Windows Programming
    Replies: 9
    Last Post: 12-13-2005, 04:04 AM
  4. Storing resources into a single file
    By LuckY in forum Game Programming
    Replies: 20
    Last Post: 08-14-2004, 11:28 PM
  5. Adding resources
    By nima_ranjbar in forum Windows Programming
    Replies: 0
    Last Post: 04-14-2002, 11:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21