Results 1 to 8 of 8

Thread: Resource files in C++..

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    I have made a menu bar in a resource file which is called untitled.rc. The name is the Menu is MYMENU. Now I want to use this menu bar in my project. How do do that? I tried to include the following:
    #include <untitled.rc>

    But it does not work. My compiler does not know from which resource file, it is to take the menu "MYmenu"

    Please reply as soon as possible
    Thanks!
    Baaaaaaaaah

  2. #2
    Megatron
    Guest
    Did you add the resource script to your project already? Also, you need to include resource.h.
    Code:
    #include "resource.h"

  3. #3

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    OK HERE YOU GO!

    When I add both the header and resource file, it finds some errors in the resource file. My resource file is this:

    #include <windows.h>
    #include "tut0.h"

    MYMENU MENU
    BEGIN
    POPUP "&File"
    BEGIN
    MENUITEM "E&xit", CM_FILE_EXIT
    END
    POPUP "&Stuff"
    BEGIN
    MENUITEM "&Go", CM_STUFF_GO
    MENUITEM "G&o somewhere else", 0, GRAYED
    END
    END


    The name of my resource file is "tut0.rc"

    My "tut0.h" is this:

    #define CM_FILE_EXIT 9001
    #define CM_STUFF_GO 9002


    My actuall project file is this:

    #include <windows.h>
    #include "tut0.h"
    #include "tut0.rc"
    static char g_szClassName[] = "MyWindowClass";
    static HINSTANCE g_hInst = NULL;

    LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    switch(Message)
    {
    case WM_CLOSE:
    DestroyWindow(hwnd);
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc(hwnd, Message, wParam, lParam);
    }
    return 0;
    }

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
    {
    WNDCLASSEX WndClass;
    HWND hwnd;
    MSG Msg;

    g_hInst = hInstance;

    WndClass.cbSize = sizeof(WNDCLASSEX);
    WndClass.style = NULL;
    WndClass.lpfnWndProc = WndProc;
    WndClass.cbClsExtra = 0;
    WndClass.cbWndExtra = 0;
    WndClass.hInstance = g_hInst;
    WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    WndClass.lpszMenuName = "MYMENU";
    WndClass.lpszClassName = g_szClassName;
    WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&WndClass))
    {
    MessageBox(0, "Window Registration Failed!", "Error!",
    MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
    return 0;
    }

    hwnd = CreateWindowEx(
    WS_EX_CLIENTEDGE,
    g_szClassName,
    "The title of my window",
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT, 320, 240,
    NULL, NULL, g_hInst, NULL);

    if(hwnd == NULL)
    {
    MessageBox(0, "Window Creation Failed!", "Error!",
    MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
    return 0;
    }

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

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


    And when I run the project, it gives me the following errors:

    In file included from c:\mydocu~1\c__pro~1\winpro~1\project2\2winpr~1.cpp:3:
    c:\mydocu~1\c__pro~1\winpro~1\project2\tut0.rc:5: syntax error before `BEGIN'
    c:\mydocu~1\c__pro~1\winpro~1\project2\2winpr~1.cpp: In function `int WinMain(HINSTANCE__ *, HINSTANCE__ *, CHAR *, int)':
    c:\mydocu~1\c__pro~1\winpro~1\project2\2winpr~1.cpp:33: warning: converting NULL to non-pointer type
    c:\mydocu~1\c__pro~1\winpro~1\project2\2winpr~1.cpp:42: `g_szClassName' undeclared (first use this function)
    c:\mydocu~1\c__pro~1\winpro~1\project2\2winpr~1.cpp:42: (Each undeclared identifier is reported only once
    c:\mydocu~1\c__pro~1\winpro~1\project2\2winpr~1.cpp:42: for each function it appears in.)


    Please note that All the files are in the same folder.
    Please help with this
    Baaaaaaaaah

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Don't include the resource script (.rc) file.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Then It does nothing

    Then I does not include the menus in the window. It just shows a simple window
    Baaaaaaaaah

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Grrr...we've had this problem before. CyberCarsten was doing pretty much the same as you and it didn't work

    First off, what compiler/IDE are you using?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    I am using DEV-C++. If you know how to install Borland C++ compiler 5.5 then you also write that in the reply
    Baaaaaaaaah

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    For Borland C++ 5.5 don't you just run the freecommandlinetools.exe program and that installs it for you?

    As for DEV-C++, I've never used it and don't have a copy so I can't say why it doesn't work...the source code looks fine
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width