Results 1 to 6 of 6

Thread: Een ander programma laden met een Delphi programmatje ?

  1. #1
    Registered User
    Join Date
    Jul 2001
    Location
    Belgie
    Posts
    7

    Question Een ander programma laden met een Delphi programmatje ?

    Ik ben een programmatje aan het schrijven om van al die pictogrammen op mijn desktop af te zijn. De bedoeling is om alle directory namen in een drop down menu (of zoiets) te steken en de programma's van daaruit laden met een 'start' knop, dus alle pictogrammen (behalve Mijn Computer en Prullenbak) worden herleid tot 1 pictogram. Mijn vraag is echter : hoe vertel ik het programma, dat hetgeen geselecteerd is in het menu een programma is dat hij moet laden als je op de 'start' knop duuwt ?? (want alle elementen uit een drop down menu zijn strings)

    Ik hoop dat iemand verstaat wat ik bedoel, want hier heb ik al lang op gezocht

    Alvast bedankt

    Bert.

  2. #2
    Registered User
    Join Date
    Jul 2001
    Location
    enschede
    Posts
    2
    als ik het goed heb begrepen dan wil je gewoon een programma opstarten met alleen een directory path ernaartoe!?

    nou als dat zo is dan is het welte doen .. namelijk met de api call

    Bool CreateProcess();

    de opties zijn heel makkelijk ..

    function CreateProcessSimple(
    sExecutableFilePath : string )
    : string;
    var
    pi: TProcessInformation;
    si: TStartupInfo;
    begin
    FillMemory( @si, sizeof( si ), 0 );
    si.cb := sizeof( si );

    CreateProcess(
    Nil,

    // path to the executable file:
    PChar( sExecutableFilePath ),

    Nil, Nil, False,
    NORMAL_PRIORITY_CLASS, Nil, Nil,
    si, pi );

    // "after calling code" such as
    // the code to wait until the
    // process is done should go here

    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );
    end;

    een voorbeeld .. als je notepad wil starten doe je dat zo

    CreateProcessSimple( 'notepad' );

    de .exe extensie kan weg gelaten worden want dit neemt windows automatisch aan .. opties kunnen ook worden meegegeven .. gewoon in de string zetten ..

    CreateProcessSimple( 'notepad readme.txr' );

    zo word het bestand readme geopend ..

    hope this helps
    jillis

  3. #3
    Boi Bert/Bruce,

    CreateProcess geeft inderdaad veel mogelijkheden, maar heeft ook een eenvoudiger broertje: ShellExecute. Om een bestand (programma of document) te openen gebruik je de volgende syntax:
    Code:
    ShellExecute(Handle, "open", PChar(FileName), nil, nil, SW_SHOW)
    Het is beperkter dan CreateProcess, CreateProcess heeft bijvoorbeeld ook mogelijkheden om te wachten tot het programma weer is afgesloten, maar misschien in dit geval voldoende.
    Marcel

  4. #4
    Hallo,

    volgende functie komt van http://www.delphi3000.com/articles/article_1362.asp


    Question/Problem/Abstract:

    Ever wanted to open a .doc in Word? Or a .htm in Internet Explorer? Then you should use ShellExecute:


    uses
    ShellApi;

    function ShellOpenFile( hWnd : HWND; AFileName, AParams, ADefaultDir : string ) : integer;
    begin
    result := shellapi.ShellExecute( hWnd, 'open', pChar( AFileName ),
    pChar(AParams),
    pChar(ADefaultDir),
    SW_SHOWDEFAULT );
    case result of
    0 :
    raise Exception.Create( 'The operating system is out of memory or resources.' );
    ERROR_FILE_NOT_FOUND :
    raise Exception.Create( 'The specified file was not found.' );
    ERROR_PATH_NOT_FOUND :
    raise Exception.Create( 'The specified path was not found.' );
    ERROR_BAD_FORMAT :
    raise Exception.Create( 'The .EXE file is invalid (non-Win32 .EXE or error ' +
    'in .EXE image).' );
    SE_ERR_ACCESSDENIED :
    raise Exception.Create( 'The operating system denied access to the specified file.' );
    SE_ERR_ASSOCINCOMPLETE :
    raise Exception.Create( 'The filename association is incomplete or invalid.' );
    SE_ERR_DDEBUSY :
    raise Exception.Create( 'The DDE transaction could not be completed because ' +
    'other DDE transactions were being processed.' );
    SE_ERR_DDEFAIL :
    raise Exception.Create( 'The DDE transaction failed.' );
    SE_ERR_DDETIMEOUT :
    raise Exception.Create( 'The DDE transaction could not be completed because the ' +
    'request timed out.' );
    SE_ERR_DLLNOTFOUND :
    raise Exception.Create( 'The specified dynamic-link library was not found.' );
    SE_ERR_NOASSOC :
    raise Exception.Create( 'There is no application associated with the given ' +
    'filename extension.' );
    SE_ERR_OOM :
    raise Exception.Create( 'There was not enough memory to complete the operation.' );
    SE_ERR_SHARE :
    raise Exception.Create( 'A sharing violation occurred.' );
    else
    end;
    end;

    Usage:

    hWnd: Handle to owner window. Usually you would use self.Handle.

    AFileName: Name of file to be opened.

    AParams: Additional parameters.

    ADefaultDir: The default (working) directory.

    Examples

    // Opens applog.txt in the notepad:
    ShellOpenFile( self.Handle, 'c:\applog.txt', '', '' );

    // Opens the document in Word:
    ShellOpenFile( self.Handle, 'mydoc.doc', '', '' );

    // Opens a web page in the default browser:
    ShellOpenFile( self.Handle, 'http://www.caos.dk', '', '' );

    // Opens your default e-mail client
    ShellOpenFile( self.Handle, 'mailto:caos@caos.dk', '', '' );


    Groeten,

    Geert

  5. #5
    Registered User
    Join Date
    Jul 2001
    Location
    enschede
    Posts
    2
    hoi allemaal,

    hehe .. bert!? de naam is jillis ( bruce Willis .. flauw ik weet het maar goed je moet toch wat he! ) shellexecute is idd eenzelfde functie .. het maakt in dit geval nix uit .. welke je kiest ..

    en idd deze functie was een oploopje naar een wat meer geavanceerde CreateProces .. ik had hem nog ergens rondzwerfen ..

  6. #6
    Hoi Bert,

    Alle reply's zijn juist. Er is echter nog een kortere manier om een programmatje te starten wanneer je op een button klikt. Deze volgt hieronder:

    ------------------------------------------------------------------------
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    WinExec('c:\uwfolder\bestandsnaam.exe' , SW_SHOW);
    end;
    ------------------------------------------------------------------------

    Je moet uiteraard wel bij 'uses' , 'ShellApi' invullen.

    Ik hoop dat je hier iets aan hebt.

    Groeten,
    Danny

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 34
    Last Post: 18-Dec-03, 00:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •