Thread overview
Resource files
Oct 23, 2003
Mårten Ask
Oct 23, 2003
J C Calvarese
Oct 24, 2003
Mårten Ask
Oct 24, 2003
Vathix
Oct 24, 2003
Mårten Ask
Oct 27, 2003
Charles Sanders
Oct 27, 2003
Mårten Ask
Oct 25, 2003
J C Calvarese
October 23, 2003
Hi, I'm trying to build a GUI using the windows API. Some of the functions expects me to use a resource file, then compile and link it with the executable. How do I do that?


October 23, 2003
Mårten Ask wrote:
> Hi, I'm trying to build a GUI using the windows API. Some of the functions expects me to use a resource file, then compile and link it with the executable. How do I do that?

I'm not sure exactly where you're running to problems, so I'll just explain a little of what I know about resource files and attach an example.

Typically, one has a resource script (.rc) that is compiled into a resource file (.res) by a resource compiler (such as Digital Mars' RCC.EXE, which is available for free).

Then the compiled resource is attached to the compiled executable.  With
  DMD, the resource file is simply added as a command line argument like
this:
dmd whatever.d resource.res


My very simple example
-----------------------------------------------------------------
compile_rc.bat: a batch file to automate the whole process
whatever.d: a minimalist D source file that doesn't do anything
resource.rc: an example of a resource script
w.ico: an icon resource called by the resource script


I hope this helps.

Justin


October 24, 2003
Thanks!

I wasn't very clear in my first post, I understand what a resource file is and what it does. It's just that every example I've seen on how to use them have been written in C or C++.

Like this example:

resource.h
------------
#define IDR_MYMENU 101
#define IDI_MYICON 201

#define ID_FILE_EXIT 9001
#define ID_STUFF_GO 9002

resource.rc
------------
#include "resource.h"

IDR_MYMENU MENU
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "E&xit", ID_FILE_EXIT
    END

    POPUP "&Stuff"
    BEGIN
        MENUITEM "&Go", ID_STUFF_GO
        MENUITEM "G&o somewhere else", 0, GRAYED
    END
END

IDI_MYICON ICON "menu_one.ico"


Then include resource.h and register the menu and the icons in the WinMain
function:
wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MYMENU);
wc.hIcon  = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
wc.hIconSm  = (HICON)LoadImage(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);


How do I translate all that to D? Do I write a resource.d file and use extern (C) to fetch the variables in resource.h?

Help!



"J C Calvarese" <jcc7@cox.net> skrev i meddelandet news:bn9ml7$27et$1@digitaldaemon.com...
> Mårten Ask wrote:
> > Hi, I'm trying to build a GUI using the windows API. Some of the
functions
> > expects me to use a resource file, then compile and link it with the executable. How do I do that?
>
> I'm not sure exactly where you're running to problems, so I'll just explain a little of what I know about resource files and attach an
example.
>
> Typically, one has a resource script (.rc) that is compiled into a
> resource file (.res) by a resource compiler (such as Digital Mars'
> RCC.EXE, which is available for free).
>
> Then the compiled resource is attached to the compiled executable.  With
>   DMD, the resource file is simply added as a command line argument like
> this:
> dmd whatever.d resource.res
>
>
> My very simple example
> -----------------------------------------------------------------
> compile_rc.bat: a batch file to automate the whole process
> whatever.d: a minimalist D source file that doesn't do anything
> resource.rc: an example of a resource script
> w.ico: an icon resource called by the resource script
>
>
> I hope this helps.
>
> Justin
>


----------------------------------------------------------------------------
----


> @echo off
>
> echo Compiling resource file...
> rem   rc /r resource.rc
> rcc resource.rc -v -32
>
> dmd whatever.d resource.res
> pause
>
> erase resource.res
> erase whatever.map
> erase whatever.obj
>
>


----------------------------------------------------------------------------
----


> void main()
> {
>
>
> }


----------------------------------------------------------------------------
----


> 1000 ICON MOVEABLE PURE LOADONCALL DISCARDABLE "w.ico"
> 1 VERSIONINFO
> FILEVERSION    1, 2, 3, 4
> PRODUCTVERSION 1, 2, 3, 4
> FILEOS 0x4
> FILETYPE 0x1
> BEGIN
> BLOCK "StringFileInfo"
> BEGIN
> BLOCK "040904B0"
> BEGIN
>         VALUE "LegalCopyright", "(c) 2002 Some Body"
>         VALUE "FileDescription",  "This program does awesome stuff!"
> VALUE "Author", "Some Body"
> VALUE "CompanyName", "XYZ Corp."
> VALUE "ProductName", "Acme Program"
> VALUE "FileVersion", "1.2.3"
> VALUE "ProductVersion", "1.2.3"
> VALUE "InternalName", "something"
> VALUE "OriginalFilename", "something.exe"
> END
> END
>
> BLOCK "VarFileInfo"
> BEGIN
> VALUE "Translation", 0x0409,  0x04B0
> END
> END
>


----------------------------------------------------------------------------
----






October 24, 2003
> resource.h
> ------------
> #define IDR_MYMENU 101

What I do is:
const char* IDR_MYMENU = cast(char*)101;
You can use IDR_MYMENU without using MAKEINTRESOURCE; make sure those values
don't get larger than short.max. I have to put the actual values in the
resource file. It would be nice if there was a resource file just for D that
you could use import.



October 24, 2003
Thanks! I'll continue tinkering and see if I can get it right..


"Vathix" <vathix@dprogramming.com> skrev i meddelandet news:bnavtu$1aoq$1@digitaldaemon.com...
> > resource.h
> > ------------
> > #define IDR_MYMENU 101
>
> What I do is:
> const char* IDR_MYMENU = cast(char*)101;
> You can use IDR_MYMENU without using MAKEINTRESOURCE; make sure those
values
> don't get larger than short.max. I have to put the actual values in the resource file. It would be nice if there was a resource file just for D
that
> you could use import.
>
>
>


October 25, 2003
Mårten Ask wrote:

> Thanks!
> 
> I wasn't very clear in my first post, I understand what a resource file is and what it does. It's just that every example I've seen on how to use them have been written in C or C++.
Okay, maybe someone else benefited from reading that reply, then...

> 
> Like this example:
Examples are always good.

> 
> resource.h
> ------------
> #define IDR_MYMENU 101
> #define IDI_MYICON 201
> 
> #define ID_FILE_EXIT 9001
> #define ID_STUFF_GO 9002
> 
> resource.rc
> ------------
> #include "resource.h"
> 
> IDR_MYMENU MENU
> BEGIN
>     POPUP "&File"
>     BEGIN
>         MENUITEM "E&xit", ID_FILE_EXIT
>     END
> 
>     POPUP "&Stuff"
>     BEGIN
>         MENUITEM "&Go", ID_STUFF_GO
>         MENUITEM "G&o somewhere else", 0, GRAYED
>     END
> END
> 
> IDI_MYICON ICON "menu_one.ico"
> 
> 
> Then include resource.h and register the menu and the icons in the WinMain
> function:
> wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MYMENU);
> wc.hIcon  = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
> wc.hIconSm  = (HICON)LoadImage(GetModuleHandle(NULL),
> MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
> 
> 
> How do I translate all that to D? Do I write a resource.d file and use extern (C) to fetch the variables in resource.h?

One thing that I've been doing is creating a simple .h file and then running my simple h_to_d program on it to create a .d file that can be imported.

h_to_d.exe resource.h
creates resource.d (it only works on very simple .h files).  I put it up
at my website in case you're interested in trying it out:
http://jcc_7.tripod.com/d/h_to_d.zip.  It's not fancy, but it's been
useful for me.

Also, I attached the file it generated from your example.


Justin
http://jcc_7.tripod.com/d/

> 
> Help!
> 
...


October 27, 2003
Marten do you still have that CGI module ?


C

"Mårten Ask" <majbritt37@hotmail.com> wrote in message news:bnb3d2$1f9r$1@digitaldaemon.com...
> Thanks! I'll continue tinkering and see if I can get it right..
>
>
> "Vathix" <vathix@dprogramming.com> skrev i meddelandet news:bnavtu$1aoq$1@digitaldaemon.com...
> > > resource.h
> > > ------------
> > > #define IDR_MYMENU 101
> >
> > What I do is:
> > const char* IDR_MYMENU = cast(char*)101;
> > You can use IDR_MYMENU without using MAKEINTRESOURCE; make sure those
> values
> > don't get larger than short.max. I have to put the actual values in the resource file. It would be nice if there was a resource file just for D
> that
> > you could use import.
> >
> >
> >
>
>


October 27, 2003
Yup. Here it is. It's not at all done yet, It doesn't understand what file-uploading is. But it works for simple apps.


"Charles Sanders" <sanders-consulting@comcast.net> skrev i meddelandet news:bnjg2v$2beq$1@digitaldaemon.com...
> Marten do you still have that CGI module ?
>
>
> C
>
> "Mårten Ask" <majbritt37@hotmail.com> wrote in message news:bnb3d2$1f9r$1@digitaldaemon.com...
> > Thanks! I'll continue tinkering and see if I can get it right..
> >
> >
> > "Vathix" <vathix@dprogramming.com> skrev i meddelandet news:bnavtu$1aoq$1@digitaldaemon.com...
> > > > resource.h
> > > > ------------
> > > > #define IDR_MYMENU 101
> > >
> > > What I do is:
> > > const char* IDR_MYMENU = cast(char*)101;
> > > You can use IDR_MYMENU without using MAKEINTRESOURCE; make sure those
> > values
> > > don't get larger than short.max. I have to put the actual values in
the
> > > resource file. It would be nice if there was a resource file just for
D
> > that
> > > you could use import.
> > >
> > >
> > >
> >
> >
>
>