Thread: GetDlgItemInt returning only 0

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    202

    GetDlgItemInt returning only 0

    I have a problem where my GetDlgItemInt is only returning 0 s. The checks in GetDlgIntmInt are returnings False too. The cide is placed below and I know its not the wrong name of the edit boxes since I have a separate dialog and I am getting the same errors. Please help. Code is pasted below.
    Code:
     static int *xpoint, *ypoint, PointY, PointX, x, y;
     static BOOL *PointYCheck, *PointXCheck;
                      ypoint=&y;
                      xpoint=&x;
    						*ypoint=GetDlgItemInt(hdc, PointY, PointYCheck, FALSE) ; // collect data from edit boxes
                      *xpoint=GetDlgItemInt(hdc, PointX, PointXCheck, FALSE) ;
    						if(PointYCheck == FALSE){
    							MessageBox(hwnd, "PointY is not collected properaly", "Error on Dialog Item", MB_OK);//check for errors
    						}
    						if(PointXCheck == FALSE){
    							MessageBox(hwnd, "PointX is not collected properaly", "Error on Dialog Item", MB_OK);
                      }
    						xspace=cxClient/30; //calculate the distance in betweent the hashes
               			yspace=cyClient/30;
                      y=(*ypoint) * yspace ; // calculate co-ordinates
                      x=(*xpoint) * xspace ;
                      if (x <= 0){               //to sepates quadrants correctly
                             x = x + (cxClient/2) ;
                   	}
    						if (y <= 0){
                             y = y + (cyClient/2) ;
                   	}

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    UINT=GetDlgItemInt(HWND, int, int, int)

    returns the int in the ctrl as UNIT

    HWND of Dialog
    int ID of control (not an int for the result)
    int BOOL fail / suc indicator
    int BOOL (TRUE ->signed) / (FALSE->unsigned) int is to be collected from control

    Don't use the pointers just int's
    ie
    Code:
    int     iResult,iSuc=FALSE,iSigned=FALSE;
    HWND    hWnd;
    
    iResult=(int)GetDlgItemInt(hWnd, MAKEINTRESOURCE(ID_THE_CTRL),&iSuc,iSigned);
    if(iSuc==FALSE)
    //error
    Last edited by novacain; 12-11-2001 at 12:21 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    202

    Errors

    Whenever I do it with MAKEINTRESOURCE() it gives me a error stating:
    Error: geometry.c(208,81):Type mismatch in parameter 'nIDDlgItem' in call to 'GetDlgItemInt'

    EDIT:
    If I do it the original way it works with no errors but returns 0 :-( .
    /Edit

    any suggestions?(Line 208 is one of my GetDlgItemInt lines and 81 is a charecter in my Check parameter for some reason :-/ )
    Last edited by Isometric; 12-11-2001 at 05:07 PM.

  4. #4
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    well it doesn't work when you try to make something already a resource into a resource

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    I was just following what novicain told me. Well if I take out MAKEINTRESOURCE() Im back to where I started where it just returns 0.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    We need to see the code where you are allocating memory for your pointers. The code you pasted can't work.

  7. #7
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    Below is attached my souce code and Resource files. They are formatted for Borland C++. I left it with MAKEINTRESOURCE() in . If you want to run it without that just take it and change 102 to PointY and 103 to PointX

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Try this. Change this:
    static BOOL *PointYCheck, *PointXCheck;
    to this:
    static BOOL PointYCheck, PointXCheck;

    And change your GetDlgItemInt() to this:

    *ypoint=(int)GetDlgItemInt(hDlg, PointY, &PointYCheck, FALSE) ; // collect data from edit boxes
    *xpoint=(int)GetDlgItemInt(hDlg, PointX, &PointXCheck, FALSE) ;

    Or this will also work:
    *ypoint=(int)GetDlgItemInt(hDlg, 103, &PointYCheck, FALSE) ; // collect data from edit boxes
    *xpoint=(int)GetDlgItemInt(hDlg, 102, &PointXCheck, FALSE) ;
    Last edited by swoopy; 12-11-2001 at 07:57 PM.

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Don't need the MAKEINTRESOURCE.
    That is a macro to convert between the int numbers that corespond to control ID's and the names you have declared.

    In this case you do not need it as you have not given them a name only a number.
    If you have a dialog with more controls you will get into trouble in your callback, or if someone else has to debug your code.
    Try to find the correct case in the WM_COMMAND switch when they are all just numbers is a pain and is not good style. Call the edits say ID_POINT_X (not 102) and I would know what I was looking for.


    The edits are called 102 and 103 in your code.

    This is the second paramater in the call to GetDlgItemInt() eg pointX and pointY

    Do not use pointers to get the return.

    PS SelectObject() has a return. A piece of memory.
    Catch the return for later use as it is important. If you do not your PC will crash from memory loss. May take a while as your leak is only small, two brushes per paint msg.

    Its something you will have to learn to do sooner or later.

  10. #10
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    dont you mean 2 pens/brushes in drawing the circle and point? I thought I had deletes in WM_PAINT but I cnat check it do to the fact Im in school and i do this at home (I play with electronics at school but not programming)

  11. #11
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    From the MSVC help on SelectObject()

    >>This function returns the previously selected object of the specified type. An application should always replace a new object with the original, default object after it has finished drawing with the new object. <<

    In other words catch the return and replace it, using SelectObject(), before cleaning up the pens / brushes.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function returning hour in either 12 or 24 hour format
    By stanlvw in forum C Programming
    Replies: 4
    Last Post: 01-01-2008, 06:02 AM
  2. Recursion: base case returning 1, function returning 0
    By yougene in forum C Programming
    Replies: 5
    Last Post: 09-07-2007, 05:38 PM
  3. Function returning incorrect value
    By CHurst in forum C Programming
    Replies: 3
    Last Post: 12-13-2005, 01:27 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. using GetDlgItemInt
    By face_master in forum Windows Programming
    Replies: 6
    Last Post: 02-04-2002, 09:39 PM