Solved

Dev-C++ - Dialog Boxes

Posted on 2004-10-01
10
4,849 Views
Last Modified: 2007-11-27
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.
0
Comment
Question by:tim102096
10 Comments
 
LVL 1

Expert Comment

by:mikrotuho
ID: 12201915
I think you need to include the windows.h file at the beginning:

#include <windows.h>
0
 
LVL 30

Expert Comment

by:Axter
ID: 12202171
Please post the exact errors you're getting
0
 
LVL 3

Expert Comment

by:allsc
ID: 12202272
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
 

Author Comment

by:tim102096
ID: 12218385
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
 

Author Comment

by:tim102096
ID: 12218416
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:tim102096
ID: 12218609
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
 
LVL 1

Expert Comment

by:mikrotuho
ID: 12224003
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
 

Author Comment

by:tim102096
ID: 12227916
I am willing to offer another 500 to 2500 points for the answer to this question.
0
 

Author Comment

by:tim102096
ID: 12238835
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
 
LVL 12

Accepted Solution

by:
OnegaZhang earned 500 total points
ID: 12316451
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now