Thread: CodeWork = TryCode(); if(!CodeWork) scream(hWnd);

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937

    CodeWork = TryCode(); if(!CodeWork) scream(hWnd);

    Hello. I created this function to resize the window to the size of the screen every time it needs to. At first it would only work once. Now it just doesn't work at all? (I call it in the WM_PAINT instance)

    PHP Code:
    bool AdjustWindowRes(HWND hWnd)
    {

        
    bool value true;
        
    RECT RepaintRect;
            
        
    GetWindowRect(hWnd,&RepaintRect);
        
    int wWidth  RepaintRect.right RepaintRect.left
        
    int wLength RepaintRect.bottom RepaintRect.top;                                  
        if (!
    wWidth == GetSystemMetrics(SM_CXSCREEN) || !wLength == GetSystemMetrics(SM_CYSCREEN))
                {
                 
    MoveWindow(hWnd,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),SWP_NOMOVE);
                }
        
    GetWindowRect(hWnd,&RepaintRect);
        
    wWidth  RepaintRect.right RepaintRect.left
        
    wLength RepaintRect.bottom RepaintRect.top;
        if (!
    wWidth == GetSystemMetrics(SM_CXSCREEN) || !wLength == GetSystemMetrics(SM_CYSCREEN))
            
    value false;

        return 
    value;

    Ok, that format is a bit wierd.... anyways, I call this code in the PAINT thing:

    PHP Code:
     bool Checker AdjustWindowRes(hWndMain);
                if(!
    Checker)
                    
    Debugger<<"ERROR: Unable to resize     window"<<endl
    It never returns false... but it doesn't work! I'm lost for ideas. You have any?
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    Well WM_SIZE would be the best place to put your code...and that SWP_NOMOVE thing, I've never seen it before, so hold on I'll look it up...Oh well nevermind, it just makes it retain the current position. Hmmm, well I have a better idea anyhow.

    ShowWindow(hwndMain, SW_MAXIMIZE);


    That will maximize your window.

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    even if there is not maximize option?
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    Ok, so even if there is a better way to resize it, that's not the problem.

    This bit of code:

    PHP Code:
    GetWindowRect(hWnd,&RepaintRect);
        
    wWidth  RepaintRect.right RepaintRect.left
        
    wLength RepaintRect.bottom RepaintRect.top;
        if (!
    wWidth == GetSystemMetrics(SM_CXSCREEN) || !wLength == GetSystemMetrics(SM_CYSCREEN))
            
    value false;

        return 
    value;

    should pick up if it didn't work. But it always goes true, even is the statement is false.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  5. #5
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    When you're testing for inequality you should do

    wWidth != GetSystemMetrics(SM_CXSCREEN)

  6. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    49
    it never returns false because

    !wWidth =0 (I assume your window has not a 0-width)

    and then

    !wWidth == GetSystemMetrics(SM_CXSCREEN) is always false.

    The same for :

    !wLength == GetSystemMetrics(SM_CYSCREEN)


    Just do:

    if (!(wWidth == GetSystemMetrics(SM_CXSCREEN)) || !(wLength == GetSystemMetrics(SM_CYSCREEN)))

    or

    if (wWidth != GetSystemMetrics(SM_CXSCREEN) || wLength != GetSystemMetrics(SM_CYSCREEN))

  7. #7
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    thanx.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed