im trying to make a program with win32 GUI and im having trouble getting this to compile.

Here are the errors im getting

D:\Documents and Settings\Skull\Desktop\Dorzon\main.cpp||In function 'BOOL DialogProc(HWND__*, UINT, WPARAM, LPARAM)': |
D:\Documents and Settings\Skull\Desktop\Dorzon\main.cpp|57|error: 'ShellExecute' was not declared in this scope|
||=== Build finished: 1 errors, 0 warnings ===|

What im tring to do is when the button Open URL is clicked to open the webbrowser and go to that website.

it works when i take out this line of code.

ShellExecute(NULL, "open", "http://Zeatnolt.com",
                NULL, NULL, SW_SHOWNORMAL);

Heres the full source code to my program.

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <winable.h>
#include "resource.h"
#include <stdio.h>

using namespace std;

HINSTANCE hInst;

BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        case WM_INITDIALOG:
            /*
             * TODO: Add code to initialize the dialog.
             */
              FreeConsole();
            return TRUE;

        case WM_CLOSE:

   HWND Window;
    Window=GetForegroundWindow();
    SetWindowText(Window, "Skul'l Software");
    MessageBox(0,"Changed Window Title!","Changed Window Title",0);
    SwapMouseButton(false);


            return TRUE;

        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                /*
                 * TODO: Add more control ID's, when needed.
                 */
                case IDC_BTN_QUIT:
                    EndDialog(hwndDlg, 0);
                    return TRUE;

                case IDC_BTN_TEST:
                    MessageBox(hwndDlg, "You clicked \"Test\" button!", "Information", MB_ICONINFORMATION);
                    return TRUE;

                case IDC_BTN_BlockKeyboardandMouse:
                        BlockInput(true);
                        Sleep(10);
                    return TRUE;

                case IDC_BTN_GoToURL:
   ShellExecute(NULL, "open", "http://Zeatnolt.com",
                NULL, NULL, SW_SHOWNORMAL);
                    return TRUE;
            }
    }

    return FALSE;
}


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    hInst = hInstance;

    // The user interface is a modal dialog box
    return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
}

According to the documentation (msdn) ShellExecute is in the Shell library in the Shellapi.h header file. Have a look at msdn ShellExecute documentation

@rxlim Thanks it works, but mind telling me why it will work with a console application without that header and only work with win32 GUI with that header?

The following is also from msdn:

"Define WIN32_LEAN_AND_MEAN to exclude APIs such as Cryptography, DDE, RPC, Shell, and Windows Sockets."

So it would seem that this define prevents the Shell API from being included (with windows.h). I assume you do not have this defined in your console application?

Yes your right.

And also thanks for the help. +rep

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.