Problems with Edit

This is a discussion on Problems with Edit within the Windows Programming forums, part of the Platform Specific Boards category; What is wrong with my code? It compiles fine, but the window does not show up. Code: case WM_CREATE: LPRECT ...

  1. #1
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136

    Problems with Edit

    What is wrong with my code? It compiles fine, but the window does not show up.

    Code:
     case WM_CREATE:
                  LPRECT lpRect;
                  GetClientRect(hWnd, lpRect);
                  hEdit=CreateWindow("edit", NULL,
                                     WS_CHILD | WS_TABSTOP | WS_VISIBLE | ES_AUTOHSCROLL | ES_LEFT,
                                     4, 4,
                                     (int)((lpRect->right) /2), (int)((lpRect->bottom) /10) ,
                                     hWnd, NULL, hInstance, NULL);
                   break;

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    ShowWindow(hEdit, SW_SHOW);

    to hide it:

    ShowWindow(hEdit, SW_HIDE);

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    The ShowWindow is not needed as you rightly included the WS_VISIBLE style....

    One nasty looking thing in your code is the
    Code:
    LPRECT lpRect;
    GetClientRect(hWnd, lpRect);
    You dont know what the hell lpRect actually points to.....therefore you are writing info to an arbitrary region of memory - a sure fire way to cause havoc!

    try...
    Code:
    RECT Rect;
    GetClientRect(hWnd, &Rect);

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Still not working. Do I need to process the paint messages? Here's my entire WndProc so far.

    Code:
    LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        static HWND hEdit;
        static RECT Rect;
                    
        switch (message)                  
        {      case WM_CREATE:
                   GetClientRect(hWnd, &Rect);
                   hEdit=CreateWindow("edit", NULL,
                                     WS_CHILD | WS_TABSTOP | WS_VISIBLE | ES_AUTOHSCROLL | ES_LEFT,
                                     4, 4,
                                     (int)((Rect.right) /2), (int)((Rect.bottom) /10) ,
                                     hWnd, NULL, hInstance, NULL);
                   break;
      
               case WM_SIZE:
                 if (wParam==SIZE_MINIMIZED) //allow window to be minimized
                  {DefWindowProc(hwnd, message, wParam, lParam);
                   break;
                   }
                                          //falls through
               case WM_MOVE:             //Doesn't let resize or move
                 SetWindowPos(hWnd, HWND_NOTOPMOST,
                              GetSystemMetrics(SM_CXSCREEN) / 6,       
                              GetSystemMetrics(SM_CYSCREEN) / 8,       
                              4 * GetSystemMetrics(SM_CXSCREEN) / 6,                 
                              6 * GetSystemMetrics(SM_CYSCREEN) / 8,
                              (UINT)NULL);
                 SetWindowPos(hEdit, HWND_TOPMOST,
                              4, 4,
                              (int)((Rect.right) /2), (int)((Rect.bottom) /10) ,
                              (UINT)NULL);
                 break;
        
               case WM_DESTROY:
                  PostQuitMessage(0);        
                  break;
               
               default:                                
                  return DefWindowProc(hwnd, message, wParam, lParam);
        }
        return 0;
    }

    EDIT: Just fixed the spacing. It didn't copy well.
    Last edited by golfinguy4; 06-25-2002 at 06:08 PM.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    Check the return from the CreateWindow() to ensure hEdit is not NULL ie edit created, call GetLastError() if not.

    In your WM_SIZE there is no break if WPARAM != SIZE_MINIMISED (as the one there is in the 'if')

    Comment out all the SetWindowPos() window code and see if that is the problem. You don't have to set the edits position as it is on the dialog, unless you want to change its position on the dlg.
    "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

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Ya, the handle is 0. Also, the WM_SIZE messages are supposed to fall through (I commented it in). This makes the window non-resizable and non-movable.

  7. #7
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    It is returning an error message of 0 which is ERROR_SUCCESS.

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    Your problem is that you did not give the edit an ID

    #define IDC_EDITCTRL 10001

    in the CreateWindow() cast the hmenu to this ID#

    (HMENU)IDC_EDITCTRL

    You need to do this for any child crtls you create

    also
    AFAIK you can't let it 'fall thru' to another case the way you are.

    Put it as

    case 1:
    case 2:
    //code

    break;

    To stop move and resize I just cast the original area back into the msg (I capture the original size and pos with GetWindowRect() )

    Use the 'ING as the WM_MOVE is sent after the move and the 'ING during the move. Users seem to get annoyed if they move the window and then it snaps back.

    case WM_MOVING:
    case WM_SIZING:// if needed
    //put the original screen coods back in place of the changed ones
    ((RECT*)lParam)->left=rScreenRect.left;
    ((RECT*)lParam)->right=rScreenRect.right;
    ((RECT*)lParam)->top=rScreenRect.top;
    ((RECT*)lParam)->bottom=rScreenRect.bottom;
    break;

    and then return it to the DefWindowProc()
    Last edited by novacain; 06-25-2002 at 11:55 PM.
    "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

  9. #9
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Thank you very much. That solved the window "snapping." However, the edit control still is not coming up.

  10. #10
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Just out of curiousity, what messages are sent when a window is maximized? Mine can still be maximized, and I am trying to prevent this.

  11. #11
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    Is the edit still failing to be created (hEdit==NULL)?

    What are is the contents of the 'Rect' on WM_CREATE? As the dlg may yet to be displayed and so the client rect could contain the wrong values. Change them, temporarily, to a set value.
    "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

  12. #12
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    I have narrowed the problem down to the call of GetClientRect. It returns 0 which indicates an error. I have no clue why though. I am truly sorry for bothering all of you. It is just that this problem is really frustrating me, and I have no clue what it is.

  13. #13
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    Is it a typo that the call to (as I don't see a declaration of hWnd)

    GetClientRect() (and CreateWindow() and SetWindowPos() ) uses hWnd and not the correct handle hwnd suppiled as a param in the callback?
    "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

  14. #14
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Wow, I completely missed that. Thank you very much.

    EDIT: It works now. Thank you very much. I hate typos.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-23-2005, 08:00 AM
  2. Capture Enter key press in EDIT Box
    By richiev in forum Windows Programming
    Replies: 4
    Last Post: 07-14-2005, 12:03 AM
  3. Buttons + Edit Control
    By jay kay in forum Windows Programming
    Replies: 6
    Last Post: 03-09-2005, 04:36 PM
  4. edit controls
    By ZerOrDie in forum Windows Programming
    Replies: 11
    Last Post: 04-08-2003, 12:09 PM
  5. Difficulty superclassing EDIT window class
    By cDir in forum Windows Programming
    Replies: 7
    Last Post: 02-21-2002, 04:06 PM

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