Thread: is it possible to:

  1. #1
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681

    is it possible to:

    1) Keep a window from being resized?
    2) Launch another window with buttons and such?

    Being trying to find a good example for #2 for a couple days but coming up dry. Any help would be great. Thanks

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    launching another window is just a matter of a CreateWindow() call, or is that not what you mean.

    I think a window that is not WS_OVERLAPPED is not sizeable
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Problem I'm facing is when doing the WM_PAINT is setting up the code to determine which window to put the info into.

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    so you're using the same callback? If so, you can either key off of the hWnd (bad method) or use GetWindowLong() and SetWindowLong with the GWL_USERDATA parameter to store a pointer specific to that window.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  5. #5
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Most people use the WS_OVERLAPPEDWINDOW style for a standard window which is the same as the WS_OVERLAPPED, WS_CAPTION, WS_SYSMENU, WS_THICKFRAME, WS_MINIMIZEBOX, and WS_MAXIMIZEBOX styles. Remove the WS_THICKFRAME style to remove the re-sizing border.

    If you wish to restrict resizing in a specific way, you can process the WM_SIZING message, and change the resizing rectangle before it takes effect, as the user is resizing the window. I use this to allow for a user to resize a window that is stuck to the corner of the screen.

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Ok here is what I got so far. This creates two windows and its a good base for what I want to do I think. Problem is that the second window shows up on the task bar and when alt-tabing. Anyway to keep that from happening?

    Code:
    #include <windows.h>
    #include <tchar.h>
    #include <stdio.h>
    #include <winuser.h>
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK WndProc2 (HWND, UINT, WPARAM, LPARAM);
    
    int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...);
    
    char *titles (void);
    char *names (void);
    
    int title=2, name=1;
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
                        
    {
        static TCHAR szAppName[] = TEXT ("HelloWin");
        static TCHAR szAppName2[] = TEXT ("#2 Win");
    
        int tmp;
    
        HWND        hwnd, hwnd2, hwnd3, hwnd4;
        MSG         msg;
        WNDCLASS    wndclass, wndclass2;
        
        wndclass.style        = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc  = WndProc;
        wndclass.cbClsExtra   = 0;
        wndclass.cbWndExtra   = 0;
        wndclass.hInstance    = hInstance;
        wndclass.hIcon        = LoadIcon (NULL, IDC_ARROW);
        wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 
        wndclass.lpszMenuName = NULL;
        wndclass.lpszClassName = szAppName;
        wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
        
        wndclass2.style        = CS_HREDRAW | CS_VREDRAW;
        wndclass2.lpfnWndProc  = WndProc2;
        wndclass2.cbClsExtra   = 0;
        wndclass2.cbWndExtra   = 0;
        wndclass2.hInstance    = hInstance;
        wndclass2.hIcon        = LoadIcon (NULL, IDC_ARROW);
        wndclass2.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 
        wndclass2.lpszMenuName = NULL;
        wndclass2.lpszClassName = szAppName2;
        wndclass2.hCursor=LoadCursor(NULL,IDC_ARROW);
        
        
        if ( !RegisterClass (&wndclass))
            {
            tmp = GetLastError();
            MessageBoxPrintf( TEXT ("Error"),
                              TEXT ("Error Number: %i"), tmp); 
            return 0;
            }
        
        if ( !RegisterClass (&wndclass2))
            {
            tmp = GetLastError();
            MessageBoxPrintf( TEXT ("Error"),
                              TEXT ("Error Number: %i"), tmp); 
            return 0;
            }
    
    
        hwnd = CreateWindow (szAppName,
                             TEXT ("The Hello Program"),
                             WS_OVERLAPPEDWINDOW,
                             10,
                             10,
                             200,
                             200,
                             NULL,
                             NULL,
                             hInstance,
                             NULL);
        
        hwnd2 = CreateWindow (szAppName2,
                              TEXT("POPUP"),
                              WS_OVERLAPPED,
                              500,
                              500,
                              200,
                              200,
                              NULL,
                              NULL,
                              hInstance,
                              NULL);
    
        ShowWindow (hwnd, iCmdShow);                     
        UpdateWindow (hwnd);
        
        ShowWindow (hwnd2, iCmdShow);
        UpdateWindow (hwnd2);
        
        while (GetMessage (&msg, NULL, 0, 0))
            {
            TranslateMessage (&msg);
            DispatchMessage (&msg);
            }
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        HDC             hdc;
        PAINTSTRUCT     ps;
        RECT            rect;
        TCHAR           szBuffer[100];
        
        switch (message)
            {
            case WM_CREATE:
                    return 0;
                    
            case WM_PAINT:
                    hdc = BeginPaint (hwnd, &ps);
                    GetClientRect (hwnd, &rect);
                    wsprintf(szBuffer, TEXT ("%s %s"), titles(), names());
                    DrawText ( hdc, szBuffer, -1, &rect,
                               DT_SINGLELINE | DT_CENTER);
                    
                    EndPaint (hwnd, &ps);              
                    
                    return 0;
                    
            case WM_DESTROY:
                    PostQuitMessage (0);
                    return 0;
            
            }
        return DefWindowProc (hwnd, message, wParam, lParam);
    }
    
    LRESULT CALLBACK WndProc2 (HWND hwnd2, UINT message, WPARAM wParam, LPARAM lParam)
    {
        HDC             hdc;
        PAINTSTRUCT     ps;
        RECT            rect;
        TCHAR           szBuffer[100];
        
        switch (message)
            {
            case WM_CREATE:
                    return 0;
                    
            case WM_PAINT:
                    hdc = BeginPaint (hwnd2, &ps);
                    GetClientRect (hwnd2, &rect);
                    DrawText ( hdc, TEXT("#2"), -1, &rect,
                               DT_SINGLELINE | DT_CENTER);
                    
                    EndPaint (hwnd2, &ps);              
                    
                    return 0;
                    
            case WM_DESTROY:
                    PostQuitMessage (0);
                    return 0;
            
            }
        return DefWindowProc (hwnd2, message, wParam, lParam);
    }
    
    
    int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...)
    {
        TCHAR   szBuffer [1024];
        va_list pArgList;
        
        va_start (pArgList, szFormat);
        
        _vsntprintf (szBuffer, sizeof (szBuffer) / sizeof (TCHAR),
                     szFormat, pArgList);
        
        va_end (pArgList);
        
        return MessageBox (NULL, szBuffer, szCaption, 0);
    }
    
    char* titles(void)
    {
    switch (title)
           {
           case 0:
                return ("Dirt Ball");
                break;
    
           case 1:
                return ("Serf");
                break;
    
           case 2:
                return ("Peasant");
                break;
    
           case 3:
                return ("Adventurer");
                break;
    
           case 4:
                return ("Governer");
                break;
                
           case 5:
                return ("Grand Governer");
                break;
    
           case 6:
                return ("Duke");
                break;
    
           case 7:
                return ("King");
                break;
    
           }
    }
    
    char* names (void)
    {
    switch (name)
        {
        case 0:
            return ("Gnos");
        case 1:
            return ("Bob");
        case 2:
            return ("Michael");
        case 3:
            return ("Shirley");
        }
    }

  7. #7
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Make it a child window of the first one and then subclass it to give it its own WNDPROC.

  8. #8
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Better yet, use CreateWindowEx() and specify the extended style WS_EX_TOOLWINDOW. It seems like the one you need.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  9. #9
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Thanks, using CreateWindowEX did the trick perfectly.

Popular pages Recent additions subscribe to a feed