- #include <windows.h>
-
- #include "resource.h"
-
- HWND hed_exe;
- HWND hed_file;
-
- int __stdcall OpenFileWithExe()
- {
- char szbuff[1024];
- char szexe[1024];
- char szfile[1024];
-
- SECURITY_ATTRIBUTES saAttr;
- BOOL fSuccess;
- HANDLE hPipeLecture, hPipeEcriture;
-
- GetWindowText(hed_exe, (char*)&szexe, 1024);
- GetWindowText(hed_file, (char*)&szfile, 1024);
-
- wsprintf((char*)&szbuff, """%s"" %s", (char*)&szexe, (char*)&szfile);
-
- saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
- saAttr.bInheritHandle = TRUE;
- saAttr.lpSecurityDescriptor = NULL;
-
- // On créer la pipe
- if (! CreatePipe(&hPipeLecture, &hPipeEcriture, &saAttr, 0))
- return 1;
-
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
-
- ZeroMemory( &si, sizeof(si) );
- si.cb = sizeof(si);
- si.hStdOutput = hPipeEcriture;
- ZeroMemory( &pi, sizeof(pi) );
-
- if( !CreateProcess( NULL,
- (char*)&szbuff,
- NULL,
- NULL,
- FALSE,
- CREATE_NEW_PROCESS_GROUP,
- NULL,
- NULL,
- &si,
- &pi )
- )
- {
- return 1;
- }
-
- CloseHandle( pi.hProcess );
- CloseHandle( pi.hThread );
-
- return 0;
- }
-
- BOOL CALLBACK AppDlgProc(HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam)
- {
- switch(mssg) {
- case WM_INITDIALOG:
- SetClassLong(hdlg, GCL_HICON, (long)LoadIcon(0, IDI_APPLICATION));
- hed_exe = GetDlgItem(hdlg, IDC_PATHEDIT);
- hed_file = GetDlgItem(hdlg, IDC_PATHFILE);
- return 1;
- case WM_COMMAND:
- switch(wParam) {
- case IDC_OUVRIR:
- if (OpenFileWithExe() != 0)
- MessageBox(hdlg, "Une erreur s'est produit lors de l'ouverture du fichier.", "Erreur", 0x40);
- return 1;
-
- case IDCANCEL: EndDialog(hdlg, 0);
- }
- }
-
- return 0;
- }
-
- int WINAPI WinMain(HINSTANCE hinst, HINSTANCE, PSTR, int)
- {
- DialogBoxParam(hinst, (LPCTSTR)IDD_APP, 0, AppDlgProc, 0);
-
- return 0;
- }
#include <windows.h>
#include "resource.h"
HWND hed_exe;
HWND hed_file;
int __stdcall OpenFileWithExe()
{
char szbuff[1024];
char szexe[1024];
char szfile[1024];
SECURITY_ATTRIBUTES saAttr;
BOOL fSuccess;
HANDLE hPipeLecture, hPipeEcriture;
GetWindowText(hed_exe, (char*)&szexe, 1024);
GetWindowText(hed_file, (char*)&szfile, 1024);
wsprintf((char*)&szbuff, """%s"" %s", (char*)&szexe, (char*)&szfile);
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;
// On créer la pipe
if (! CreatePipe(&hPipeLecture, &hPipeEcriture, &saAttr, 0))
return 1;
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
si.hStdOutput = hPipeEcriture;
ZeroMemory( &pi, sizeof(pi) );
if( !CreateProcess( NULL,
(char*)&szbuff,
NULL,
NULL,
FALSE,
CREATE_NEW_PROCESS_GROUP,
NULL,
NULL,
&si,
&pi )
)
{
return 1;
}
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return 0;
}
BOOL CALLBACK AppDlgProc(HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam)
{
switch(mssg) {
case WM_INITDIALOG:
SetClassLong(hdlg, GCL_HICON, (long)LoadIcon(0, IDI_APPLICATION));
hed_exe = GetDlgItem(hdlg, IDC_PATHEDIT);
hed_file = GetDlgItem(hdlg, IDC_PATHFILE);
return 1;
case WM_COMMAND:
switch(wParam) {
case IDC_OUVRIR:
if (OpenFileWithExe() != 0)
MessageBox(hdlg, "Une erreur s'est produit lors de l'ouverture du fichier.", "Erreur", 0x40);
return 1;
case IDCANCEL: EndDialog(hdlg, 0);
}
}
return 0;
}
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE, PSTR, int)
{
DialogBoxParam(hinst, (LPCTSTR)IDD_APP, 0, AppDlgProc, 0);
return 0;
}