can anyone suggest any tutorials for the vc++ resource editor?
or can anyone tell me how to use it?
i know how to design the forms but i dont know how to use it in my code

any help would be appreciated :)

Recommended Answers

All 12 Replies

There is nothing special way to use it. It's like you asking how to use the notepad in windows.


Just design your resource using the resource editor. and save it where your project source files are. and add it to the project. and add it as a resource ( just go to the file view and right click resource files -> add files to the folder) .then you can see a resource tab on your workspace slide. Then again go to the file view slide and just compile the resource named with extension ".rc" and it will generate a file called "resource.h" in the directory where you save the resource script file( your source file folder).
then include that resource helder file using ,

#include "resource.h"

and you can use the symbol ID's that you given when the time you created resources.
If string resource is needed ( for example for a WNDCLASS.lpszMenuName ) use MAKEINTRESOURCE macro to conver it to a string.

i know how to design the forms but i dont know how to use it in my code

You means a dialog ?
well here is the source code . Note that DLG_MAIN is comming from the resource.h. That ID that you given in the resource editor.

#include "stdafx.h"
#include <windows.h>
#include "resource.h"
#include <Commdlg.h>



BOOL WINAPI DlgProc( HWND  hDlg, UINT Msg, WPARAM Param1, LPARAM Param2 );

int WINAPI WinMain( HINSTANCE hInstance , HINSTANCE hPrevInstance , LPSTR lpCmdLine , int nCmdShow )
{
	
	// well just creating the dialog box
	HWND hDialog = CreateDialog( hInstance , MAKEINTRESOURCE( DLG_MAIN) , NULL , DlgProc );

	ShowWindow( hDialog , nCmdShow );

	// then enter the message loop
	MSG msg ;
    while(GetMessage(&msg, NULL, 0, 0))
    {
        if(!IsDialogMessage(hDialog , &msg ))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

	return 0;
}

BOOL WINAPI DlgProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam  )
{
    switch(message)
    {
        
		case WM_COMMAND:
        break;

        default:
            return FALSE;
    }
    return TRUE;

}

i mean what should i put into the resource.rc file and how would i get that to show up in my program such as:

IDR_MYMENU MENU
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "Exit", ID_FILE_EXIT
    END
END

is that right?

commented: Thanks man , now i can type the question directly nica tool , need to find a exe or mozilla addon of that web application. Or somebody write a extension +1

i know about the win32 api but not about using .rc files in it

Read the tutorial and it will tell you how to do it!

You really should get a GUI resource editor so that you can create dialogs and associated controls graphically.

#define IDI_MYICON 101
how do i know what number to give? eg the 101. i got this from a tut

you can assign any number you want, as long as all the numbers in the RC file are unique. Put a lot of space between control types, such as start icons with 100, menus with 200, dialogs with 1000, etc. The reason is to make it easy to add new items of the same type without having to renumber everything and still keep the numbers organized by type.

this is my code:

resource.h:

#define IDR_MYMENU 101
#define IDI_MYICON 201

#define ID_FILE_NEW 1001
#define ID_FILE_OPEN 1002
#define ID_FILE_SAVE 1003
#define ID_FILE_EXIT 1004

#define ID_EDIT_CUT 2005
#define ID_EDIT_COPY 2006
#define ID_EDIT_PASTE 2007

resource.rc:

#include "resource.h"

IDR_MYMENU MENU
BEGIN
    POPUP "File"
    BEGIN
		MENUITEM "New", ID_FILE_NEW
		MENUITEM "Open", ID_FILE_OPEN
		MENUITEM "Save", IF_FILE_SAVE
        MENUITEM "Exit", ID_FILE_EXIT
    END
	POPUP "Edit"
	BEGIN
		MENUITEM "Cut", ID_EDIT_CUT
		MENUITEM "Copy", ID_EDIT_COPY
		MENUITEM "Paste", ID_EDIT_PASTE
	END
END

IDI_MYICON ICON "icon.ico"

main.cpp:

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

const char g_szClassName[] = "myWindowClass";

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
	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;
	
    //Step 1: Registering the Window Class
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;

    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MYMENU);
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);

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

    // Step 2: Creating the Window
    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "A Simple Text Editor",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
        NULL, NULL, hInstance, NULL);

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

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

    // Step 3: The Message Loop 
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}

and this is my error:

.\resource.h(11) : fatal error RC1004: unexpected end of file found

any ideas?

I'm using VC++ 2008 Express and I had to change the resource.h file as shown below. Make sure there is a '\n' after the last line or the resource compiler will complain.

#ifndef APSTUDIO_INVOKED
#define IDR_MYMENU 101
#define IDI_MYICON 201

#define ID_FILE_NEW 1001
#define ID_FILE_OPEN 1002
#define ID_FILE_SAVE 1003
#define ID_FILE_EXIT 1004

#define ID_EDIT_CUT 2005
#define ID_EDIT_COPY 2006
#define ID_EDIT_PASTE 2007
#endif

Then you have a typo in the resource.rc file.

Thanks heaps Ancient Dragon, you really are a great poster. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.