0

HI,
I started to play with files in C++ and I have a little problem.
Here is my c++ project and the problem:
main.cpp

#include <iostream>
#include "resource.h"
#include <windows.h>
#include <stdio.h>
#include <fstream>

using namespace std;

int main()
{
    HRSRC hRsrc;
    hRsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_MYTEXTFILE), TEXTFILE);
    if (hRsrc == NULL) {
        printf("Not found\n");
    } else {
        printf("Found\n");
    }
    //system("notepad " + myfile);
    return 0;
}

resource.h:

#ifndef RESOURCE_H_INCLUDED
#define RESOURCE_H_INCLUDED
#define TEXTFILE 0
#define IDR_MYTEXTFILE 0

#endif // RESOURCE_H_INCLUDED

Resource.rc:

#include "resource.h"

IDR_MYTEXTFILE TEXTFILE "Demo.txt"

Now it's time to explain my problem:
I want to run Demo.txt with Nodepad using "system("notepad " + myfile_Demo.txt);"
I don't know where is Demo.txt from Resources and How can I open it.
I use Code::Blocks - Download the c++ files from end of message.
I appreciate any suggestions.
Best regards,
Diana

Edited by diana_pro: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Prosammer
0

Use Visual Studio C++ Express 2010. It's better

DL: Visaul Studio Express

#include <iostream>
#include <string>
#include <windows.h>
// using namespace std; // if u find the std:: namespace operator annoying each time

HINSTANCE g_hInstance;

int main( int argc, TCHAR **argv[], ... )
{
	std::string setPath = "C:\\Users\\YourUserNameHere\\Desktop\\Demo.txt";

	printf( "Looking for %s\n", setPath.data()/*c_str()*/ );
	Sleep( 1000 );

	while(( g_hInstance = ShellExecuteA( 0, "open", setPath.data(), 0, 0, SW_SHOW )) == 0 )
		Sleep( 100 );

	printf( "File has been found" );

	if( std::cin.get() )
		return EXIT_SUCCESS;
}

The

std::string setPath = "C:\\Users\\YourUserNameHere\\Desktop\\Demo.txt";

doesnt need to be opened from Desktop you can also just open it like this if you save your .txt file where the binary is:

std::string setPath = "Demo.txt" /*ShellExecuteA( 0, "open", "Demo.txt", 0, 0, SW_SHOW )*/

Edited by Prosammer: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.