Thread: edit control in dialog box problems

  1. #1
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Angry edit control in dialog box problems

    I still think I may be using the GetDlgItem API incorrectly.

    1. I select the popup 'Sections' from my menu
    2. Then I select the actual cross section i.e. a 'circle' from the popup (ID_SECTIONS_CIRCLE)
    3. This in turn runs my dialog (ID_CIRCLE_PROPERTIES) that allows me to enter a radius into the (IDC_EDIT_RADIUS) field.
    4. The prog. then crashes... and says it must be closed. So I am obviously doing something wrong.

    All I want to do is get this info. stored into a variable so I can check it. Anyone see what I did wrong?

    Code:
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
         switch (message)
         {
         case WM_COMMAND:
              switch (LOWORD (wParam))
              {
              //case IDM_FILE_NEW:
              //case IDM_FILE_OPEN:
              //case IDM_FILE_SAVE:
              //case IDM_FILE_SAVE_AS:
                   MessageBeep (0) ;
                   return 0 ;
                   
              case ID_EXIT:
                   SendMessage (hwnd, WM_CLOSE, 0, 0) ;
                   return 0 ;
    			   
                   InvalidateRect (hwnd, NULL, TRUE) ;
                   return 0 ;
    			  
    
    		  case ID_SECTIONS_CIRCLE:
    			  {
    				  int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_CIRCLE_PROPERTIES), hwnd, AboutDlgProc);
    				  //Test return value of Dialog....
    					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);
    					}
    					//Dialog must have exited with IDOK.  ToDo.Check for valid input.??? Return to label if incorrect???
    				  // End test return value of Dialog..
    
    					int nLen = GetWindowTextLength(hwnd);
    					LPTSTR buffer = 0;
    					buffer[nLen] = NULL;
    					
    					{
    						HWND hdlg;
    
    				////////////////What am I doing wrong here//////////////////
    				// program crashes when I select Sections | Circle and then enter the radius in the edit field
    
    						hdlg = GetDlgItem(hwnd, IDC_EDIT_RADIUS);
    						//GetWindowText(hwnd, buffer, nLen);
    
    						GetDlgItemText(hdlg,	// handle to dialog box
    							IDC_EDIT_RADIUS,	// control identifier
    							buffer,				// pointer to buffer for text
    							nLen				// maximum size of string
    						);
    						
    						MessageBox(hwnd, "Dialog!", "I'd like to print buffer here", MB_OK | MB_ICONINFORMATION);
    
    					
    					}
    
    
     
    
    
    			  }
    			  break;

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    8
    First, I think you mixed your window handles!
    Second, you can't call GetDlgItem(hWnd, IDC_EDIT_RADIUS) because the dialog with this edit box doesn't exist anymore after DialogBox returns (DialogBox returns after destroying the dialog). By the way, I hope you understand my english :-)

    Manage you program like this:

    - In you WndProc of the Propertie Dialog Box (with the
    IDC_EDIT_RADIUS edit box) check if the user press the
    OK Button. If he does call GetDlgItemText and store the
    the value in a variable. Make sure you can access the variable
    from your main WndProc !!
    - In your main WndProc you just have to check if the user pressed
    the ok button (f.e. like you did) and get the value from the
    variable, in that you stored the radius!

    hope this will help you!

  3. #3
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Thanks so much for your help!

    Thanks everyone for your help I am greatfull. lvk I will try what you suggested.

  4. #4
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Unhappy Still problems understanding.

    Apparently the light hasn't dawned yet. Everything in the menu and dialogs work except for the ID_CIRCLE_PROPERTIES (The most important part, of course). It doesn't even display the dialog now so that I could even try to enter a value. I thought that I understood what you had directed me to do. I must still be doing something incorrectly, here is what I think is the most logical process I have yet tried:

    // Moments of Inertia Program.

    Code:
    #include <windows.h>
    #include <math.h>
    #include <winuser.h>
    #include "resource.h"
    
    #define PI  4 * atan(0.0);
    
    HINSTANCE hInstance;
    //HWND	hdlg;
    HMENU   hMenu ;
    char* radius = 0;
    int ret = 0;
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    BOOL CALLBACK AboutDlgProc(HWND , UINT, WPARAM, LPARAM);
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    TCHAR szAppName[] = TEXT ("Moment of Inertia Program") ;
    
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
         HWND     hwnd;
         MSG      msg ;
         WNDCLASS wndclass ;
         
         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
         wndclass.hCursor       = LoadCursor (NULL, IDC_CROSS) ;
         wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
         wndclass.lpszMenuName  = szAppName ;
         wndclass.lpszClassName = szAppName ;
         
         if (!RegisterClass (&wndclass))
         {
              MessageBox (NULL, TEXT ("This program requires Windows NT!"),
                          szAppName, MB_ICONERROR) ;
              return 0 ;
         }
         
    	 hMenu = LoadMenu (hInstance, MAKEINTRESOURCE(IDR_MENU1));
         hwnd = CreateWindow (szAppName, TEXT ("Moment of Inertia Program"),
                              WS_OVERLAPPEDWINDOW,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              NULL, hMenu, hInstance, NULL) ;
    
    
         
         ShowWindow (hwnd, iCmdShow) ;
         UpdateWindow (hwnd) ;
         
         while (GetMessage (&msg, NULL, 0, 0))
         {
              TranslateMessage (&msg) ;
              DispatchMessage (&msg) ;
         }
         return msg.wParam ;
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	
    	//int ret;
        switch (message)
        {
        case WM_COMMAND:
             switch (LOWORD (wParam))
             {
    	//case IDM_FILE_NEW:
    	case IDM_FILE_OPEN:
    	case IDM_FILE_SAVE:
    	//case IDM_FILE_SAVE_AS:
    	MessageBeep (0) ;
    	return 0 ;
                   
              case IDM_EXIT:
                   SendMessage (hwnd, WM_CLOSE, 0, 0) ;
                  // return 0 ;
    			   
                   InvalidateRect (hwnd, NULL, TRUE) ;
                   return 0 ;
    			  
    
              case ID_SECTIONS_CIRCLE:
    			  ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_CIRCLE_PROPERTIES), hwnd, AboutDlgProc);
    			return ret ;
    
    	case ID_SECTIONS_RECTANGLE:
    			  MessageBox (hwnd, TEXT ("To Do!"),
                               szAppName, MB_ICONEXCLAMATION | MB_OK) ;
                  return 0 ;
    
              case ID_HELP_HELP:
                   MessageBox (hwnd, TEXT ("Help not yet implemented!"),
                               szAppName, MB_ICONEXCLAMATION | MB_OK) ;
                   return 0 ;
                   
              case ID_ABOUT:
                   MessageBox (hwnd, TEXT ("Moments of Inertia\n")
                                     TEXT ("Me, 2002"),
                               szAppName, MB_ICONINFORMATION | MB_OK) ;
                   return 0 ;
              }
              break ;
             
                   
         case WM_DESTROY:
              PostQuitMessage (0) ;
              return 0 ;
         }
         return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    	HWND hdlg;
    	//int ret = 0;
    	int nLen = 0;
    	LPTSTR buffer = NULL;
    	buffer[nLen] = NULL;
    	
    
        switch(Message)
        {
            case WM_INITDIALOG:
    
            return TRUE;
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case IDOK:
    	        {
    	            hdlg = GetDlgItem(hwnd, IDC_EDIT_RADIUS);  // handle to dialog box edit field???
    						nLen = GetWindowTextLength(hdlg);
    						GetDlgItemText(hdlg,	// handle to dialog box
    							IDC_EDIT_RADIUS,	// control identifier
    							buffer,				// pointer to buffer for text
    							nLen				// maximum size of string
    						);
    						radius = buffer;	// No error checking yet! atod!
    						MessageBox(hwnd, "Dialog!", "I'd like to print buffer here", MB_OK | MB_ICONINFORMATION);
    					}
    
    
                        EndDialog(hwnd, IDOK);
                    break;
                    case IDCANCEL:
                        EndDialog(hwnd, IDCANCEL);
                    break;
                }
            break;
            default:
                return FALSE;
        }
        return TRUE;
    }

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    There are a couple of things which may be dubious, but I can't tell because I don't have your resource script(s) and header. Zip everything you need to build and run it together and post that, I'll download it, build it and have a fiddle. Won't be today though, (or at least - unlikely - we have guests).
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Here it all is.

    Here is my cpp, header and resource files. Thanks for offering to take a look. I am sure it is something that I am doing incorrectly, so whenever you get a chance here it is.

    I was up until 4am this morning trying to make it work I believe that these files are the closest I've come so far.

    // Moments of Inertia Program.



    Code:
    #include <windows.h>
    #include <math.h>
    #include <winuser.h>
    #include "resource.h"
    
    #define PI  4 * atan(0.0);
    
    HINSTANCE hInstance;
    HWND	hdlg;
    HMENU   hMenu ;
    char* radius = 0;
    int ret=0;
    
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    BOOL CALLBACK AboutDlgProc(HWND , UINT, WPARAM, LPARAM);
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    TCHAR szAppName[] = TEXT ("Moment of Inertia Program") ;
    
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
         HWND     hwnd;
         MSG      msg ;
         WNDCLASS wndclass ;
         
         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
         wndclass.hCursor       = LoadCursor (NULL, IDC_CROSS) ;
         wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
         wndclass.lpszMenuName  = szAppName ;
         wndclass.lpszClassName = szAppName ;
         
         if (!RegisterClass (&wndclass))
         {
              MessageBox (NULL, TEXT ("This program requires Windows NT!"),szAppName, MB_ICONERROR) ;
              return 0 ;
         }
         
    	 hMenu = LoadMenu (hInstance, MAKEINTRESOURCE(IDR_MENU1));
         hwnd = CreateWindow (szAppName, TEXT ("Moment of Inertia Program"), 
    		 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, hMenu, hInstance, NULL) ;
    	 ShowWindow (hwnd, iCmdShow) ;
         UpdateWindow (hwnd) ;
         
         while (GetMessage (&msg, NULL, 0, 0))
         {
              TranslateMessage (&msg) ;
              DispatchMessage (&msg) ;
         }
         return msg.wParam ;
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	//int ret;
        switch (message)
        {
        case WM_COMMAND:
             switch (LOWORD (wParam))
             {
    			 //case IDM_FILE_NEW:  //case IDM_FILE_SAVE_AS:
    		 case IDM_FILE_OPEN:
    		 case IDM_FILE_SAVE:
    			 MessageBeep (0) ;
    			 return 0 ;
                   
    		 case IDM_EXIT:
    			 SendMessage (hwnd, WM_CLOSE, 0, 0) ;
                 // return 0 ;
    
    			 InvalidateRect (hwnd, NULL, TRUE) ;
    			 return 0 ;
    			  
    
    		 case ID_SECTIONS_CIRCLE:
    			 ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_CIRCLE_PROPERTIES), hwnd, AboutDlgProc);
    			//return ret ;
    			 return 0;
    
    		 case ID_SECTIONS_RECTANGLE:
    			 MessageBox (hwnd, TEXT ("To Do!"), szAppName, MB_ICONEXCLAMATION | MB_OK) ;
                 return 0 ;
    
    		 case ID_HELP_HELP:
                  MessageBox (hwnd, TEXT ("Help not yet implemented!"), szAppName, MB_ICONEXCLAMATION | MB_OK) ;
                  return 0 ;
                   
    		 case ID_ABOUT:
    			 MessageBox (hwnd, TEXT ("Moments of Inertia\n") TEXT ("Me, 2002"),szAppName, MB_ICONINFORMATION | MB_OK) ;
                   return 0 ;
    		 }
             break ;
    	case WM_DESTROY:
    		PostQuitMessage (0) ;
    		return 0 ;
    	}
    	return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    	//HWND hdlg;
    	//int ret = 0;
    	int nLen = 0;
    	LPTSTR buffer = NULL;
    	buffer[nLen] = NULL;
    	
    
        switch(Message)
        {
            case WM_INITDIALOG:
    
            return TRUE;
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case IDOK:
    						{
    						hdlg = GetDlgItem(hwnd, IDC_EDIT_RADIUS);  // handle to dialog box edit field???
    						nLen = GetWindowTextLength(hdlg);
    						GetDlgItemText(hdlg,	// handle to dialog box
    							IDC_EDIT_RADIUS,	// control identifier
    							buffer,				// pointer to buffer for text
    							nLen				// maximum size of string
    						);
    						radius = buffer;	// No error checking yet! atod!
    						MessageBox(hwnd, "Dialog!", "I'd like to print buffer here", MB_OK | MB_ICONINFORMATION);
    					}
    
    
                        EndDialog(hwnd, IDOK);
                    break;
                    case IDCANCEL:
                        EndDialog(hwnd, IDCANCEL);
                    break;
                }
            break;
            default:
                return FALSE;
        }
        return TRUE;
    }

    Resource.h

    //{{NO_DEPENDENCIES}}
    // Microsoft Developer Studio generated include file.
    // Used by Script1.rc
    //
    #define IDR_MENU1 101
    #define ID_CIRCLE_PROPERTIES 102
    #define IDC_EDIT_RADIUS 1000
    #define ID_SECTIONS_CIRCLE 40003
    #define ID_ABOUT 40004
    #define ID_EXIT 40005
    #define IDM_EXIT 40005
    #define ID_HELP_HELP 40011
    #define ID_SECTIONS_RECTANGLE 40012
    #define IDM_FILE_OPEN 40013
    #define IDM_FILE_SAVE 40014

    // Next default values for new objects
    //
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NEXT_RESOURCE_VALUE 103
    #define _APS_NEXT_COMMAND_VALUE 40015
    #define _APS_NEXT_CONTROL_VALUE 1001
    #define _APS_NEXT_SYMED_VALUE 101
    #endif
    #endif

  7. #7
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Here it all is.

    Here is my cpp, header and resource files. Thanks for offering to take a look. I am sure it is something that I am doing incorrectly, so whenever you get a chance here it is.

    I was up until 4am this morning trying to make it work I believe that these files are the closest I've come so far.

    // Moments of Inertia Program.



    Code:
    #include <windows.h>
    #include <math.h>
    #include <winuser.h>
    #include "resource.h"
    
    #define PI  4 * atan(0.0);
    
    HINSTANCE hInstance;
    HWND	hdlg;
    HMENU   hMenu ;
    char* radius = 0;
    int ret=0;
    
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    BOOL CALLBACK AboutDlgProc(HWND , UINT, WPARAM, LPARAM);
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    TCHAR szAppName[] = TEXT ("Moment of Inertia Program") ;
    
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
         HWND     hwnd;
         MSG      msg ;
         WNDCLASS wndclass ;
         
         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
         wndclass.hCursor       = LoadCursor (NULL, IDC_CROSS) ;
         wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
         wndclass.lpszMenuName  = szAppName ;
         wndclass.lpszClassName = szAppName ;
         
         if (!RegisterClass (&wndclass))
         {
              MessageBox (NULL, TEXT ("This program requires Windows NT!"),szAppName, MB_ICONERROR) ;
              return 0 ;
         }
         
    	 hMenu = LoadMenu (hInstance, MAKEINTRESOURCE(IDR_MENU1));
         hwnd = CreateWindow (szAppName, TEXT ("Moment of Inertia Program"), 
    		 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, hMenu, hInstance, NULL) ;
    	 ShowWindow (hwnd, iCmdShow) ;
         UpdateWindow (hwnd) ;
         
         while (GetMessage (&msg, NULL, 0, 0))
         {
              TranslateMessage (&msg) ;
              DispatchMessage (&msg) ;
         }
         return msg.wParam ;
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	//int ret;
        switch (message)
        {
        case WM_COMMAND:
             switch (LOWORD (wParam))
             {
    			 //case IDM_FILE_NEW:  //case IDM_FILE_SAVE_AS:
    		 case IDM_FILE_OPEN:
    		 case IDM_FILE_SAVE:
    			 MessageBeep (0) ;
    			 return 0 ;
                   
    		 case IDM_EXIT:
    			 SendMessage (hwnd, WM_CLOSE, 0, 0) ;
                 // return 0 ;
    
    			 InvalidateRect (hwnd, NULL, TRUE) ;
    			 return 0 ;
    			  
    
    		 case ID_SECTIONS_CIRCLE:
    			 ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_CIRCLE_PROPERTIES), hwnd, AboutDlgProc);
    			//return ret ;
    			 return 0;
    
    		 case ID_SECTIONS_RECTANGLE:
    			 MessageBox (hwnd, TEXT ("To Do!"), szAppName, MB_ICONEXCLAMATION | MB_OK) ;
                 return 0 ;
    
    		 case ID_HELP_HELP:
                  MessageBox (hwnd, TEXT ("Help not yet implemented!"), szAppName, MB_ICONEXCLAMATION | MB_OK) ;
                  return 0 ;
                   
    		 case ID_ABOUT:
    			 MessageBox (hwnd, TEXT ("Moments of Inertia\n") TEXT ("Me, 2002"),szAppName, MB_ICONINFORMATION | MB_OK) ;
                   return 0 ;
    		 }
             break ;
    	case WM_DESTROY:
    		PostQuitMessage (0) ;
    		return 0 ;
    	}
    	return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    	//HWND hdlg;
    	//int ret = 0;
    	int nLen = 0;
    	LPTSTR buffer = NULL;
    	buffer[nLen] = NULL;
    	
    
        switch(Message)
        {
            case WM_INITDIALOG:
    
            return TRUE;
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case IDOK:
    						{
    						hdlg = GetDlgItem(hwnd, IDC_EDIT_RADIUS);  // handle to dialog box edit field???
    						nLen = GetWindowTextLength(hdlg);
    						GetDlgItemText(hdlg,	// handle to dialog box
    							IDC_EDIT_RADIUS,	// control identifier
    							buffer,				// pointer to buffer for text
    							nLen				// maximum size of string
    						);
    						radius = buffer;	// No error checking yet! atod!
    						MessageBox(hwnd, "Dialog!", "I'd like to print buffer here", MB_OK | MB_ICONINFORMATION);
    					}
    
    
                        EndDialog(hwnd, IDOK);
                    break;
                    case IDCANCEL:
                        EndDialog(hwnd, IDCANCEL);
                    break;
                }
            break;
            default:
                return FALSE;
        }
        return TRUE;
    }

    Resource.h

    //{{NO_DEPENDENCIES}}
    // Microsoft Developer Studio generated include file.
    // Used by Script1.rc
    //
    #define IDR_MENU1 101
    #define ID_CIRCLE_PROPERTIES 102
    #define IDC_EDIT_RADIUS 1000
    #define ID_SECTIONS_CIRCLE 40003
    #define ID_ABOUT 40004
    #define ID_EXIT 40005
    #define IDM_EXIT 40005
    #define ID_HELP_HELP 40011
    #define ID_SECTIONS_RECTANGLE 40012
    #define IDM_FILE_OPEN 40013
    #define IDM_FILE_SAVE 40014

    // Next default values for new objects
    //
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NEXT_RESOURCE_VALUE 103
    #define _APS_NEXT_COMMAND_VALUE 40015
    #define _APS_NEXT_CONTROL_VALUE 1001
    #define _APS_NEXT_SYMED_VALUE 101
    #endif
    #endif


    It won't let me attach my resource files! Wonder why?

  8. #8
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Here is the aps file.

    //Microsoft Developer Studio generated resource script.
    //
    #include "resource.h"

    #define APSTUDIO_READONLY_SYMBOLS
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 2 resource.
    //
    #include "afxres.h"

    /////////////////////////////////////////////////////////////////////////////
    #undef APSTUDIO_READONLY_SYMBOLS

    /////////////////////////////////////////////////////////////////////////////
    // English (U.S.) resources

    #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
    #ifdef _WIN32
    LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
    #pragma code_page(1252)
    #endif //_WIN32

    /////////////////////////////////////////////////////////////////////////////
    //
    // Menu
    //

    IDR_MENU1 MENU DISCARDABLE
    BEGIN
    POPUP "&FILE"
    BEGIN
    MENUITEM "&OPEN", IDM_FILE_OPEN
    MENUITEM "&SAVE", IDM_FILE_SAVE
    MENUITEM SEPARATOR
    MENUITEM "E&XIT", IDM_EXIT
    END
    POPUP "SECTIONS"
    BEGIN
    MENUITEM "CIRCLE", ID_SECTIONS_CIRCLE
    MENUITEM "&RECTANGLE", ID_SECTIONS_RECTANGLE
    END
    POPUP "&HELP"
    BEGIN
    MENUITEM "&HELP", ID_HELP_HELP
    MENUITEM "&ABOUT", ID_ABOUT
    END
    END


    #ifdef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    //
    // TEXTINCLUDE
    //

    1 TEXTINCLUDE DISCARDABLE
    BEGIN
    "resource.h\0"
    END

    2 TEXTINCLUDE DISCARDABLE
    BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
    END

    3 TEXTINCLUDE DISCARDABLE
    BEGIN
    "\r\n"
    "\0"
    END

    #endif // APSTUDIO_INVOKED


    /////////////////////////////////////////////////////////////////////////////
    //
    // Dialog
    //

    ID_CIRCLE_PROPERTIES DIALOGEX 0, 0, 160, 46
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "Circle"
    FONT 8, "MS Sans Serif"
    BEGIN
    PUSHBUTTON "OK",IDOK,103,7,50,14
    PUSHBUTTON "Cancel",IDCANCEL,103,24,50,14
    LTEXT "Radius:",IDC_STATIC,7,15,27,11
    EDITTEXT IDC_EDIT_RADIUS,33,13,58,13,ES_CENTER | ES_AUTOHSCROLL |
    NOT WS_BORDER,WS_EX_CLIENTEDGE
    END


    /////////////////////////////////////////////////////////////////////////////
    //
    // DESIGNINFO
    //

    #ifdef APSTUDIO_INVOKED
    GUIDELINES DESIGNINFO DISCARDABLE
    BEGIN
    ID_CIRCLE_PROPERTIES, DIALOG
    BEGIN
    LEFTMARGIN, 7
    RIGHTMARGIN, 153
    TOPMARGIN, 7
    BOTTOMMARGIN, 39
    END
    END
    #endif // APSTUDIO_INVOKED

    #endif // English (U.S.) resources
    /////////////////////////////////////////////////////////////////////////////



    #ifndef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 3 resource.
    //


    /////////////////////////////////////////////////////////////////////////////
    #endif // not APSTUDIO_INVOKED

  9. #9
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    What in the heck is going on sometimes it will let me add an attachment other times it won't anyone know what is going on?

  10. #10
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>>
    LPTSTR buffer = NULL;
    buffer[nLen] = NULL;
    <<<

    You are declaring a pointer to buffer but not allocating any storage to it, you then try to use the storage you have not got!

    You have a few other problems as well, (let me know if you want more help), but that is what is crashing you!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  11. #11
    Registered User
    Join Date
    Oct 2002
    Posts
    8
    In AboutDlgProc

    (1) remove the line buffer[nLen] = NULL;
    (2) after 'nLen = GetWindowTextLength(hdlg);' you have to allocate memory space for buffer like this 'buffer = (LPTSTR)malloc(nLen + 1);' You have to allocate nLen + 1 bytes because you need space for the \0 character at the end of the string
    (3) Call GetDlgItemText with hwnd instead of hdlg. this is because hdlg is the handle to edit box. But GetDlgItemText needs the owner of the control item (in your case hwnd).
    (4) Don't forget to free memory after you used the value with 'free(radius);'.
    (5) The easiest way would be to declare a global variable like this 'double dRadius = 0'; after you get the radius into buffer call printf and then free buffer.

    Hope this will help you!

  12. #12
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Talking Thank you all so much!

    You guys are great.
    Thank you for taking the time to help me out.

    I sincerely appreciate it!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Edit controls of a dialog from another dialog...
    By Snake in forum Windows Programming
    Replies: 9
    Last Post: 07-01-2005, 02:18 PM
  2. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  3. Updating a list control
    By MPSoutine in forum Windows Programming
    Replies: 2
    Last Post: 12-05-2003, 02:03 AM
  4. Dialog Box Resources
    By Mecnels in forum Windows Programming
    Replies: 2
    Last Post: 04-28-2003, 05:57 AM
  5. Limiting Characters in Edit Box :: MFC
    By kuphryn in forum Windows Programming
    Replies: 5
    Last Post: 06-02-2002, 10:21 AM