C++ and WinAPI?

This is a discussion on C++ and WinAPI? within the C++ Programming forums, part of the General Programming Boards category; Hello All, I'm after a bit of advice... I want to write a windows program capable of the following: start ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    4

    Question C++ and WinAPI?

    Hello All,

    I'm after a bit of advice...

    I want to write a windows program capable of the following:

    start notpad
    write some predetermined text to notepad
    let the user edit the text in notpad
    read the text back from notpad
    end notepad

    I'm assuming that the way to go is C++ and WinAPI calls, but I'm open to suggestions. I am reasonably familiar with C, but not very with C++ or the WinAPI calls yet. Has anyone done something like this before who can give me a few pointers?

    thanks in advance
    Matthew

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    start notpad
    write some predetermined text to notepad
    let the user edit the text in notpad
    read the text back from notpad
    end notepad
    Well an easier way would be to do steps in this order 2,1,3,5,4

    IE...
    • Write whatever to a standard Text file
    • Open the file in notepad with ShellExecute()
    • Let the user edit or whatever
    • Close notepad (this would be the trickiest part but its do-able with some WinAPI calls, but I dont know how you'd save the text)
    • Read the info from the text file


    The only thing is....what are you trying to do........it sounds like a basic form of edit window........ IMHO using notepad is not the best way forward for this.........

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    4

    Wink

    Wow - didn't expect a response so soon!

    Thanks for the info Fordy.

    What I'm trying to do is make a fairly generic shell program, I'm just using notepad as a starting example. Theoretically, once I get it working for notepad, I should be able to modify it to run Word/Excel/Access and other windows programs (I'm assuming).

    regards Matthew

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    49
    start notpad
    write some predetermined text to notepad
    predetermined how ? is it text in a file ?
    let the user edit the text in notpad
    do you mean change it ?
    read the text back from notpad
    ??
    end notepad
    closing it or through the program ?

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    49
    Do you mean something like :

    #include <stdlib.h>

    int main(void)
    {
    system("C:\\WINDOWS\\notepad.exe myfile.txt");
    return 0;
    }

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> modify it to run Word/Excel/Access and other windows programs

    I don't know how far into the topic you are, but programs like Word, Excel and Access are written to be controlled by other programs via "Object Linking and Embedding", OLE for short, (sometimes OLE Automation, or simply automation). You might want to research that a bit, it will save you a lot of work.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    4
    Hello GertFaller,

    In answer to your posts (my answers are in italics):
    __________________________________________________
    start notepad
    write some predetermined text to notepad
    predetermined how ? is it text in a file ? Yes
    let the user edit the text in notepad
    do you mean change it ? Yes
    read the text back from notepad
    ?? I want to be able to store the changed/edited text in a file
    end notepad
    closing it or through the program ? through the program
    __________________________________________________ _
    Do you mean something like :

    #include <stdlib.h>

    int main(void)
    {
    system("C:\\WINDOWS\\notepad.exe myfile.txt");
    return 0;
    }

    This would certainly start notepad with the contents of myfile.txt, and allow the user to edit. However, I am trying to write a fairly flexible shell, and am only using notepad as an example application. (If I can get it working for notepad, then other windows applications should be possible).

    So I suppose I need to write generic routines to:
    start a windows application
    write text to a windows application
    read text from a windows application
    save text to disk
    end a windows application

    regards, Matthew

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    So I suppose I need to write generic routines to:
    start a windows application
    write text to a windows application
    read text from a windows application
    save text to disk
    end a windows application
    Oh right......I think im getting closer to what you want.....I guess you are looking for some sort of Automation....

    I once wrote a Visual Basic routine that opened a specific word document and populated it with information for a mail merge.......

    I could then save, print, close whatever.......this is quite easy to do with M$ Office and VBA (Hell I know very little VB, but managed this with the help of MSDN and a little experementation), but with C/C++ it would be really hard as adrain has already said.

    If you want to limit your work to M$ Office, then VBA is a good alternative.

  9. #9
    Registered User
    Join Date
    Jan 2002
    Posts
    4

    Thumbs up

    Thanks Adrianxw and Fordy

    I will look at VBA - I've had a bit of a play with it in the past (macros in Word etc). I'm not sure I will want to limit myself to M$ Office in the long run, but it will certainly take care of my immediate needs.

    regards, Matthew

  10. #10
    UNBANNED OneStiffRod's Avatar
    Join Date
    Jan 2002
    Posts
    669
    There are three fxn's that I know of that can open window programs. All, I believe, are accessible by inserting windows.h into your program.

    The 1st one is the easiest but I think it's been deleted from the newer (XP) platform specs - so it won't work on those machines:

    ShellExecute(); //Obsolete

    there's a 2nd that I don't recall the name of that is probably the one your gonna use since it is the 2nd easiest(look up shellexecute() on MSDN.MICROSOFT.com and it'll probably point you to this fxn).

    the last one is the doozy - CreateProcess(). This is the one I have used but it is complicated to use and there are other structures that must be used inside of it's parameter list. This one is the one they want you to use to start up window programs but sooey - it's a ***** to get it to do what you want it to do.
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21