DevPinoy.org
A Filipino Developers Community

>>> First two to make 3 wins! <<<

How Are Resource Files Used?

rated by 0 users
This post has 22 Replies | 0 Followers

Top 10 Contributor
Posts 742
Points 10,050
modchip Posted: 03-16-2006 6:00 PM
Hi to all of you,

... I'm searching for tutorials on how to use resource file but unfortunately didn't find any.

So, I would like to ask help from anybody in this forum to at least give some sample codes of a little application that uses resource files. I'm using WinAsm Studio/MASM32 9.0, it has a visual resource editor but I don't know how to use it. I tried to, but it doesn't work... Please help.

Thanks in advance.

Regards,
mods

  • Filed under:
  • | Post Points: 20
Top 10 Contributor
Posts 498
Points 8,375
Hi, there is a help file (RC.HLP) in the help folder of MASM32. I think that's one of the best help there is, since MASM is using Microsoft Resource Compiler.

Regards,

-chris
Chris Vega This posting is provided "AS IS" with no warranties, and confers no rights My Weblog|Visit MSDN Community
  • | Post Points: 20
Top 10 Contributor
Posts 742
Points 10,050
Thanks Chris! Hindi ko alam meron palang doc dun. Thanks, I'll work on this.

BTW, thanks for inviting me to this site. ;)

  • Filed under:
  • | Post Points: 20
Top 10 Contributor
Posts 498
Points 8,375
No prob.

Just post any question or tips for Assembly Language in here.

Regards,

-chris
Chris Vega This posting is provided "AS IS" with no warranties, and confers no rights My Weblog|Visit MSDN Community
  • | Post Points: 20
Top 10 Contributor
Posts 742
Points 10,050
Hi,

I scanned through the RC.HLP file and I can't find what I'm looking for...

The first page sort of gives me a glimpse of what I'm after;

;from rc.hlp
Including Resources in an Application

To include resources in your 32-bit Windows application, do the following:

1.    Create individual resource files for cursors, icons, bitmaps, dialog boxes, and fonts. To do this, you can use Microsoft Image Editor and Dialog Editor (IMAGEDIT.EXE and DLGEDIT.EXE) and Microsoft Windows Font Editor (FONTEDIT.EXE).
2.    Create a resource-definition file (script) that describes all the resources used by the application.
3.    Compile the script into a resource (.RES) file with RC.
4.    Link the compiled resource files into the application's executable file.


Number 4 is what I'm really searching for which is how you actually use/link the resource file to the executable... I've searched the net,
barely found the info, though found some source codes BUT are too confusing for me.

To make it short, I'm politely asking you guys post your source code of a little app that has some textboxes, buttons, dialog... etc. that does nothing but show itself, if its ok with you.

Pasensya sa pangungulit. Thanks in advance. Big Smile

Regards,
mods

  • Filed under:
  • | Post Points: 20
Top 10 Contributor
Posts 498
Points 8,375

You can use RC.EXE file in the bin directory to compile the resource script.

Example: Your script is saved in myresource.rc

     rc /v myresource.rc

That will produce a myresource.res file, which you can convert it to object file using CVTRES.EXE:

     cvtres /machine:ix86 myresource.res

That will produce a myresource.obj file, ready for linking using the LINK.EXE:

Example: You ASM file has been assembled as myprogram.obj:
     link /SUBSYSTEM:WINDOWS myprogram.obj myresource.obj

You final product is
myprogram.EXE
.

Regards,

-chris

Chris Vega This posting is provided "AS IS" with no warranties, and confers no rights My Weblog|Visit MSDN Community
  • | Post Points: 20
Top 10 Contributor
Posts 742
Points 10,050
How about in the .asm file, do I need to write something in it? I saw some examples with this lines that I'm assuming are related to the resource file...

.const
IDD_DLG1001                     Equ 1001
IDC_BUTTON1002                  Equ 1002


Thanks again.

Regards,
mods

  • Filed under:
  • | Post Points: 20
Top 10 Contributor
Posts 498
Points 8,375
These are actually constant values for easy reference in .ASM codes; these are the same values in the actual resource script (*.RC). IDD_DLG1001 is a dialog resource, and IDC_BUTTON1002 is a control resource.

Regards,

-chris
Chris Vega This posting is provided "AS IS" with no warranties, and confers no rights My Weblog|Visit MSDN Community
  • | Post Points: 20
Top 10 Contributor
Posts 742
Points 10,050
Ok thanks. I'll research more on this. I'll just post again things that are unclear to me. Thanks again Chris, you've been a lot of help. :)

Regards,
mods

  • Filed under:
  • | Post Points: 20
Top 10 Contributor
Posts 498
Points 8,375

No prob. I'm here always in DevPinoy Smile [:)]

Chris Vega This posting is provided "AS IS" with no warranties, and confers no rights My Weblog|Visit MSDN Community
  • | Post Points: 20
Top 10 Contributor
Posts 742
Points 10,050
I finally did it! Thanks for the help!

And for the last favor, could you please point out the important lines needed just to show the resource... and a little explanation of the lines if its ok... Thanks again!

Regards,
mods


;---------------------------------------------------------------------------
; my resource file... but generated for WinasmStudio vre
;---------------------------------------------------------------------------

#define IDC_OK 1003
#define IDC_EXIT 1004

101 DIALOGEX 0,0,157,29
CAPTION "Test Dialog"
FONT 8,"Tahoma"
STYLE 0x90c80880
EXSTYLE 0x00000000
BEGIN
    CONTROL "OK",IDC_OK,"Button",0x10000001,103,6,24,14,0x00000000
    CONTROL "Exit",IDC_EXIT,"Button",0x10000000,130,6,21,14,0x00000000
    CONTROL "",1001,"Edit",0x10000080,7,7,90,12,0x00000200
END



;---------------------------------------------------------------------------
; my asm file...
;---------------------------------------------------------------------------
.386
.model    flat,stdcall
option    casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

.const
IDC_OK Equ 1003
IDC_EXIT Equ 1004

.data?
hInstance dd ?

.code
start:
    invoke GetModuleHandle, NULL
    mov hInstance, eax
    invoke DialogBoxParam, hInstance, 101, 0, ADDR DlgProc, 0
    invoke ExitProcess, eax

DlgProc proc hWin:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD

    .if uMsg == WM_CLOSE
        invoke EndDialog,hWin,0
    .endif

    xor eax,eax
    ret
DlgProc endp

end start


  • Filed under:
  • | Post Points: 20
Top 10 Contributor
Posts 498
Points 8,375

I dont usually use resource generators, or if I use one, I usually use the one from Microsoft Visual C++ (and clean it after). From your resource, you can actually use a C' curly braces in defining blocks:

Here's yours
#define IDC_OK 1003
#define IDC_EXIT 1004

101 DIALOGEX 0,0,157,29
CAPTION "Test Dialog"
FONT 8,"Tahoma"
STYLE 0x90c80880
EXSTYLE 0x00000000
BEGIN
    CONTROL "OK",IDC_OK,"Button",0x10000001,103,6,24,14,0x00000000
    CONTROL "Exit",IDC_EXIT,"Button",0x10000000,130,6,21,14,0x00000000
    CONTROL "",1001,"Edit",0x10000080,7,7,90,12,0x00000200
END

Here's the modified one, with comments:
#define IDC_OK 1003
#define IDC_EXIT 1004

101 DialogEx 0, 0, 157, 29  // Dialog - X, Y, Width, Height
    Caption "Test Dialog" // Dialog Caption
    Font 8,"Tahoma"       // Font - Size in Point, Font-Face
    Style 0x90c80880      // Window Styles (WS_*)
    ExStyle 0x00000000    // Window Extended Styles (WS_EX_*)
{
    // This is a button "OK" control
    Control           // Definition can span multiple lines
         "OK",        // Caption
         IDC_OK,      // ID
         "Button",    // Class
         0x10000001,  // Styles
         103,         // X
         6,           // Y
         24,          // Width
         14,          // Height
         0x00000000   // Extended-Styles (Optional)

    // This is a button "Exit" control
    Control "Exit",IDC_EXIT,"Button",0x10000000,130,6,21,14,0x00000000

    // This is an edit control
    Control "",1001,"Edit",0x10000080,7,7,90,12,0x00000200
}

As you may have noticed from the modified recource script, nothing has changed except that I added indentation and changed the BEGIN-END to curly braces {}; and since I used the C language notation, I can now use the C comment styles, both single-line comment // and multi-line comments /* */ will work.

One the part of defines, like this one:
#define IDC_OK 1003
#define IDC_EXIT 1004


If the list becomes huge, i.e., for number of controls, menus, resource and accelerators; you can simply move it to another (*.h) header file, i.e., resource.h; then use the C language #include directive to attach the external resource script to your main resource script.

See the attachment for another example of a dialog-based MASM program (coded in WinAsm studio), and it uses the MessageCracker include file.

Regards,

-chris


Chris Vega This posting is provided "AS IS" with no warranties, and confers no rights My Weblog|Visit MSDN Community
  • | Post Points: 20
Top 10 Contributor
Posts 742
Points 10,050
Thank you very much. Your reply was very well illustrated and I appreciate that. I liked the { }, it makes the code more readable, thanks for that advice. Hopefully, with your tips, I could become better in coding in asm.

Once again, thanks!

Regards,
mods

  • Filed under:
  • | Post Points: 20
Top 10 Contributor
Posts 498
Points 8,375
No problem, I'm glad to help.

By the way, also check resource.h file in include directory of MASM32, it has defines for all the Window Styles (Control Styles) constants you can use in your resource script. Many examples in MASM32 actually uses that file.

Regards,

-chris
Chris Vega This posting is provided "AS IS" with no warranties, and confers no rights My Weblog|Visit MSDN Community
  • | Post Points: 20
Top 10 Contributor
Posts 742
Points 10,050
Thank you. I'm also currently studying the message cracker that you included in the attachment. Expect more questions soon... Stick out tongue he he he.

Regards,
mods

  • Filed under:
  • | Post Points: 35
Page 1 of 2 (23 items) 1 2 Next > | RSS

Copyright DevPinoy 2005-2008