Ecere SDK/eC Forums
Print view

[Solved]How to use
Page 1 of 1
Author:  samsam598 [ Mon Aug 22, 2011 4:51 am ]
Post subject:  [Solved]How to use

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 error: Couldn't open obj/release.win32\windowsShortcut.sym 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);
         return true;
Form1 form1 {};
Author:  jerome [ Mon Aug 22, 2011 7:42 am ]
Post subject:  Re: How to use

1. You need to add 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
Author:  samsam598 [ Mon Aug 22, 2011 7:29 pm ]
Post subject:  Re: How to use

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.
Author:  jerome [ Mon Aug 22, 2011 9:14 pm ]
Post subject:  Re: How to use

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.


Author:  samsam598 [ Mon Aug 22, 2011 9:31 pm ]
Post subject:  Re: How to use

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.

Author:  jerome [ Mon Aug 22, 2011 9:59 pm ]
Post subject:  Re: How to use

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 };

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;
   MessageBox { text = "You chose ", contents = dialog.filePath }.Modal();
delete dialog;
Author:  samsam598 [ Fri Sep 16, 2011 2:25 am ]
Post subject:  Re: [Solved]How to use

Updated the full source at the begining of the post.
All times are UTC-05:00 Page 1 of 1