Thread: Resource file

  1. #1
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321

    Resource file

    hii have been reading a few tutorials and come to one where i have been taught to create a dialog box, but when i compiles it, a few errors came up:

    Code:
     C:\Documents and Settings\Ross\My Documents\C++\Windows Programs\main.cpp In function `BOOL AboutDlgProc(HWND__*, unsigned int, unsigned int,  long int)': 
    
    85 C:\Documents and Settings\Ross\My Documents\C++\Windows Programs\main.cpp `ID_HELP_ABOUT' undeclared (first use this function) 
    
    88 C:\Documents and Settings\Ross\My Documents\C++\Windows Programs\main.cpp `IDD_ABOUT' undeclared (first use this function)
    i know i have to declare them, but i don't know how, because i am relatively knew to windows programming, can anyone help me?

  2. #2
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    oh yeah, and here is the code:

    Code:
    //main.cpp
    #include <windows.h>
    
    /*  Declare Windows procedure  */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    
    /*  Make the class name into a global variable  */
    char szClassName[ ] = "WindowsApp";
    
    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 */
    
        /* 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;
    
        /* 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 */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
    
        /* Make the window visible on the screen */
        ShowWindow (hwnd, nFunsterStil);
    
        /* 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()  */
    
    BOOL CALLBACK AboutDlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  /* handle the messages */
        {
            case WM_INITDIALOG:
    
            return TRUE;
            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;
               case IDOK:
                  EndDialog(hwnd, IDOK);
               break;
               case IDCANCEL:
                  EndDialog(hwnd, IDCANCEL);
               break;
                }
               break;
               default:
                   return FALSE;
           }
           return TRUE;
    }

  3. #3
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    oh, i forgot, i named the thread resource file because i was having problems with it, but i fixed those problems, so don't take any notice of the title of the thread.

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    43
    Create a header file 'resource.h' and include it in main.cpp like so:

    Code:
    #include "resource.h"
    Then, in your header, #define IDD_ABOUT and ID_HELP_ABOUT like so:

    Code:
    #define IDD_ABOUT     101
    #define ID_HELP_ABOUT 102
    Hope this helps.
    Last edited by Darklighter; 10-16-2006 at 02:12 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. resource file problem
    By jjj93421 in forum Game Programming
    Replies: 6
    Last Post: 03-30-2004, 10:58 PM
  5. menu resource file
    By satriani in forum Windows Programming
    Replies: 5
    Last Post: 06-08-2002, 10:52 PM