[Solved]How to use windowsShortcut.ec?

General help specific to the Windows platform.
Post Reply
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

[Solved]How to use windowsShortcut.ec?

Post by samsam598 »

I want to create a shortcut for my ecere program.Given below code:

Code: Select all

import "ecere"
import "windowsShortcut"//import "my/path/to/ecere/extra/windowsShortcut"   ->the same

...
Button myButton
{
   ...
   bool NotifyClicked(Button button,int x,int y,Modifier mods)
    {
         CreateLink("program.exe","myShortcut.ext","this is a shortcut for program.exe");
    }
}
But it does get compiled.Was I missing something?Thanks for the help.

Code: Select all

form1.ec
   form1.ec:3:1: error: Couldn't open obj/release.win32\windowsShortcut.sym
   form1.ec:3:1: error: Couldn't open obj/release.win32\windowsShortcut.sym           

Edited on Sep 16,2011.Updated full source:

Code: Select all

 
 
//app name:shortcutapp
import "ecere"
import "windowsShortcut"
class Form1 : Window
{
   text = "快捷方式";
   background = activeBorder;
   borderStyle = fixed;
   hasMaximize = true;
   hasMinimize = true;
   hasClose = true;
   size = { 200, 80 };
   anchor = { horz = -239, vert = -181 };
   nativeDecorations = true;
 
   Button btnShortcut 
   {      
      this, text = "(S)创建快捷方式", altS, size = { 146, 21 }, position = { 24, 16 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         String program = "C:\\person\\ecere\\ex\\shortcutapp\\obj\\release.win32\\shortcutapp.exe";
         String dir = "C:\\Users\\shu\\Desktop";
         char file[MAX_LOCATION];strcpy(file, dir);
         PathCat(file, "shortcutapp.exe.lnk");
         //MakeDir(dir); // Ensure the Start Menu folder is created
         CreateLink(program, file, null);
 
         MessageBox{text="快捷方式",contents="已在桌面上创建本程序的快捷方式。"}.Modal();
         return true;
      }
   };
}
 
Form1 form1 {};
 
 
Last edited by samsam598 on Fri Sep 16, 2011 2:28 am, edited 2 times in total.
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: How to use windowsShortcut.ec?

Post by jerome »

1. You need to add windowsShortcuts.ec to your project (right click project node, Add file to project or select project node and 'Enter')
import works 2 ways:
- It imports an eC shared library (e.g. ecere.dll)
- It imports another eC file within your project (works through the '.sym' files)
First it will look for a dll, if it can't find any it will look for a .sym files (which get generated by the files within your project). See page 93-97 in the Tao for more info.

2. import "windowsShortcut" is right

3. You have a typo: Modifier instead of Modifiers

4. You will need to add uuid and ole32 to your Project Settings / Linking / Additional Libraries for the application to link
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

Re: How to use windowsShortcut.ec?

Post by samsam598 »

Thanks Jerome,it compiles!

But sorry for my stupid.The CreateLink params seems wrong(I mean I have no idea how to set the right params) since I did not create a shortcut after the program is running.
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: How to use windowsShortcut.ec?

Post by jerome »

Hi Sam,

I've tried your code, and it does work. It creates a shortcut to program.exe, in the current directory. Also note that this function expects UTF-8 parameters (It will converts to Windows' UTF-16 encoding).

The extension for shortcut however should be '.lnk', and if you want the text to be displayed you should name your shortcut that way, e.g. 'this is a shortcut for program.exe.lnk'.

For the last parameter you can just pass null, it only goes in the 'comment' (which you can check if you hit alt-enter on the shortcut to bring up the properties dialog).

This is used e.g. by the installer to fill up the Start Menu, e.g.:

Code: Select all

String program = "C:\\Program Files (x86)\\ECERE SDK\\bin\\ide.exe";
String dir = "C:\\Users\\Jerome\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\ECERE SDK";
char file[MAX_LOCATION];
strcpy(file, dir);
PathCat(file, "ECERE IDE.lnk");
MakeDir(dir); // Ensure the Start Menu folder is created
CreateLink(program, file, null);
Of course the directories are hardcoded, and a smart installer would find the proper values from the system (through environment variables and the registry, it's a bit messy). If you're interested, you can look at the Ecere Installer source code.

Cheers,

Jerome
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

Re: How to use windowsShortcut.ec?

Post by samsam598 »

Hi Jerome,

Thanks.It is perfect.

BWT,I noticed you used String instead of char* in the snippet,what's a String,what can it do?I want to learn more.Thanks.
Also I know there is a FileDialog which allow us to pick a file from a dialog window.Is there also a DirectoryDialog to allow select a folder?Thanks.

Regards,
Sam
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: How to use windowsShortcut.ec?

Post by jerome »

At the moment, String and char * are interchangeable and represent the same data type.

In the future, we hope to have a more evolved String data type that makes life easier for eC programmers. (Right now, all we have are a bunch of convenience functions, like CopyString, and operators like new/delete to help us with the complexity of C strings).

For example, see this thread for a lot more info about strings in eC.

The DirectoryDialog is a FileDialog with the 'type' member set to 'selectDir'

Code: Select all

public enum FileDialogType { open, save, selectDir, multiOpen };
e.g.:

Code: Select all

FileDialog dialog { type = selectDir, text = "Please select a folder..." };
/* At the moment you need to use incref if 'dialog' is not a member 
of another instance or a global object, because otherwise it won't be 
valid when Modal() terminates. (And we need to retrieve the 'filePath')
This will be fixed when we improve eC to always start reference count
at 1 and decrease them at the end of the compound block in which it
is defined. */
incref dialog;
if(dialog.Modal())
   MessageBox { text = "You chose ", contents = dialog.filePath }.Modal();
delete dialog;
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

Re: [Solved]How to use windowsShortcut.ec?

Post by samsam598 »

Updated the full source at the begining of the post.
Post Reply