Я проверял. У меня не пошлО Значит, я чего-то не так сделал. Где здесь ошибка?| Код | // Painting in WM_SIZE handler 2.cpp // // Возникает подозрение, что во время обработки сообщения WM_SIZE // нельзя рисовать на вновь появившейся части окна. // C FillRect однако все проходит нормально. // Сейчас попробуем ScrollWindow. // // 07.08.2006
#define _USE_METHOD_ 3 // 1 - standart method // 2 - Fixin's method // 3 - Earnest's method
#include <windows.h> #include <tchar.h>
const LPTSTR ClassName = _TEXT("Painting in WM_SIZE handler"); const LPTSTR MainWindowCaption = _TEXT("Painting in WM_SIZE handler"); const COLORREF ColorToFill = RGB(255, 69, 0);
int APIENTRY _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int); LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR CmdLine, int CmdShow) { WNDCLASS wc = {0}; wc.hCursor = LoadCursor(0, IDC_ARROW); wc.hInstance = hInstance; wc.lpfnWndProc = WindowProc; wc.lpszClassName = ClassName;
RegisterClass(&wc); HWND hWindow = CreateWindow( MainWindowCaption, ClassName, WS_OVERLAPPEDWINDOW, 100, 100, 100, 100, 0, 0, 0, 0);
ShowWindow(hWindow, CmdShow); UpdateWindow(hWindow);
MSG msg; while (true) { int a = GetMessage(&msg, 0, 0, 0);
if (a == 0) { return static_cast<int>(msg.wParam); }
if (a == -1) { return -1; }
DispatchMessage(&msg); } }
LRESULT CALLBACK WindowProc(HWND hWindow, UINT Message, WPARAM wParam, LPARAM lParam) { static bool First = true; static int WindowHeight = 0; switch (Message) {
/////////////////////////////////// // STANDART METHOD
#if _USE_METHOD_ == 1
case WM_SIZE: { // put a breakpoint here // ---------------------
RECT Rect; GetClientRect(hWindow, &Rect); if (Rect.bottom > WindowHeight && !First) { RECT NewRect = Rect; NewRect.bottom = WindowHeight; ScrollWindow(hWindow, 0, Rect.bottom - WindowHeight, &NewRect, 0); ValidateRect(hWindow, &Rect); }
WindowHeight = Rect.bottom; } return 0;
#endif
/////////////////////////////////// // FIXIN'S METHOD
#if _USE_METHOD_ == 2
case WM_GETMINMAXINFO: { if (First) { return 0; } RECT Rect; GetClientRect(hWindow, &Rect);
if (Rect.bottom > WindowHeight) { RECT NewRect = Rect; NewRect.bottom = WindowHeight; ScrollWindow(hWindow, 0, Rect.bottom - WindowHeight, &NewRect, 0); } } return 0;
case WM_SIZE: { RECT Rect; GetClientRect(hWindow, &Rect); if (!First) { ValidateRect(hWindow, &Rect); }
WindowHeight = Rect.bottom; } return 0;
#endif
/////////////////////////////////// // EARNEST'S METHOD
#if _USE_METHOD_ == 3
case WM_SIZE: { // put a breakpoint here // ---------------------
RECT Rect; GetClientRect(hWindow, &Rect); if (Rect.bottom > WindowHeight && !First) { PostMessage(hWindow, WM_USER + 1, WindowHeight, 0); ValidateRect(hWindow, &Rect); }
WindowHeight = Rect.bottom; } return 0;
case WM_USER + 1: { RECT Rect; GetClientRect(hWindow, &Rect);
int Delta = static_cast<int>(Rect.bottom) - static_cast<int>(wParam);
Rect.bottom = static_cast<long>(wParam);
ScrollWindow(hWindow, 0, Delta, &Rect, 0); } return 0;
#endif
///////////////////////////////////
case WM_ERASEBKGND:
return TRUE;
case WM_PAINT: { PAINTSTRUCT ps; HDC hDC = BeginPaint(hWindow, &ps);
if (First) { RECT Rect; GetClientRect(hWindow, &Rect); HBRUSH hBrush = CreateSolidBrush(ColorToFill); FillRect(hDC, &Rect, hBrush); DeleteObject(hBrush);
First = false; }
EndPaint(hWindow, &ps); } return 0;
case WM_DESTROY:
PostQuitMessage(0); return 0; } return DefWindowProc(hWindow, Message, wParam, lParam); }
|
|