Dev-C++ - Dialog Boxes

Im using Dev-C++ 4.9.9.0 This version can use resources and can compile them as well as use events with the resources (ive tested and got the menus to work).
The problem is i cant figure out why it wont compile this code:

#include "no.rh"

ABOUTDLG 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", IDOK22, 130, 10, 50, 14
END

 
AppMenu MENU
BEGIN
   POPUP "&File"
   BEGIN
      MENUITEM "E&xit", CM_FILE_EXIT
   END
   POPUP "&Stuff"
   BEGIN
      MENUITEM "&Go", CM_STUFF_GO
      MENUITEM "G&o somewhere else", 0, GRAYED
   END
END

It flags the dialog box definement, the menus work fine.
First it flags:
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
then if i comment that out it flags the pushbutton.
tim102096Asked:
Who is Participating?
 
OnegaZhangConnect With a Mentor Commented:
It is fine in my case.
create a window project containing the following 3 files
open project options--> Files,  select untitled2.rc, check "Include in compilation"
then it is OK!
1.   I create no.h as
#ifndef _NO_RH
#define _NO_RH
#define CM_FILE_EXIT 9001
#define CM_STUFF_GO 9002
#define  ABOUTDLG 6000
#define  AppMenu 6001
#endif

2. create untitled2.rc as
#include <windows.h>
#include "no.h"
ABOUTDLG 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

 
AppMenu MENU
BEGIN
   POPUP "&File"
   BEGIN
      MENUITEM "E&xit", CM_FILE_EXIT
   END
   POPUP "&Stuff"
   BEGIN
      MENUITEM "&Go", CM_STUFF_GO
      MENUITEM "G&o somewhere else", 0, GRAYED
   END
END
3. main.cpp as
#include <windows.h>
#include "no.h"
/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsApp";

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);
            return TRUE;
            case IDCANCEL:
               EndDialog(hwnd, IDCANCEL);
            return TRUE;
         }
      break;
   }
   return FALSE;
}
void ShowDlg(HINSTANCE hInstance,HWND hwnd)
{
    int ret;
  ret = DialogBox(hInstance, "ABOUTDLG",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);
      }  
}

HINSTANCE hInst;
int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */
    hInst = hThisInstance;
    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;
HMENU menu = LoadMenu(hThisInstance, MAKEINTRESOURCE(AppMenu));
    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Windows App",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           menu,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
        ShowWindow (hwnd, nFunsterStil);
   
    //SetMenu(hwnd, menu);


    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        case WM_COMMAND:
           switch( wParam )
           {
               case CM_STUFF_GO:
                   ShowDlg(hInst, hwnd);
                   break;
           }
           break;                
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

welcome to www.fruitfruit.com
0
 
mikrotuhoCommented:
I think you need to include the windows.h file at the beginning:

#include <windows.h>
0
 
AxterCommented:
Please post the exact errors you're getting
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
allscCommented:
Yes post the error please also make sure you have the window.h file included which I think you do cause you are getttng the menu to work and I asume it is include in the #include "no.rh" file.Also you have a mistake here that could be giving you a error


DEFPUSHBUTTON   "OK", IDOK22, 130, 10, 50, 14//This line here should be

DEFPUSHBUTTON   "OK", IDOK, 130, 10, 50, 14//should be

Also make sure ABOUTDLG is define etc.Like so

 #define  ABOUTDLG 6000
0
 
tim102096Author Commented:
Resource Compiler Output:

4 H:\C++ IDE\bin\Dev-Cpp\Proj\res.rc [Resource error] parse error
 
H:\C++ IDE\bin\Dev-Cpp\Proj\Makefile.win [Build Error]  [Project1_private.res] Error 1

I added the #define to the top of the program.
Compiler output:

Compiler: Default compiler
Building Makefile: "H:\C++ IDE\bin\Dev-Cpp\Proj\Makefile.win"
Executing  make...
make.exe -f "H:\C++ IDE\bin\Dev-Cpp\Proj\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"H:/C++ IDE/bin/Dev-Cpp/include/c++/3.3.1"  -I"H:/C++ IDE/bin/Dev-Cpp/include/c++/3.3.1/mingw32"  -I"H:/C++ IDE/bin/Dev-Cpp/include/c++/3.3.1/backward"  -I"H:/C++ IDE/bin/Dev-Cpp/lib/gcc-lib/mingw32/3.3.1/include"  -I"H:/C++ IDE/bin/Dev-Cpp/include"  

windres.exe -i Project1_private.rc -I rc -o Project1_private.res -O coff

windres.exe: res.rc:4: parse error

make.exe: *** [Project1_private.res] Error 1

Execution terminated


THE no.rh file has the following:

#define CM_FILE_EXIT 9001
#define CM_STUFF_GO 9002


Im still getting the same errors, I also fixed the IDOK22 thing.
0
 
tim102096Author Commented:
Ok i added the include for windows.h and i get a different error.

  [Resource error] can't open font file `char*': Invalid argument
  H:\C++ IDE\bin\Dev-Cpp\Proj\Makefile.win [Build Error]  [Project1_private.res] Error 1
0
 
tim102096Author Commented:
Im also having a problem initializing the dialog. If i comment out the two lines that cause errors (The style code line and the button code line), The dialog still wont initialize. Heres the basic dialog code:

void ShowDlg(HINSTANCE hInstance,HWND hwnd)
{
    int ret;
  ret = DialogBox(hInstance, "ABOUTDLG",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);
      }  
}

Im passing the Application instance from the Winmain and the Hwnd from the window creation of the main app, to this function.

If it helps heres the AboutDlg proc:

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);
            return TRUE;
            case IDCANCEL:
               EndDialog(hwnd, IDCANCEL);
            return TRUE;
         }
      break;
   }
   return FALSE;
}
0
 
mikrotuhoCommented:
Methinks that you need to add WS_VISIBLE to your styles if you want to see your dialog box. But if you need to comment that line out to get the program to compile then the problem is somewhere else.
0
 
tim102096Author Commented:
I am willing to offer another 500 to 2500 points for the answer to this question.
0
 
tim102096Author Commented:
Unless by some far doubt dev-c++ doesn't support it? I know it suppports some resources but maybe doesnt have full dialog support? How can i fix this? do i get another resource compiler? Get the newest Gnu compiler?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.