Shellexecute help

This is a discussion on Shellexecute help within the C++ Programming forums, part of the General Programming Boards category; here is the code: Code: #include <iostream> #include <windows.h> #include <stdlib.h> #include <cstdlib> #include <string> #include <Shellapi.h> using namespace std; ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    75

    Exclamation Shellexecute help

    here is the code:
    Code:
    #include <iostream>
    #include <windows.h>
    #include <stdlib.h>
    #include <cstdlib>
    #include <string>
    #include <Shellapi.h>
    using namespace std;
    int main()
    {
    ShellExecute(m_hWnd,"open","C:\\p1.html",NULL,NULL,SW_SHOW);
    cout << " HI" << endl;
    system ("PAUSE");
    return 0;
    }
    Here are the errors:

    ------ Build started: Project: videotest, Configuration: Debug Win32 ------
    Compiling...
    videotest.cpp
    c:\documents and settings\hp_administrator\my documents\visual studio 2005\projects\videotest\videotest\videotest.cpp(10 ) : error C2065: 'm_hWnd' : undeclared identifier
    Build log was saved at "file://c:\Documents and Settings\HP_Administrator\My Documents\Visual Studio 2005\Projects\videotest\videotest\Debug\BuildLog.h tm"
    videotest - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Thank You Very Much

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,338
    m_hWnd is not declared.

    Look again at the example you got that code from. There's more to it than just running the single line of code.

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    75
    that is all that was there (it was a ***** website)

    Thanks

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,338
    Which site?

    There is an example of ShellExecute in the FAQ on this site. I think it's the FAQ that is about running another program from inside your program.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,765
    I believe that example is from a program using MFC, since MFC's CWnd class has a member m_hWnd containing the class's HWND.
    The first param for ShellExecute is the handle to a window. If you don't have any, pass NULL.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Perhaps the tutorial assumes you've been reading from the beginning, so that you're aware of such things without having to be endlessly repetitive.
    Just one of the dangers of just dipping in in the middle and assuming it will work out of the box.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Jul 2007
    Posts
    75
    I am new to C++ and I do not understand what the toutorial is saying. Can someone please post code (that shows what header files are needed as well) that will open a html document that is on my c drive named p1.

    Thank You

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,765
    The docs say a lot:
    Code:
    HINSTANCE ShellExecute(HWND hwnd,
        LPCTSTR lpOperation,
        LPCTSTR lpFile,
        LPCTSTR lpParameters,
        LPCTSTR lpDirectory,
        INT nShowCmd
    );
    Prototype of Shellexecute.
    First argument - handle to your window. If you don't have any, pass NULL.
    Operation: passing "open" will open a document, file or whatever you specify.
    File: the file you're trying to open.
    Parameters: if you try to run an application, what parameters you want to pass to it.
    Directory: Working directory.
    Last param asks how you want to file to open - how the window is to open. SW_SHOWNORMAL opens it as normal and gives it focus.

    So...
    Code:
    ShellExecute(NULL, _T("your_file_name_here"), NULL, NULL, NULL, SW_SHOWNORMAL);
    Is an example of how to use it.

  9. #9
    Registered User
    Join Date
    Jul 2007
    Posts
    75
    Code:
    #include <iostream>
    #include <windows.h>
    #include <stdlib.h>
    #include <cstdlib>
    #include <string>
    #include <Shellapi.h>
    using namespace std;
    int main()
    {
    	ShellExecute(NULL, _T("C:\\p1.html"), NULL, NULL, NULL, SW_SHOWNORMAL);	
    	cout << " HI" << endl;
    	system ("PAUSE");
    	return 0;
    }
    ------ Build started: Project: videotest, Configuration: Debug Win32 ------
    Compiling...
    videotest.cpp
    c:\documents and settings\hp_administrator\my documents\visual studio 2005\projects\videotest\videotest\videotest.cpp(10 ) : error C3861: '_T': identifier not found
    Build log was saved at "file://c:\Documents and Settings\HP_Administrator\My Documents\Visual Studio 2005\Projects\videotest\videotest\Debug\BuildLog.h tm"
    videotest - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Can someone help with this error.

    Thanks

  10. #10
    Registered User
    Join Date
    Jul 2007
    Posts
    75
    Does anyone know what is going on?

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,765
    I don't know why _T isn't defined as it should be if Windows.h is included, but you could manually include tchar.h where it's defined.

  12. #12
    Registered User
    Join Date
    Jul 2007
    Posts
    75
    The Program now compiles, but does not open the file. Here is the code:
    Code:
    #include <iostream>
    #include <windows.h>
    #include <stdlib.h>
    #include <cstdlib>
    #include <string>
    #include <tchar.h>
    #include <Shellapi.h>
    using namespace std;
    int main()
    {
    	ShellExecute(NULL, _T("C:\\p1.html"), NULL, NULL, NULL, SW_SHOWNORMAL);	
    	cout << " HI" << endl;
    	system ("PAUSE");
    	return 0;
    }

  13. #13
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,765
    My fault. I showed faulty code.
    Code:
    ShellExecute(NULL, _T("open"), _T("C:\\p1.html"), NULL, NULL, SW_SHOWNORMAL);

  14. #14
    Registered User
    Join Date
    Jul 2007
    Posts
    75
    Excellent, It now works. Thank You Very Much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Retrieving the handle of shellexecute
    By cloudy in forum Windows Programming
    Replies: 2
    Last Post: 08-21-2006, 09:01 AM
  2. ShellExecute, strange !!
    By BianConiglio in forum C Programming
    Replies: 2
    Last Post: 05-05-2004, 04:41 AM
  3. ShellExecute() string problem
    By henrikstolpe in forum Windows Programming
    Replies: 2
    Last Post: 05-21-2003, 09:54 AM
  4. ShellExecute and popups or MessageSending
    By Unregistered in forum Windows Programming
    Replies: 0
    Last Post: 01-03-2002, 08:50 AM

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