Hi,

I want to write code for opening an external file or program from the C program.Could anyone tell me how to do this?

Say if I want to open calculator.exe I mention the path in the program and it should open it or say if I want to open "image.jpg" with the default program...How shall I do this?

Any sample code would be of great help.

Thanks in advance

Recommended Answers

All 6 Replies

call win32 api function ShellExecute


More here

call win32 api function ShellExecute


More here

//example of ShellExecute Function

#include <shellapi.h>

#pragma comment(lib,"shell32.lib") 

static HWND hBut; 

switch (message) 

{

case WM_CREATE: 

hBut = CreateWindow(TEXT(

"button"),TEXT("button"),WS_VISIBLE|WS_CHILD,100,100,100,100,hWnd,(HMENU)1,NULL,NULL); 

case WM_COMMAND: 

switch(LOWORD(wParam)){ 

case 1: 

LoadLibrary(TEXT("shell32.dll")); 

ShellExecute(hWnd,TEXT("open"), TEXT("http://www.rsdn.ru"), TEXT(""),NULL,SW_SHOWNORMAL); 

}

If I have to use shell execute not in MFC but like a simple function call without using the hWnd etc..how shall i?

line 25 is not necessary. You don't have to specifically load win32 api DLLs.


>>If I have to use shell execute not in MFC
I didn't ask you to use MFC -- MFC has nothing to do with ShellExecute function. Had you bothered to read the link I gave you, you would have seen that the first parameter can be NULL.

ok fine...will try and get back

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.