dialog help needed

This is a discussion on dialog help needed within the Windows Programming forums, part of the Platform Specific Boards category; here are all of my codes Main.CPP Code: #include <windows.h> #include "resource.h" #include "dialog.h" const char *ClsName = "BasicApp"; const ...

  1. #1
    C++ Beginner
    Join Date
    Jun 2005
    Posts
    39

    dialog help needed

    here are all of my codes

    Main.CPP
    Code:
    #include <windows.h>
    #include "resource.h"
    #include "dialog.h"
    
    const char *ClsName = "BasicApp";
    const char *WndName = "Mystical Island"; //window name
    
    LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg,
    			   WPARAM wParam, LPARAM lParam);
    
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow) //main function of window
    {
    	MSG        Msg; //window messages
    	HWND       hWnd; //handle of window
    	WNDCLASSEX WndClsEx;  //structure of window
    
    	// Create the application window
    	WndClsEx.cbSize        = sizeof(WNDCLASSEX); //type
    	WndClsEx.style         = CS_HREDRAW | CS_VREDRAW; //horizontal | vertical
    	WndClsEx.lpfnWndProc   = WndProcedure; 
    	WndClsEx.cbClsExtra    = 0; //none
    	WndClsEx.cbWndExtra    = 0; //none
    	WndClsEx.hIcon         = LoadIcon(NULL, IDI_APPLICATION); //loading icon
    	WndClsEx.hCursor       = LoadCursor(NULL, IDC_ARROW); //loading cursor
    	WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); //background color
    	WndClsEx.lpszMenuName  = MAKEINTRESOURCE(IDR_MYMENU); //loading menu
    	WndClsEx.lpszClassName = ClsName; //varaible class name
    	WndClsEx.hInstance     = hInstance; //previous instance
    	WndClsEx.hIconSm  = LoadIcon(NULL, IDI_APPLICATION);
    
    
    	// Register the application
    	RegisterClassEx(&WndClsEx);
    
    	// Create the window object
    	hWnd = CreateWindow(ClsName,
    			  WndName,
    			  WS_OVERLAPPEDWINDOW,
    			  CW_USEDEFAULT,
    			  CW_USEDEFAULT,
    			  CW_USEDEFAULT,
    			  CW_USEDEFAULT,
    			  NULL,
    			  NULL,
    			  hInstance,
    			  NULL);
    	
    	// Find out if the window was created
    	if( !hWnd ) // If the window was not created,
    		return 0; // stop the application
    
    	// Display the window to the user
    	ShowWindow(hWnd, SW_SHOWNORMAL);
    	UpdateWindow(hWnd);
    
    	// Decode and treat the messages
    	// as long as the application is running
    	while( GetMessage(&Msg, NULL, 0, 0) )
    	{
                 TranslateMessage(&Msg);
                 DispatchMessage(&Msg);
    	}
    	return Msg.wParam;
    }
    
    LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
    			   WPARAM wParam, LPARAM lParam)
    {
        switch(Msg)
        {  
          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 WM_DESTROY:
            // then close it
            PostQuitMessage(WM_QUIT);
            break;
        default:
            // Process the left-over messages
            return DefWindowProc(hWnd, Msg, wParam, lParam);
        }
        // If something was not done, let it go
        return 0;
    }
    Windows1.rc
    Code:
    #include "resource.h"
    #include "windows.h"
    
    IDR_MYMENU MENU
    BEGIN
        POPUP "&File"
        BEGIN
            MENUITEM "E&xit", 9001
        END
    
        POPUP "&Area"
        BEGIN
            MENUITEM "&Go", 9002
            MENUITEM "G&o somewhere else", 0, GRAYED
        END
        
        POPUP "&Battle"
        BEGIN
            MENUITEM "&Player", 9003
    END
        POPUP "&Help"
        BEGIN
            MENUITEM "&About", 9004
        END
    END
    
    IDD_ABOUT DIALOG DISCARDABLE  0, 0, 239, 66
    STYLE  DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "About Mystical Island"
    FONT 8, "Courier New"
    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           "This is a test version of the RPG, \r\n\r\nMystical Island by  Renegade"
                        IDC_STATIC,16,18,144,33
    END
    dialog.h
    Code:
    #ifndef _DIALOG_H_
    #define _DIALOG_H_
    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;
    }
    #endif
    finally, resource.h
    Code:
    #ifndef _RESOURCE_H_
    #define _RESOURCE_H_
    
    #define IDR_MYMENU 101
    #define ID_FILE_EXIT 9001
    #define ID_AREA_GO 9002
    #define ID_BATTLE_PLAYER 9003
    #define ID_HELP_ABOUT 9004
    #define IDC_STATIC -1
    #endif
    I get these errors:
    main.cpp: In function `LRESULT WndProcedure(HWND__*, UINT, WPARAM, LPARAM)':
    main.cpp:76: error: `IDD_ABOUT' undeclared (first use this function)
    main.cpp:76: error: (Each undeclared identifier is reported only once for each function it appears in.)
    main.cpp:76: error: `hwnd' undeclared (first use this function)
    main.cpp:72: warning: unreachable code at beginning of switch statement

    Thank you in advance, and if any1 can help through IM my AIM screen name is: MetalChansey18
    I'm a beginner C++ programmer, but I have studied HTML and Java. So if you need to help me I should catch on fast =)

  2. #2
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    You know, you could try reading your errors before you post here. I'm not trying to be rude, but really. IDD_ABOUT isn't declared, anywhere. Look through your code, it isn't there. In WndProcedure(), the argument says HWND hWnd, not hwnd. In that function, hwnd isn't declared.

    Also, I don't know where everyone keeps getting PostQuitMessage(WM_QUIT), but WM_QUIT is defined to be 18. If you want your program to end, you must use PostQuitMessage(0).
    Code:
    void function(void)
     {
      function();
     }

  3. #3
    C++ Beginner
    Join Date
    Jun 2005
    Posts
    39
    OMG, read throught the code before I post here, I've been reading that code for hours, and I made it myself, after reading tutorials all day almost. The tutorial I read said nothing about defining IDD_About and please don't insult me like a downloading source code junkee, because i don't hardly even c+p from tutorial I usually type it out. Please don't say look at the code before posting because that tends to make people hostile when they been working their heart out at this stuff. Thanx for the advice if it works. Peace to ya.
    I'm a beginner C++ programmer, but I have studied HTML and Java. So if you need to help me I should catch on fast =)

  4. #4
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    I know. I'm sorry for being harsh, and I wasn't making any assumptions about you. I don't do that, cause I know what it's like. But you could have found the hwnd error. Bah, I'm criticizing you again. I apologize. I'm just used to dealing with simple errors like this. It's second nature to me.
    Last edited by Jaken Veina; 07-17-2005 at 10:15 PM.
    Code:
    void function(void)
     {
      function();
     }

  5. #5
    The N00b That Owns You!
    Join Date
    Jul 2005
    Location
    Canada!
    Posts
    178
    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 "This is a test version of the RPG, \r\n\r\nMystical Island by Renegade"
    IDC_STATIC,16,18,144,33
    when i did this it gave me improper syntax tofix it place GROUPBOX at the top and CTEXT under it
    New Function!!!!

    glAddIdol(C+noob);

    The feeling of rusty spoons against my salad fingers is almost ORGASMIC

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  2. Edit controls of a dialog from another dialog...
    By Snake in forum Windows Programming
    Replies: 9
    Last Post: 07-01-2005, 03:18 PM
  3. make Child Dialog not Popup?
    By Zeusbwr in forum Windows Programming
    Replies: 5
    Last Post: 04-08-2005, 03:42 PM
  4. Getting the position of a dialog without parent on the screen
    By stormbringer in forum Windows Programming
    Replies: 1
    Last Post: 08-27-2003, 03:59 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21