tags:

views:

135

answers:

3

I know it is a very simple question but i currently cant create a parent window... My code:

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
static HWND paste;
static HWND update_list;

/*HWND changeuser =  CreateWindow(0, 0,    
                  0,
                  0, 0, x, y,        
                  0, (HMENU)changeuser2, 0, NULL); */

switch(msg)  
{

case WM_CREATE:
     meniu(hwnd);

     CreateWindow(TEXT("static"), TEXT("\nSuckers online:"),    
                  WS_VISIBLE | WS_CHILD | SS_CENTER,
                  0, 0, x, 55,        
                  hwnd, (HMENU)delete, NULL, NULL); 

    connected = CreateWindow(TEXT("edit"), TEXT(""),    
                  WS_VISIBLE | WS_CHILD | WS_VSCROLL| ES_MULTILINE ,
                  0, 60, x, 340,        
                  hwnd, (HMENU)delete2, NULL, NULL); 

    CreateWindow(TEXT("static"), TEXT(""),    
                  WS_VISIBLE | WS_CHILD | SS_CENTER|BS_PUSHBUTTON,
                  0, 405, x, 358,        
                  hwnd, (HMENU) delete3, NULL, NULL); 

    paste = CreateWindow(TEXT("Edit"), TEXT("Paste the ip here"),    
                  WS_VISIBLE | WS_CHILD | SS_CENTER,
                  x/2 - 60, 410, 120, 40,        
                  hwnd, (HMENU) ip, NULL, NULL); 

    CreateWindow(TEXT("Button"), TEXT("Connect!"),    
                  WS_VISIBLE | WS_CHILD | SS_CENTER | BS_PUSHBUTTON,
                  x/2 - 120, 450, 120, 40,        
                  hwnd, (HMENU) connect2, NULL, NULL); 

    update_list = CreateWindow(TEXT("Button"), TEXT("Update the list!"),  
                  WS_VISIBLE | WS_CHILD | SS_CENTER | BS_PUSHBUTTON,
                  x/2, 450, 120, 40,        
                  hwnd, (HMENU) update, NULL, NULL); 

    _beginthread( lista, 0, (void*)(0) );//begin thread lista

     break;

case WM_CTLCOLORSTATIC : {
    HBRUSH br = CreateSolidBrush(RGB(80,67,77)); // change background color
    SetTextColor((HDC)wParam,RGB(0,102,51)); //the controls text color
    return (LRESULT) br;
    }


 case WM_COMMAND:
     switch LOWORD(wParam)
     {

     case exit:
     PostQuitMessage(0);
     break;

     case ip:
     int nr;
     nr = GetWindowTextLength(paste);
     if (nr >= 17)
     SetWindowText(paste, "");
     break;//omor textul, ca sa pot sa fac paste

     case connect2:
      GetWindowText(paste,adresa,16);
     _beginthread( start, 0, (void*)(0) ); //as\ici se face conexiunea principala
     //DestroyWindow(hwnd);
     MessageBox(0,"Connected with the user","Ok",0);

     break;

     case update:
      exit2 = true;
      Sleep(100);
      SetWindowText(connected,"");
      _beginthread( lista, 0, (void*)(0) );//begin thread lista
      break;   
     }
    break;

 case WM_DESTROY:
     PostQuitMessage(0);
     break;

 }
  return DefWindowProc(hwnd, msg, wParam, lParam);

}

I want the other windows created to be the child of the changeuser window... I just cant make it happen... Any help will be appreciated!

A: 

I am trying to make a small gui... It will have mrore windows... So, at some point, i need to "delete" the old window, and create a new one... I can use DestroyWindow(hwnd), but it will destroy everything... So i need something to replace hwnd, another parent for some windows and so on....

zorro
Bump! Really nobody knows?
zorro
Please try to make that a comment or an edit to your question next time.
Georg Fritzsche
A: 

To change the window of a parent, use SetParent().
But i would think about the structure - if you need to change the parent of one or more windows in a normal dialog setting, it is likely these windows should have a different parent.

In your case there is a problem in your handling of window messages though:
If your message handler receives WM_DESTROY you call PostQuitMessage(), which probably results in your application closing.

There are two ways you can handle that:

  • use different window processes for your main dialog and child dialogs (preferably)
  • or use the hwnd parameter to decide wether you call PostQuitMessage()
Georg Fritzsche
A: 

You can't 'replace' a window. If you need to tear down and replace your main window, delete it and make a new one. Windows only get the parent flag when they have children, not because you tell them to.

bmargulies