帮忙看看。。
for (i = 0; i < 300; i++){
StringCchPrintf(str, 300, TEXT("%d"), i + 1);
StringCchLength(str, 300, &it);
for (j = it,t=0; j < 200; j++,t++)
{
if (t > 25) t = 0;
str = 'A' + t;
}
}
为什么编译运行后[]行号是乱码呢? 问题出在这一行:
staticstr;
改正如下:
#include <windows.h>
#include <strsafe.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 | WM_HSCROLL | WM_VSCROLL,
200,
100,
300,
200,
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)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
static TCHAR str;
int i, j, t;
size_t it;
TEXTMETRIC tm;
static int cxChar, cyChar, cxCou, cyCou;
switch (message)
{
case WM_SIZE:
hdc = GetDC(hwnd);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
GetTextMetrics(hdc, &tm);
GetClientRect(hwnd, &rect);
cxChar = tm.tmAveCharWidth;
cyChar = tm.tmHeight;
cxCou = (rect.right - rect.left) / cxChar;
cyCou = (rect.bottom - rect.top) / cyChar;
for (i = 0; i < 300; i++)
{
StringCchPrintf(&str, 200, TEXT("%d"), i + 1);
StringCchLength(&str, 200, &it);
for (j = it, t = 0; j < 200; j++, t++)
{
if (t > 25) t = 0;
str = 'A' + t;
}
}
ReleaseDC(hwnd, hdc);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
for (i = 0; i < cyCou; i++)
{
for (j = 0; j < cxCou; j++)
{
TextOut(hdc, cxChar*j, cyChar*i, &str, 1);
}
}
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
} 完整代码。。。。
#include <windows.h>
#include <strsafe.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 | WM_HSCROLL | WM_VSCROLL,
200,
100,
300,
200,
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)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
staticstr;
int i, j,t;
size_t it;
TEXTMETRIC tm;
static int cxChar, cyChar, cxCou, cyCou;
switch (message)
{
case WM_SIZE:
hdc = GetDC(hwnd);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
GetTextMetrics(hdc, &tm);
GetClientRect(hwnd, &rect);
cxChar = tm.tmAveCharWidth;
cyChar = tm.tmHeight;
cxCou = (rect.right - rect.left) / cxChar;
cyCou = (rect.bottom - rect.top) / cyChar;
for (i = 0; i < 300; i++)
{
StringCchPrintf(&str, 200, TEXT("%d"), i + 1);
StringCchLength(&str, 200, &it);
for (j = it,t=0; j < 200; j++,t++)
{
if (t > 25) t = 0;
str = 'A' + t;
}
}
ReleaseDC(hwnd, hdc);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
for (i = 0; i < cyCou; i++)
{
for (j = 0; j < cxCou; j++)
{
TextOut(hdc, cxChar*j, cyChar*i, &str, 1);
}
}
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
} 谢谢小甲鱼。。。。。
查了一晚上,{:5_109:} 请结贴,并发放赏金 察看汇编 看了半天,这是C。。。。。。。。。
页:
[1]