problem with resizing an Edit box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ayan4u
    New Member
    • Apr 2007
    • 86

    problem with resizing an Edit box

    [CODE=c]

    HWND gEditBox;

    int APIENTRY WinMain(....)
    {
    HWND hWnd;
    ...
    ...
    ...

    WNDCLASSEX wcex;

    wcex.style = CS_HREDRAW | CS_VREDRAW;
    ..
    ..
    ..
    // Main Window
    hWnd = CreateWindow(sz WindowClass, szTitle, WS_OVERLAPPEDWI NDOW,CW_USEDEFA ULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
    ..
    ..
    }


    LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    switch(msg)
    {
    case WM_CREATE:

    RECT rect;
    GetClientRect(h Wnd, &rect);

    // Creating Edit Box
    gEditBox = CreateWindow("E DIT", NULL, WS_CHILD | WS_HSCROLL |
    WS_VSCROLL | WS_VISIBLE | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_WANTRETURN | ES_MULTILINE | ES_LEFT | ES_NOHIDESEL, 0, 0, rect.right, rect.bottom, hWnd, (HMENU)IDC_TEXT PAD, ((LPCREATESTRUC T)lParam)->hInstance, NULL);

    beak;

    case WM_COMMAND:
    wmId = LOWORD(wParam);
    wmEvent = HIWORD(wParam);
    switch(wmId)
    {
    ...
    ...
    ..
    }
    }

    [/CODE]

    I have created an Edit box through Createwindow() as the WinProc recieves the WM_CREATE message
    Now everything is working fine but except that when i maximise my parent window or resize it the edit box fails to do so though it is declared a child window.
    How could i fix this?

    if my problem is not understood should i post the entire code here for better analysis...
  • Studlyami
    Recognized Expert Contributor
    • Sep 2007
    • 464

    #2
    I believe you have to handle the resize automatically. You can capture the WM_SIZE grab the rect of the main window then resize the edit box as needed.

    Comment

    • ayan4u
      New Member
      • Apr 2007
      • 86

      #3
      Originally posted by Studlyami
      I believe you have to handle the resize automatically. You can capture the WM_SIZE grab the rect of the main window then resize the edit box as needed.

      well i tried that...

      captured the WM_SIZE message and then used

      DestroyWindow(g EditBox)

      SendMessage(hWn d, WM_CREATE, 0, 0);

      so that the edit box is created again but there an access violation is occuring in CreateWindow() i.e, when it is called through WM_SIZE

      BTW a WM_SIZE message is also dispatched as soon as a window is created along with WM_CREATE so now i am using WM_SIZING

      Comment

      • Studlyami
        Recognized Expert Contributor
        • Sep 2007
        • 464

        #4
        I wouldn't destroy the edit box on WM_SIZE; you just need to set the window position.

        The way i would handle this is have a global variable that holds the old parent window rect. find how far it moves to the left and right and set the edit box to the left and right. To scale the size you need to know how much of the parent you want the edit box to take up. The example below uses 75% of the parent window.

        Also in your WM_SIZE you will need to ensure that the EditBoxHandle != NULL before you call the ResizeEdit function.

        EX:
        Code:
        RECT OldParentRect;
        
        void ResizeEdit(hWnd)
        {
           //hWnd = parent window
            RECT TempRect;
            GetWindowRect(hWnd, &TempRect);
             int EditBoxPositionX += (TempRect.left-OldParentRect.left); 
              int EditBoxPositionY += (TempRect.top-OldParentRect.top);
             int EdbitBoxPositionXc = EditBoxPositionX + ((TempRect.right-TempRect.left) *.75);
           int EdbitBoxPositionYc = EditBoxPositionY+ ((TempRect.bottom-TempRect.top) *.75);
             SetWindowPos(EditBoxhWnd, EditBoxPositionX, EditBoxPositionY, EditBoxPositionXc,  EditBoxPositionYc,)
           OldParentRect = TempRect;  //i think that needs the function copy rect don't remember.
        }

        Comment

        • ayan4u
          New Member
          • Apr 2007
          • 86

          #5
          Originally posted by Studlyami
          I wouldn't destroy the edit box on WM_SIZE; you just need to set the window position.

          The way i would handle this is have a global variable that holds the old parent window rect. find how far it moves to the left and right and set the edit box to the left and right. To scale the size you need to know how much of the parent you want the edit box to take up. The example below uses 75% of the parent window.

          Also in your WM_SIZE you will need to ensure that the EditBoxHandle != NULL before you call the ResizeEdit function.

          EX:
          Code:
          RECT OldParentRect;
           
          void ResizeEdit(hWnd)
          {
          //hWnd = parent window
          RECT TempRect;
          GetWindowRect(hWnd, &TempRect);
          int EditBoxPositionX += (TempRect.left-OldParentRect.left); 
          int EditBoxPositionY += (TempRect.top-OldParentRect.top);
          int EdbitBoxPositionXc = EditBoxPositionX + ((TempRect.right-TempRect.left) *.75);
          int EdbitBoxPositionYc = EditBoxPositionY+ ((TempRect.bottom-TempRect.top) *.75);
          SetWindowPos(EditBoxhWnd, EditBoxPositionX, EditBoxPositionY, EditBoxPositionXc, EditBoxPositionYc,)
          OldParentRect = TempRect; //i think that needs the function copy rect don't remember.
          }

          hmmm thanks a lot...i will try to implement that....but wonder wht creating a new edit window afresh is not working....thou gh this technique is very bad as i must admit...neways thanx a lot again

          Comment

          Working...