|
发表于 2015-3-11 08:50:11
|
显示全部楼层
明显上面的是有问题的
(修改版)
#include <windows.h>
#include "strsafe.h"
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int nCmdShow)
{
TCHAR szAppName[] = TEXT("Windows程序设计");
WNDCLASSEX wndClass;
MSG msg;
HWND hwnd;
wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndClass.hIconSm = NULL;
wndClass.hInstance = hInstance;
wndClass.lpszClassName = TEXT("AppTest0");
wndClass.lpszMenuName = NULL;
wndClass.lpfnWndProc = WndProc;
wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_IME;
RegisterClassEx(&wndClass);
hwnd = CreateWindowEx(WS_EX_TOPMOST, TEXT("AppTest0"), szAppName, WS_OVERLAPPED |
WS_CAPTION |
WS_SYSMENU |
WS_MINIMIZEBOX | WS_SIZEBOX
, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
int a = ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static int cxScr = 0, cyScr = 0, cxClient = 0, cyClient = 0, time;
TCHAR Buffer[1024];
PAINTSTRUCT ps;
static int n = 0;
switch (msg)
{
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
break;
case WM_SIZING:
wsprintf(Buffer, TEXT("窗口分辨率:%d, %d px"), cxClient, cyClient);
TextOut(GetDC(hwnd), 0, 0, Buffer, lstrlen(Buffer));
if (((LPRECT)lParam)->bottom - ((LPRECT)lParam)->top < 200)
{
if (wParam == WMSZ_BOTTOM)
((LPRECT)lParam)->bottom = ((LPRECT)lParam)->top + 200;
if (wParam == WMSZ_TOP)
((LPRECT)lParam)->top = ((LPRECT)lParam)->bottom - 200;
if (wParam == WMSZ_BOTTOMLEFT)
{
((LPRECT)lParam)->bottom = ((LPRECT)lParam)->top + 200;
if (((LPRECT)lParam)->right - ((LPRECT)lParam)->left < 200)
((LPRECT)lParam)->left = ((LPRECT)lParam)->right - 200;
}
if (wParam == WMSZ_BOTTOMRIGHT)
{
((LPRECT)lParam)->bottom = ((LPRECT)lParam)->top + 200;
if (((LPRECT)lParam)->right - ((LPRECT)lParam)->left < 200)
((LPRECT)lParam)->right = ((LPRECT)lParam)->left + 200;
}
if (wParam == WMSZ_TOPLEFT)
{
((LPRECT)lParam)->top = ((LPRECT)lParam)->bottom - 200;
if (((LPRECT)lParam)->right - ((LPRECT)lParam)->left < 200)
((LPRECT)lParam)->left = ((LPRECT)lParam)->right - 200;
}
if (wParam == WMSZ_TOPRIGHT)
{
((LPRECT)lParam)->top = ((LPRECT)lParam)->bottom - 200;
if (((LPRECT)lParam)->right - ((LPRECT)lParam)->left < 200)
((LPRECT)lParam)->right = ((LPRECT)lParam)->left + 200;
}
}
if (((LPRECT)lParam)->right - ((LPRECT)lParam)->left < 200)
{
if (wParam == WMSZ_RIGHT)
((LPRECT)lParam)->right = ((LPRECT)lParam)->left + 200;
if (wParam == WMSZ_LEFT)
((LPRECT)lParam)->left = ((LPRECT)lParam)->right - 200;
if (wParam == WMSZ_BOTTOMLEFT)
{
((LPRECT)lParam)->left = ((LPRECT)lParam)->right - 200;
if (((LPRECT)lParam)->bottom - ((LPRECT)lParam)->top < 200)
((LPRECT)lParam)->bottom = ((LPRECT)lParam)->top + 200;
}
if (wParam == WMSZ_BOTTOMRIGHT)
{
((LPRECT)lParam)->right = ((LPRECT)lParam)->left + 200;
if (((LPRECT)lParam)->bottom - ((LPRECT)lParam)->top < 200)
((LPRECT)lParam)->bottom = ((LPRECT)lParam)->top + 200;
}
if (wParam == WMSZ_TOPLEFT)
{
((LPRECT)lParam)->left = ((LPRECT)lParam)->right - 200;
if (((LPRECT)lParam)->bottom - ((LPRECT)lParam)->top < 200)
((LPRECT)lParam)->top = ((LPRECT)lParam)->bottom - 200;
}
if (wParam == WMSZ_TOPRIGHT)
{
((LPRECT)lParam)->right = ((LPRECT)lParam)->left + 200;
if (((LPRECT)lParam)->bottom - ((LPRECT)lParam)->top < 200)
((LPRECT)lParam)->top = ((LPRECT)lParam)->bottom - 200;
}
}
break;
case WM_PAINT:
n++;
wsprintf(Buffer, TEXT("重绘的次数:%d "), n);
TextOut(GetDC(hwnd), 0, 15, Buffer, lstrlen(Buffer));
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
} |
|