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:
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.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) ; }
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 (:



LinkBack URL
About LinkBacks


