NO

Author Topic: how to use resource editor  (Read 9900 times)

goom

  • Guest
how to use resource editor
« on: March 16, 2011, 04:38:22 pm »
I see there is a resource editor but I am really new to
this and see there isn't much online documentation
or tutorial on how you create a resource and then
use it (while using Pelles C).  Anyone know where
I should start


Offline Vortex

  • Member
  • *
  • Posts: 529
    • http://www.vortex.masmcode.com
Re: how to use resource editor
« Reply #1 on: March 16, 2011, 10:27:48 pm »
Code it... That's all...

CommonTater

  • Guest
Re: how to use resource editor
« Reply #2 on: March 16, 2011, 11:54:28 pm »
Anyone know where I should start

You can read up on resources, that's a pretty helpful thing.

But just for the sake of getting you going....

Create a new project (gui or console) and get your main page running...
"Hello world" is fine...
Now select an icon (*.ico) for your program and place it in the folder with your source code.
Next click New -> Resources
You should see an untitled page open...
Right click on untitled and select Import
Select your icon and click OK.
Then save the tab as "resources".

When you compile the icon is included into the file and you can see it in explorer.

Now that you have resources in your project you can expand them as much as you like
You simple right click, New - > Dialog and you can make your own dialog boxes

IOW... mess around with it a bit... It's not that hard to figure out.


nutzu2010

  • Guest
Re: how to use resource editor
« Reply #3 on: April 22, 2011, 05:20:35 pm »
thanks @CommonTater ,I managed with a cursor and a icon(I created a header file),but how make a menu?to understand,I want to do menu manually...can you tell me how?

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1896
Re: how to use resource editor
« Reply #4 on: April 22, 2011, 05:47:39 pm »
Read this:
http://www.winprog.org/tutorial/menus.html

PellesC have good resource editor, learn to use it.

Example of dynamic menu.
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commctrl.h>

//#pragma lib "comctl32.lib"

#define IDM_EXIT 6000
#define IDM_OPEN 6001

#define IDC_STATUS 4000
#define IDC_TOOLBAR 4001

#ifndef NELEMS
#define NELEMS(a)  (sizeof(a) / sizeof(a[0]))
#endif

LRESULT WINAPI WndProc(HWND, UINT, WPARAM, LPARAM);
BOOL OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct);
void OnDestroy(HWND hwnd);
void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify);
void OnSize(HWND hwnd, UINT state, int cx, int cy);

TCHAR szAppName[] = TEXT("WSDIFrame");
TCHAR szFrameClass[] = TEXT("cWSDIFrame");
HWND hFrame, hStatus, hToolbar;
HANDLE hInst;
HMENU hMenu, hMenuT;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
        WNDCLASSEX wcx;
        MSG msg;

        wcx.cbSize = sizeof(WNDCLASSEX);
        //GetClassInfoEx(hInstance, MAKEINTRESOURCE(32770), &wcx);
        wcx.style     = CS_HREDRAW | CS_VREDRAW;
        wcx.lpfnWndProc = (WNDPROC) WndProc;
        wcx.cbClsExtra        = 0;
        wcx.cbWndExtra        = 0;
        wcx.hInstance   = hInstance;
        wcx.hIcon     = LoadIcon(NULL, IDI_APPLICATION);
        wcx.hCursor   = LoadCursor(NULL, IDC_ARROW);
        //wcx.hbrBackground = (HBRUSH)COLOR_WINDOW;
        wcx.hbrBackground= (HBRUSH)COLOR_APPWORKSPACE+1;
        wcx.lpszMenuName      = NULL;
        wcx.lpszClassName= szFrameClass;
        wcx.hIconSm   = LoadIcon(NULL, IDI_APPLICATION);

        if (!RegisterClassEx(&wcx))
                return 0;
        hInst = hInstance;

        hFrame = CreateWindowEx(0, szFrameClass, szAppName,
                WS_OVERLAPPEDWINDOW,
                CW_USEDEFAULT, CW_USEDEFAULT,
                CW_USEDEFAULT, CW_USEDEFAULT,
                NULL, NULL, hInst, NULL);
        if(!hFrame) return 0;
        ShowWindow(hFrame, nCmdShow);
        UpdateWindow(hFrame);

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

HWND MakeToolbar(HWND hWnd, UINT wID)
{
        TBBUTTON tbb[] = {
                //{STD_, IDM_, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
                {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, 0},
                //{STD_FILENEW, IDM_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
                {STD_FILEOPEN, IDM_OPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
        };

        HWND hToolbar = CreateToolbarEx(hWnd,
                WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT
                , wID, 0, HINST_COMMCTRL, IDB_STD_SMALL_COLOR,
                 tbb, NELEMS(tbb), 100, 0, 30, 30, sizeof(TBBUTTON));
        return hToolbar;
}

HWND MakeStatusbar(HWND hWnd, UINT wID)
{
        HWND hStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE,        // | SBARS_SIZEGRIP,
                NULL, hWnd, wID);
        return hStatus;
}

HMENU MakeMenubar(HWND hWnd)
{
        HMENU hMenu, hMenuT;

        hMenu = CreateMenu();
        hMenuT = CreatePopupMenu();
        AppendMenu(hMenuT, MF_ENABLED | MF_STRING, IDM_OPEN, TEXT("&Open"));
        AppendMenu(hMenuT, MF_ENABLED | MF_STRING, IDM_EXIT, TEXT("&Exit"));
        AppendMenu(hMenu, MF_ENABLED | MF_POPUP, (UINT)hMenuT, TEXT("&File"));
        SetMenu(hWnd, hMenu);
        return hMenu;
}

LRESULT WINAPI WndProc(HWND hwnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
        switch(wMsg) {
        case WM_COMMAND:
                return OnCommand(hwnd,(int)(LOWORD(wParam)),(HWND)(lParam),(UINT)HIWORD(wParam)),0;
        case WM_SIZE:
                return OnSize(hwnd,(UINT)(wParam),(int)(short)LOWORD(lParam),(int)(short)HIWORD(lParam)),0;
        case WM_CREATE: return OnCreate(hwnd,(LPCREATESTRUCT)(lParam)),0;
        case WM_DESTROY: return OnDestroy(hwnd),0;

        default:
                return DefWindowProc(hwnd, wMsg, wParam, lParam);
        }
}

BOOL OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
{
        InitCommonControls();
        hToolbar = MakeToolbar(hwnd, IDC_TOOLBAR);
        hStatus = MakeStatusbar(hwnd, IDC_STATUS);
        hMenu = MakeMenubar(hwnd);
        return 0;
}

void OnDestroy(HWND hwnd)
{
        PostQuitMessage(0);
}

void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
        switch(id) {
        case IDM_EXIT:
                PostMessage(hwnd, WM_CLOSE, 0, 0L);
                return;
        }

}

void OnSize(HWND hwnd, UINT state, int cx, int cy)
{
        SendMessage(hToolbar, WM_SIZE, state, cx);
        SendMessage(hStatus, WM_SIZE, state, cx);
}
« Last Edit: April 22, 2011, 06:35:23 pm by timovjl »
May the source be with you

nutzu2010

  • Guest
Re: how to use resource editor
« Reply #5 on: April 22, 2011, 06:25:57 pm »
you must add ,in your project,all files(.h and .rc)?not enough to write include "resource.h" ?

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1896
Re: how to use resource editor
« Reply #6 on: April 22, 2011, 06:40:50 pm »
You must insert .rc file to project where menu recource is.
After that you can edit resource with resource-editor.
From IDE menu File -> New -> Resources you can insert empty resouce to project.
May the source be with you

nutzu2010

  • Guest
Re: how to use resource editor
« Reply #7 on: April 22, 2011, 06:42:47 pm »
So better,I'm learning how to make a dynamic menu?

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 567
    • Homepage
Re: how to use resource editor
« Reply #8 on: April 22, 2011, 07:13:10 pm »
I would start with a static one to get a feeling, then you can advance to the dynamic one.
---
Stefan

Proud member of the UltraDefrag Development Team

CommonTater

  • Guest
Re: how to use resource editor
« Reply #9 on: April 22, 2011, 07:59:08 pm »
thanks @CommonTater ,I managed with a cursor and a icon(I created a header file),but how make a menu?to understand,I want to do menu manually...can you tell me how?

Y'know what... read the help file under "Integrated Environment" everything is there.

To ad a menu to your resources simply open the resource you created in my first example and right click on it... Then click New and Menu... That will open the menu editor.

Really this isn't all that hard... You just gotta be a little bit experimental... cllick on stuff, right click on stuff, explore! When in doubt read the help file... Pelles help file is one of the best I've ever seen.

« Last Edit: April 22, 2011, 08:03:27 pm by CommonTater »

jboyes

  • Guest
Re: how to use resource editor
« Reply #10 on: August 01, 2011, 12:56:13 pm »
When you say that everything is in the help file, you are not entirely correct. For example, the Menu resource is very easy to manipulate but nowhere does it point out that one has to add "lpszMenuName = MAKEINTRESOURCE(IDR_MAIN_MENU);" to actually make it appear on the dialog. I found this information in a book that I just happen to have.

My problem now is that although I can use the resource editor to create a ToolBar, when I run the program, it doesn't show on the dialog. Unfortunately, in this case, there is no parameter in WNDCLASSEX for it to go. It appears in the TEXT version of the resource file just like all the other controls (which do appear and work OK) but is invisible when the program runs. Is there something that needs to be added to make it show up? (In Window styles, Visible is set to Yes).

Online articles say that one has to create the toolbar from scratch but there is a ton of stuff in the commdlg header file which seems to me to have done all of that work for us and we just need to access it somehow.

Any help would be appreciated.

John.


CommonTater

  • Guest
Re: how to use resource editor
« Reply #11 on: August 01, 2011, 02:52:38 pm »
When you say that everything is in the help file, you are not entirely correct. For example, the Menu resource is very easy to manipulate but nowhere does it point out that one has to add "lpszMenuName = MAKEINTRESOURCE(IDR_MAIN_MENU);" to actually make it appear on the dialog. I found this information in a book that I just happen to have.
Because you don't have to do that.   You can name your menu "MAINWM" (or whatever you choose) then when registering your windclass just use it's text name....  lpszMenuName = "MAINWM";

In fact you can do that with any resource... Just right click the resource, select properties and give it a text name in quotes.  (See the attached image below)

Quote
My problem now is that although I can use the resource editor to create a ToolBar, when I run the program, it doesn't show on the dialog. Unfortunately, in this case, there is no parameter in WNDCLASSEX for it to go. It appears in the TEXT version of the resource file just like all the other controls (which do appear and work OK) but is invisible when the program runs. Is there something that needs to be added to make it show up? (In Window styles, Visible is set to Yes).

Toolbars are created as child windows, just like EDIT or BUTTON controls.  Before you're going to see it you need to add your buttons, separators etc to it.  This would typically be done during WM_INITDIALOG or WM_CREATE. 

Quote
Online articles say that one has to create the toolbar from scratch but there is a ton of stuff in the commdlg header file which seems to me to have done all of that work for us and we just need to access it somehow.

'Fraid not... To create a toolbar you will need to load your button images (or you can use the defaults) and then add each button to the toolbar manually. 

« Last Edit: August 01, 2011, 03:09:16 pm by CommonTater »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1896
Re: how to use resource editor
« Reply #12 on: August 01, 2011, 06:29:06 pm »
Example for WM_INITDIALOG
Code: [Select]
FillToolbar(hwndDlg, 4001);
Code: [Select]
void FillToolbar(HWND hWndDlg, int iCtl)
{
TBBUTTON tbb[] = {
{STD_FILENEW, IDM_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON},
{STD_FILEOPEN, IDM_OPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON},
};
HWND hToolbar = GetDlgItem(hWndDlg, iCtl);
if (hToolbar) {
// Load the button images.
SendMessage(hToolbar, TB_LOADIMAGES, (WPARAM)IDB_STD_SMALL_COLOR, (LPARAM)HINST_COMMCTRL);
// Add buttons.
SendMessage(hToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
SendMessage(hToolbar, TB_ADDBUTTONS, (WPARAM)NELEMS(tbb), (LPARAM)&tbb);
}
}
May the source be with you

CommonTater

  • Guest
Re: how to use resource editor
« Reply #13 on: August 01, 2011, 07:25:31 pm »
Thanks Timo... I was looking for an example in my own code but they were all far more complex than yours.

jboyes

  • Guest
Re: how to use resource editor
« Reply #14 on: August 01, 2011, 07:58:16 pm »
Many many thanks Timo; I would never have found that out by myself.

May I be cheeky and ask another question?  Where are the standard bitmaps for the buttons stored?

John.