Results 1 to 3 of 3

Thread: Stop controls from floating around (and yes, they are children of the main form)

  1. #1

    Thread Starter
    Lively Member dubae524's Avatar
    Join Date
    Jun 2001
    Location
    Currently on this Super Star Destroyer being telekinetically strangled to death by Darth Vader
    Posts
    78

    Angry Stop controls from floating around (and yes, they are children of the main form)

    PHP Code:
    #include <windows.h>

    HINSTANCE trackinst;
    HWND myformpushbuttoneditbox;
    LRESULT CALLBACK WindowProc(HWND hwndUINT wMsgWPARAM wParamLPARAM lParam);

    int WINAPI WinMain(HINSTANCE myinstHINSTANCE beforeinstLPSTR cmdsint nFunsterStil) {
        
    WNDCLASSEX wndcl;
        
    MSG messages;
        
    char szClassName[ ] = "WindowsApp";
        
        
    trackinst myinst;

        
    wndcl.cbClsExtra 0;
        
    wndcl.cbSize sizeof(WNDCLASSEX);
        
    wndcl.cbWndExtra 0;
        
    wndcl.hbrBackground = (HBRUSHGetStockObject(LTGRAY_BRUSH);
        
    wndcl.hCursor LoadCursor(NULLIDC_ARROW);
        
    wndcl.hIcon LoadIcon(NULLIDI_APPLICATION);
        
    wndcl.hIconSm LoadIcon(NULLIDI_APPLICATION);
        
    wndcl.hInstance myinst;
        
    wndcl.lpfnWndProc WindowProc;
        
    wndcl.lpszClassName szClassName;
        
    wndcl.lpszMenuName NULL;
        
    wndcl.style 0;

        if (!
    RegisterClassEx(&wndcl)) return 0;

        
    myform CreateWindowEx(0,
                                
    szClassName,
                                
    "Push the Button",
                                
    WS_BORDER || WS_CAPTION || WS_VISIBLE,
                                
    500500600300,
                                
    HWND_DESKTOP,
                                
    NULL,
                                
    myinst,
                                
    NULL);

        
    ShowWindow(myformnFunsterStil);

        
    pushbutton CreateWindowEx(0,
                                    
    "BUTTON",
                                    
    "Click me!",
                                    
    WS_CHILD || WS_VISIBLE,
                                    
    4007576150,
                                    
    myform,
                                    
    NULL,
                                    
    myinst,
                                    
    NULL);

        
    ShowWindow(pushbuttonSW_SHOW);

        
    editbox CreateWindowEx(0,
                                 
    "EDIT",
                                 
    "jj",
                                 
    WS_CHILD || WS_VISIBLE,
                                 
    010060026,
                                 
    myform,
                                 
    NULL,
                                 
    myinst,
                                 
    NULL);

        
    ShowWindow(editboxSW_SHOW);

        while (
    GetMessage(&messagesNULL00)) {
            
    TranslateMessage(&messages);
            
    DispatchMessage(&messages);
        }

        return 
    messages.wParam;
    }

    LRESULT CALLBACK WindowProc(HWND hwndUINT wMsgWPARAM wParamLPARAM lParam) {
        switch (
    wMsg) {
        case 
    WM_DESTROY:
            
    PostQuitMessage(0);
            break;
        case 
    WM_LBUTTONDOWN:
            if((
    HWND)lParam == pushbutton) {
                
    SetWindowText(editbox"Hello, world!");
            }
        }
        return 
    0;

    (Yes, I know some C++: I worked mainly with consoles but now am trying to go to Win32. With that, the difficulty level went way up!)

    That was the entire code, I personally think it has something to do with the ShowWindow function for creating the form. I'll check back tomorrow, see ya!
    - Justin Patrick Butler

    Comme je trouve. "As I find."
    - Butler family quote

    Beneficia sumptos procul superant. "The benefits far exceed the costs."
    - Myself

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I don't understand your problem, but here are some things I noticed in your code:
    1) Why do you use CreateWindowEx if you don't use the dwStyleEx parameter?
    2) Do you want the main window as a child of the desktop? If so, add the WS_CHILD style. If not, supply NULL as hwndParent.
    3) You should avoid global variables as much as possible. It's not necessary to use globals for all these windows.
    4) Create the child windows in the message handler for WM_CREATE, and save their handles in static variables of the window functions (maybe this even solves you problem, not sure however)
    5) Use either WS_VISIBLE or ShowWindow, not both. Usually you use ShowWindow (and UpdateWindow) for the main window, and WS_VISIBLE for it's childs.
    6) Use while(GetMessage(...) > 0). This is a trick I just recently learned and that honors the fact that GetMessage returns 0 in case of a failure.
    7) Use a different approach to test if the button was clicked:
    Code:
    // instead of
         case WM_LBUTTONDOWN:
         .
         .
    
    // use
        case WM_COMMAND:
             switch(HIWORD(wParam))
             {
              case EN_CLICKED:
                   if(lParam == hwndButton)
                   {
                         // do whatever you want
                   }
                   break;
             }
    This has the advantage of better extensibility and avoids an unnecessary hit test (windows performs it's own hit test regardless of what you do)

    That's all for now
    All the buzzt
    CornedBee

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Also, you should assign an ID to the child windows (using the hMenu parameter)

    All the buzzt
    CornedBee

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width