|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我想要实现的是每次击键对应的链表会增加一个,那样在WM_PAINT中随着击键次数的增多i的值也会相应的增大,但i的值有时候会忽然变小然后接着涨大,一段时间的累加后又会变小,就像是链表断开了,有人知道为什么会断开吗
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT("MyWindows");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("这个程序需要在 Windows NT 才能执行!"), szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName,
TEXT("鱼C工作室"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
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)
{
typedef struct EnglishChar {
MSG msg;
struct EnglishChar *next;
}ec;
static ec *head = NULL;
ec *biaoji;
static int cxLines, cyLines, cxChar, cyChar, cxClient, cyClient;
int i;
TCHAR buffer[7];
TEXTMETRIC tm;
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch (message)
{
case WM_CREATE:
hdc = GetDC(hwnd);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
GetTextMetrics(hdc, &tm);
cxChar = tm.tmAveCharWidth;
cyChar = tm.tmHeight;
ReleaseDC(hwnd, hdc);
return 0;
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
return 0;
case WM_CHAR:
{
ec * p = (ec*)malloc(sizeof(ec*));
for (;;)
{
if (!p)
{
p = (ec*)malloc(sizeof(ec*));
}
else
break;
}
p->msg.wParam = wParam;
p->next = NULL;
ec* last = head;
if (head)
{
while (last->next)
{
last = last->next;
}
last->next = p;
}
else
head = p;
InvalidateRect(hwnd, NULL, TRUE);
return 0;
}
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
biaoji = head;
i = 0;
if (biaoji)
{
for (biaoji; biaoji; biaoji = biaoji->next)
{
i++;
}
}
wsprintf(buffer, TEXT("%d"), i);
TextOut(hdc, 0, 0, buffer, lstrlen(buffer));
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
|
|