Drag and Drop onto console app

D

Daz

Hi all.

I would like to make a console application, where I can drag, say, a
text file, onto the exe itself, and the console window will popup and
tell me what file was dragged onto the exe, (if it's even possible).

Would anyone know which route to take? If I need to use MFC or
something, than I will try this another time when I start learning
about MFC scripting. Hopefully there is a simple way that I am unaware
of.

Best wishes

Daz
 
P

Phlip

Daz said:
I would like to make a console application, where I can drag, say, a
text file, onto the exe itself, and the console window will popup and
tell me what file was dragged onto the exe, (if it's even possible).

Would anyone know which route to take? If I need to use MFC or
something, than I will try this another time when I start learning
about MFC scripting. Hopefully there is a simple way that I am unaware
of.

First, learn C++ before MFC, and don't bother with learning MFC. If you must
write windowing applications, use WTL.

Next, we don't script here we compile.

Next, nearly the first thing your C++ tutorial will teach is the arguments
to main. Google "main argc argv" to get plenty of samples.

Next, your OS (which might just possibly be Windows) knows to convert a drop
into a filename in argv[1], but the details are off-topic for this
newsgroup. We only know about the raw C++ language itself here. So main(int,
char**) is on-topic, but dragging, dropping, MFC, and such are all
off-topic.

Use Google Groups to find the best newsgroup for your next question!
 
D

Daz

Thanks for the reply Philip! Much appreciated! :)

I will most certainly look into WTL, as I am fed up with every turn I
take leading right back to Microsoft. However, after saying that, most
of the programs I would write would are likely to be for Windows
machines, purely because I don't know anywhere near enough about
non-windows systems as I should, and I believe that most of that will
take years to learn. I will learn it eventually, but don't wan't to get
distracted from the basics for now.

Thanks again.

Daz
Daz said:
I would like to make a console application, where I can drag, say, a
text file, onto the exe itself, and the console window will popup and
tell me what file was dragged onto the exe, (if it's even possible).

Would anyone know which route to take? If I need to use MFC or
something, than I will try this another time when I start learning
about MFC scripting. Hopefully there is a simple way that I am unaware
of.

First, learn C++ before MFC, and don't bother with learning MFC. If you must
write windowing applications, use WTL.

Next, we don't script here we compile.

Next, nearly the first thing your C++ tutorial will teach is the arguments
to main. Google "main argc argv" to get plenty of samples.

Next, your OS (which might just possibly be Windows) knows to convert a drop
into a filename in argv[1], but the details are off-topic for this
newsgroup. We only know about the raw C++ language itself here. So main(int,
char**) is on-topic, but dragging, dropping, MFC, and such are all
off-topic.

Use Google Groups to find the best newsgroup for your next question!
 
D

Daz

Phlip said:
First, learn C++ before MFC, and don't bother with learning MFC. If you must
write windowing applications, use WTL.

Aaah. My bad. WTL is not cross platform, it's windows specific. My
apologies for jumping the gun. :)

I am reading an article which describes it as being 'MFC on
template-based steroids'. It looks VERY usefule indeed!

Many thanks for the recommendation.

Daz
 
D

Daz

Marcus said:
Thanks for that Marcus, it really helped. I suspected that it would
work like that, I think the problem I am having is with pointers.

int main(int argc, char *argv[])
{
char *p[] = *argv;
cout << argv << endl;
cout << p << endl;
return 0;
}

I would like for p to point to the same location as the *argv pointer.
Please could someone point out where I am going wrong? I get the error
message:
"Cannot convert from 'char *'[] to 'char *[]'"

I have tried absolutely every other possible combination _I_ can think
if, and I can't figure it out.

I orginally thought:

char *p; //declare a pointer of type 'char
p = *argv; // set p to point to the same address as *argv

But I was clearly wrong.

argv[1] returns C:\test.txt
but p[1] returns ':'
 
D

Daz

Marcus said:
Thanks for that Marcus, it really helped. I suspected that it would
work like that, I think the problem I am having is with pointers.

int main(int argc, char *argv[])
{
char *p[] = *argv;
cout << argv << endl;
cout << p << endl;
return 0;
}

I would like for p to point to the same location as the *argv pointer.
Please could someone point out where I am going wrong? I get the error
message:
"Cannot convert from 'char *'[] to 'char *[]'"

I have tried absolutely every other possible combination _I_ can think
if, and I can't figure it out.

I orginally thought:

char *p; //declare a pointer of type 'char
p = *argv; // set p to point to the same address as *argv

But I was clearly wrong.

argv[1] returns C:\test.txt
but p[1] returns ':'
 
M

Marcus Kwok

Daz said:
Marcus said:
Thanks for that Marcus, it really helped. I suspected that it would
work like that, I think the problem I am having is with pointers.

int main(int argc, char *argv[])
{
char *p[] = *argv;
cout << argv << endl;
cout << p << endl;
return 0;
}

I would like for p to point to the same location as the *argv pointer.

I'm not quite sure what you mean by this, but see below.
Please could someone point out where I am going wrong? I get the error
message:
"Cannot convert from 'char *'[] to 'char *[]'"

On mine, I get "cannot convert from 'char *' to 'char *[]' (note that
the [] are missing from the first 'char *').
I have tried absolutely every other possible combination _I_ can think
if, and I can't figure it out.

I orginally thought:

char *p; //declare a pointer of type 'char
p = *argv; // set p to point to the same address as *argv

But I was clearly wrong.

argv[1] returns C:\test.txt
but p[1] returns ':'

When you do this, argv[1] = "C:\test.txt", and (*p) = "C:\test.txt"
also. When you do p[1], that returns the second character of p, which
is indeed ':'.


Did you want something like this?

#include <iostream>

int main(int argc, char* argv[])
{
for (int i = 1; i < argc; ++i) {
char* p = argv;
std::cout << p << '\n';
}
}
 
D

Daz

Hi Marcus!

Marcus said:
Did you want something like this?

#include <iostream>

int main(int argc, char* argv[])
{
for (int i = 1; i < argc; ++i) {
char* p = argv;
std::cout << p << '\n';
}
}


Yes, that's exactly what I wanted. I guess I will just have to make a
function to tokenize the words for me. No problems there, I just don't
know why I never thought of it in the first place...

Thanks for your input Marcus. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top