Member Avatar for Fjdd

I use visual c++ compiler 2008 express edition, because express edition doesn't support resources is it possible to make a win32 dialog box in express edition, if so how might I create one?
Thank you for reading

Is this not viable?

public:
   void theFunction()
   {
      MessageBox::Show("This is a sexy message", MessageBoxButtons::OKCancel,
         MessageBoxIcon::Asterisk);
   }

Or am I well off... I could be (I'm a total C++ novice)

You need to get a resource editor.

If you want to create it manually, here is a popular tutorial.

Member Avatar for Fjdd

To do it manually would I have to make a purchase?

Does mmcdonald's code above not work for you?

Here's a minimal, complete messagebox example that works on Win32. Does it work for you?

#include <windows.h>

INT WINAPI wWinMain(HINSTANCE hInst,
            HINSTANCE hPrevInst,
            LPWSTR lpCmdLine,
            INT nShowCmd)

{
    int nResult=MessageBox(NULL,
            "An example of Cancel,Retry,Continue",
            "Hello Message Box!",
            MB_ICONERROR|MB_ABORTRETRYIGNORE);

    return 0;
}
Member Avatar for Fjdd

I would like a dialog box not a message box, thanks for the rep

Member Avatar for Fjdd

This is what I'm having trouble with, I don't know how to open a .rc file, thanks for the reply :)

didn't you read the tutorial I provided???

To do it manually would I have to make a purchase?

No.

Member Avatar for Fjdd

Express edition isn't able to open .rc files so will I have to buy vc++ professional to have acsess to this feature? Thanks for the reply.

.rc files are plain text files. You can open them with any text editor. For example, notepad. They're just plain text. In the last link I gave, the plain text .rc file contains this:

#include "Resource.h"

IDD_DLGFIRST DIALOG 260, 200, 188, 95
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Win32 Programming"
FONT 8, "MS Shell Dlg"
BEGIN
    DEFPUSHBUTTON   "OK", IDOK, 130, 10, 50, 14
END

It's just plain text.

Member Avatar for Fjdd

So did you have to add an .rc extension or could it be just .txt?

Member Avatar for Fjdd

??:)

Member Avatar for Fjdd

I have followed WinProg dialog box tutorial, and I'm getting this error:
error C2065: 'AboutDlgProc' : undeclared identifier
Here is the code:

Main.cpp:

#include <windows.h>
#include "resource.h"
const char g_szClassName[] = "myWindowClass";



LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    HDC hdc;
    PAINTSTRUCT ps;
    RECT rect;
    HMENU hMenu;
    HMENU ShMenu;
    case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
    case WM_CREATE:
        hMenu = CreateMenu();
ShMenu = CreatePopupMenu();
AppendMenu(ShMenu,MF_STRING|MF_POPUP,ID_HELP_ABOUT,"&About");
AppendMenu(hMenu,MF_STRING|MF_POPUP,(UINT)ShMenu,"&Help");
SetMenu(hwnd,hMenu);
break;

            SetMenu(hwnd,hMenu);
        break;
    case WM_COMMAND:
    switch(LOWORD(wParam))
    {
        case ID_HELP_ABOUT:
        {
            int ret = DialogBox(GetModuleHandle(NULL), 
                MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
            if(ret == IDOK){
                MessageBox(hwnd, "Dialog exited with IDOK.", "Notice",
                    MB_OK | MB_ICONINFORMATION);
            }
            else if(ret == IDCANCEL){
                MessageBox(hwnd, "Dialog exited with IDCANCEL.", "Notice",
                    MB_OK | MB_ICONINFORMATION);
            }
            else if(ret == -1){
                MessageBox(hwnd, "Dialog failed!", "Error",
                    MB_OK | MB_ICONINFORMATION);
            }
        }
        break;
        // Other menu commands...
    }
break;
    case WM_PAINT:
            hdc = BeginPaint(hwnd, &ps);
            GetClientRect(hwnd,&rect);

            EndPaint(hwnd,&ps);
            return 0;

    case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}
BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    switch(Message)
    {
        case WM_INITDIALOG:

        return TRUE;
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case IDOK:
                    EndDialog(hwnd, IDOK);
                break;
                case IDCANCEL:
                    EndDialog(hwnd, IDCANCEL);
                break;
            }
        break;
        default:
            return FALSE;
    }
    return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;


    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }


    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "Draw Test",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 1000, 700,
        NULL, NULL, hInstance, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);


    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}

.rc File:

#include <windows.h>
#include "resource.h"
IDD_ABOUT DIALOG DISCARDABLE  0, 0, 239, 66
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "My About Box"
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON   "&OK",IDOK,174,18,50,14
    PUSHBUTTON      "&Cancel",IDCANCEL,174,35,50,14
    GROUPBOX        "About this program...",IDC_STATIC,7,7,225,52
    CTEXT           "An example program showing how to use Dialog Boxes\r\n\r\nby theForger",
                    IDC_STATIC,16,18,144,33
END

resource.h:

#define ID_HELP_ABOUT 101
#define IDD_ABOUT 102

Thankyou for the Help, and thank you for reading :)

AboutDlgProc is something you are trying to pass into a function on line 35. However ,at that point the compiler has never heard of it because you do not create it until line 68. In C++, if you want to use something, the compiler must know it exists before you try to use it.

Member Avatar for Fjdd

I have fixed that problem by moving AboutDialogProc to the top but now ret = -1 and I'm getting dialog failed messsage box.
thanks for the reply :)

Member Avatar for Fjdd

?? :)

Member Avatar for Fjdd

Is my question too difficult?

Member Avatar for Fjdd

I've done it, Thanks to everyone on this thread.

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.