Appereance of the message box due to the change of the window size

This is a discussion on Appereance of the message box due to the change of the window size within the Windows Programming forums, part of the Platform Specific Boards category; Hi. I'm new to windows programming, so I need some help. We had homework, and I did everything but one ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    3

    Appereance of the message box due to the change of the window size

    Hi. I'm new to windows programming, so I need some help.

    We had homework, and I did everything but one thing that I can't figure out.
    I need to change something in the code so that the message box doesn't appear all the time when I re-size the window, because doing so it allows me to re-size only for one pixel at time.. and not more.


    This is the code for my program:

    Code:
    #include <windows.h>
    #include <WINUSER.h>
    #include <stdio.h>
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
            PSTR szCmdLine, int iCmdShow)
    {
        HWND         hwnd ;
        MSG          msg ;
        WNDCLASS     wc ;
    
        wc.style         = CS_HREDRAW | CS_VREDRAW ;
        wc.lpfnWndProc   = WndProc ;
        wc.cbClsExtra    = 0 ;
        wc.cbWndExtra    = 0 ;
        wc.hInstance     = hInstance ;
        wc.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
        wc.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
        wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
        wc.lpszMenuName  = NULL ;
        wc.lpszClassName = "Moja klasa";
    
        if (!RegisterClass (&wc))
        {
            MessageBox (NULL, "Greska u registraciji klase",
                    "Greska", MB_ICONERROR) ;
            return 0 ;
        }
        hwnd = CreateWindow ("Moja klasa",  // ime windows klase
                "Zadaca 1", // tekst u Window title bar-u
                WS_OVERLAPPEDWINDOW, // stil prozora
                100,              // inicijalna x koordinata
                100,              // inicijalna y koordinata
                320,              // inicijalna sirina prozora
                250,              // inicijalna visina prozora
                NULL,            // handle na vlasnika (parent) prozora
                NULL,            // window menu handle
                hInstance,     // handle na instancu aplikacije
                NULL) ;        // dodatni kreacioni parametri
        ShowWindow (hwnd, iCmdShow) ;
        UpdateWindow (hwnd) ;
    
        while (GetMessage (&msg, NULL, 0, 0))
        {
            TranslateMessage (&msg) ;
            DispatchMessage (&msg) ;
        }
        return msg.wParam ;
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        static int cxClient, cyClient;
        HDC hdc;
        static PAINTSTRUCT ps;
        static RECT invalid;
        char poruka[] = "Homework";
        static SIZE sz;
        static char pismo[100];
    
        switch (message)
        {
            case WM_CREATE:
                 hdc = GetDC(hwnd);
                 GetTextExtentPoint32(hdc,poruka,strlen(poruka),&sz);
                 ReleaseDC(hwnd,hdc);
                 return 0;
    
            case WM_SIZE:
                 cxClient = LOWORD(lParam);
                 cyClient = HIWORD(lParam);
    
                 return 0;
    
            case WM_PAINT:
                 hdc = BeginPaint(hwnd,&ps);
                 GetClientRect(hwnd,&invalid);
                 TextOut(hdc,(cxClient - sz.cx),(cyClient -  sz.cy),poruka,strlen(poruka));
                 sprintf(pismo,"The size of the invalid area is:\n x=%ld \n y=%ld " ,invalid.right,invalid.bottom);
    
                 MessageBox (NULL, pismo,"Greska",   MB_ICONEXCLAMATION) ;
                 EndPaint(hwnd,&ps);
                 return 0;
    
            case WM_DESTROY:
                 PostQuitMessage (0) ;
                 return 0 ;
    
        }
        return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    Now if you run it you will see that as soon as you try to re-size the window (unless you maximize), the message box appears so you can move only for one pixel at time.
    And what I would want to is for me to be able to move it as much as I want to, and then only when I stop that it shows me the size of the invalid area.

    Thanks in advance (:

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Welllll you could comment out lines 81 and 83, recompile and test....see what happens...

    Really... it's pretty obvious.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    3
    But then I get rid of the message box and that's not what I need. I need to re-size and still have the message box.

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    3
    I've copied the wrong code here, and now I see why my question made no sense.
    This was supposed to be the case:
    Code:
    case WM_PAINT:
                hdc = BeginPaint(hwnd,&ps);
    
                TextOut(hdc,(cxClient - sz.cx),(cyClient - sz.cy),poruka,strlen(poruka));
                sprintf(pismo,"Velicina invalidnog podrucija je:\n x=%d \n y=%d " ,ps.rcPaint.right-ps.rcPaint.left,ps.rcPaint.bottom-ps.rcPaint.top);
    
                MessageBox (NULL, pismo,"Greska", MB_ICONEXCLAMATION) ;
    
                EndPaint(hwnd,&ps);
                return 0;
    We've figured it out today, but so thanks anyways (:

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Why would not not just display the message box at the end of resizing by processing the WM_EXITSIZEMOVE message?

    Message boxes in WM_PAINT are going to pop up at very unexpected times because repainting is a low priority message that is also sent in many other circumstances...

    A list of windows messages and their functions is HERE

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting a change message
    By publikum in forum Windows Programming
    Replies: 3
    Last Post: 02-05-2005, 11:02 AM
  2. why do my TCHARS change size?!
    By reanimated in forum C++ Programming
    Replies: 5
    Last Post: 01-12-2004, 04:52 AM
  3. window size VS. pixel size
    By dug in forum Windows Programming
    Replies: 2
    Last Post: 08-26-2003, 06:30 AM
  4. Replies: 0
    Last Post: 10-23-2002, 08:45 AM
  5. change array size
    By dontknow in forum C++ Programming
    Replies: 6
    Last Post: 04-05-2002, 01:25 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21