I need to know a way to open a notepad document from one of my programs without opening a console window. The calling program is a standard window, so it would look bad if a console widow opened. There are a couple of things you should be aware of as well. I have already tried system("call ..."), which opens the console, and also, I can't include windows.h due to conflicting class names. Please help.

So add a new source file to your project called runner.cpp

All this does, is
- include windows.h
- implements a thin wrapper, say myRunner() round say CreateProcess()
- and returns

runner.h just contains the prototype of myRunner(), which in itself is NOT dependent on windows.h

Include runner.h when you want to run something.

Write and compile it as a Windows program (without a window), you could use the fstream classes for file I/O :)

Um, unless i'm not doing it right, it still comes up with the same conflicting definitions errors. Here's the code:

#ifndef  RUNNER_CPP
#define  RUNNER_CPP

#include <windows.h>

void run()
{
    CreateProcess(<parameters here>);
}

#endif //RUNNER_CPP

Oh, by the way tux4life, I don't want to open it for i/o. I just want the user to be able to read it. It's kind of like a help file.

>>I need to know a way to open a notepad document from one of my programs without opening a console window.
>>Oh, by the way tux4life, I don't want to open it for i/o. I just want the user to be able to read it. It's kind of like a help file.

You cannot read a file without using I/O techniques :P

Actually you need I/O (but only the input part then): you have to read out the notepad document and display it on the screen right?

Oh sorry, I think I know what you mean: You want to open a notepad file in notepad without a command line popping up ...

Maybe you could try posting your errors.

> Um, unless i'm not doing it right, it still comes up with the same conflicting definitions errors. Here's the code:
That looks for all the world like you just created a new .cpp file, then right away did
#include "runner.cpp"
in some other module.

Read my post again, that is NOT what I told you to do.

Oh sorry, I think I know what you mean: You want to open a notepad file in notepad without a command line popping up ...

Correct.

What I did was create a new file (actually .h not .cpp. I don't know why I put _CPP.) and put that code in it. I then linked it to my project and included it in my main file. Where am I going wrong?

You need a separate source file as well.

So that windows.h and all your conflicting headers do NOT appear in the same .cpp file.

Place this function into the separate .cpp file:

void ShowText(const char* filename)
{
    ::ShellExecuteA(::GetDesktopWindow(),
        "open",
        "notepad.exe",
        filename,
        0,
        SW_SHOWNORMAL);
}

Include <windows.h> dependency into this file only.
This function works in console applications too.

commented: Good job! +5

It works great! Thanks!:)

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.