VBCE.com - The Premier Website For Visual Basic/CE Developers

 

*Dev Corner

Sample Code
Controls
Workarounds
Tips & Tricks
Q & A
Forums

*Goodies
Downloads
Software
Bookstore


*General
Home
What's New
General Info
Misc. Info


*News Worthy
News
Articles
Editorials
KB Articles
Reviews
Awards

*Miscellaneous
Web Links
Partners
Search
Feedback
Advertising

<% On Error Resume Next SiteStats() %>

Sponsors


More...


Adding an Icon to Your VBCE Application
By mike@vbce.com

One of the major drawbacks of VBCE is that it creates a P-Code/Script "executable" (*.pvb file) that is interpreted by the VBCE runtime as if it were a document, and thus, the *.pvb file does not contain an icon. The *.pvb file extension is associated in the registry with the pvb.exe. When a pvb file is launched, pvb.exe is executed and the *.pvb file is passed it it. This works the same way as a Pocket Word file does (*.pwd), that is, it is associated with the Pocket Word exe.

Windows CE 2.0 does not support the association of extensions with icon files, otherwise we could just change the extension of the pvb file to something else, and associate that something else to the pvb.exe and set the default icon to the *.ico file. I tried this, it took quite a long time to figure out what was going on. It works in the emulator, but does not work on the devices.

So that leaves us only one option - create a VCCE executable. If you don't have VC, I might be able to make the exe for you. This will actually serve two purposes. It will host the icon for our app, and it will serve as a launcher for our app so people can browse for the exe and double click it to run the application. I'll be honest with you right up front, this is going to be a lot of work until you get the hang of it.

You don't need to know any C or C++, all you have to have is VC++, the VCCE toolkit, and know how to follow instructions.

Step One - Create the VCCE executable.

1) Start Developer Studio.

2) Create a new project by selecting New... from the File menu.

3) In the New dialog, Select Win32 Application from the Projects tab.

4) Type the name of the project in the Project name: text box, such as "HelloWorld", uncheck the Win32 box and click OK. (Click here for an image of this dialog.)

5) Add a new C++ Source file to the project by selecting New... from the File menu, name the file
"helloworld.cpp" and click OK.

6) Paste the following code below into the .CPP file and then modify the "helloworld.pvb" string to that of your pvb file name.

    #include <windows.h>

    //Modify the following line to your project name
    TCHAR szAppName[ ] = TEXT("helloworld.pvb");
    TCHAR szPVB[ ] = TEXT("pvb.exe");

    int WINAPI WinMain(HINSTANCE hInstance,

                       HINSTANCE hPrevInstance,
                       LPTSTR lpCmdLine,
                       int nCmdShow )
    {
        BOOL boolResult;
        boolResult = CreateProcess(szPVB, szAppName,

        NULL, NULL, FALSE, 0, NULL, NULL, NULL, NULL );
        return (0);
    }

7) Select Resource... from the Insert menu.

8) In the Insert Resource dialog, select Icon and then click the Import... button. (See image at Right) Insert Resource

9) In the Import Dialog, select an icon file for the application then click Import.

10) Select Save from the File menu to save the resource file, for example "helloworld.rc"

11) From the menu select Project, then Add to Project, then Files....

12) In the Insert Files into Project dialog, select the .rc file saved in step 10 and then press OK.

13) Select Set Active Configuration... from the Project menu and set the desired target to the Mips Release version.

14) Select Rebuild All from the Build menu to compile the project into an exe.

15) Repeat steps 13 and 14 for the SH Release version.

This completes the VCCE portion, you can now close VC++.

Step Two - Create and Recompile the VBCE Setup Files

These next steps will recreate the CAB files to install the new exe.

1) Launch the VBCE Application Install Wizard and create an install for the application.

2) In the directory that was created by the CE Application Wizard there is a INF file, for example "HelloWorld.inf", double-click this file to open it in notepad.

3) Edit the following line in the INF file:

From:

[Shortcuts]
%AppName%,0,"helloworld.pvb"

To:

[Shortcuts]
%AppName%,0,"helloworld.exe"

4) Copy each version of the Helloworld.exe (mips and sh3) created with VCCE to the appropriate sub-directory that you are to create below the output directory that your setup files are in, for example:\Appsh3\helloworld.exe

\Appsh3\helloworld.exe
\Appmips\helloworld.exe

5) For each processor, add the following to the
[DestinationDirs] section:

[DestinationDirs]
Files.Appsh3=,%InstallDir%
Files.Appmips=,%InstallDir%

6) Add the new Files.Appmips and Files.Appsh3 Copy File Sections to each CopyFiles line of the sections like this: (New items are in bold and red.)

[DefaultInstall.Mips 3000 (4K)]
CopyFiles=Files.Mips 3000 (4K), Files.Appmips

[DefaultInstall.Mips 4000 (1K)]
CopyFiles=Files.Mips 4000 (1K), Files.Appmips

[DefaultInstall.SH 3 (1K)]
CopyFiles=Files.SH 3 (1K), Files.Appsh3

7) Add the following sections to the INF file:

[SourceDisksNames.Appsh3]
4= ,"Application Exe mips",,Appsh3

[SourceDisksFiles.Appsh3]
helloworld.exe=4

[Files.Appsh3]
helloworld.exe

[SourceDisksNames.Appmips]
4= ,"Application Exe sh3",,Appmips

[SourceDisksFiles.Appmips]
helloworld.exe=4

[Files.Appmips]
helloworld.exe

8) Add the two lines for new sections to the [SourceDisksNames] section like this: (New items are in bold and red.)

[SourceDisksNames]
1=,"Application Files",, App
4=,"Application Exe mips",, Appmips
4=,"Application Exe sh3",, Appsh3

9) Add the exe reference to the [SourceDisksFiles] section like this:  (New items are in bold and red.)

[SourceDisksFiles]
helloworld.pvb=1
helloworld.exe=4

10) The Readme.txt file in the directory where the INF file is contains a commandline that can be used to rebuild the cab files, just copy and paste it to the Start, Run Dialog or execute at a DOS prompt.

11) Copy the cab files generated in step 10 to the appropriate CD1, directory. This should complete the process, now you may test the install.

Now that wasn't that bad was it? (grin) The process isn't so bad after you do it a couple of times.

So You Don't Have Visual Studio?
Now your probably thinking "You expect me to spend several hundred dollars on VC and the VCCE toolkit just so I can add an icon to my application?!?!"   No I don't, so I'll make you a deal. If you can contribute a review, source code sample, sample application, or an article on VBCE for the VBCE.COM website, I'll make the exe for you. Just mail me and let me know what you have to contribute and I'll get back to you.

webmaster@vbce.com

You don't need to know any C or C++...”

Read about the deal...

 

VBCE.com is DevX Winner!

Unless otherwise noted, all information on VBCE.com is Copyright 1998 - 2002
Windows, Windows CE, and Visual Basic are trademarks of the Microsoft Corporation.
VBCE.com is not responsible for content on external sites.
Send all feedback to webmaster@vbce.com
Webmasters - feel free to link to
VBCE.com - Premier Website for Visual Basic/CE Development

Buy Books!