鱼C论坛

 找回密码
 立即注册
查看: 2769|回复: 6

帮忙看看。。

[复制链接]
发表于 2016-8-9 00:00:57 | 显示全部楼层 |阅读模式
1鱼币
         for (i = 0; i < 300; i++)
                {
                        StringCchPrintf(str[i], 300, TEXT("%d"), i + 1);
                        StringCchLength(str[i], 300, &it);
                        for (j = it,t=0; j < 200; j++,t++)
                        {
                                if (t > 25) t = 0;
                                str[i][j] = 'A' + t;
                               
                        }
                }
为什么编译运行后[]行号是乱码呢?
1.PNG

最佳答案

查看完整内容

问题出在这一行: 改正如下:
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-8-9 00:00:58 | 显示全部楼层
问题出在这一行:
  1. static  str[300][200];
复制代码


改正如下:
  1. #include <windows.h>
  2. #include <strsafe.h>

  3. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

  4. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
  5. {
  6.     static TCHAR szAppName[] = TEXT("MyWindows");
  7.     HWND hwnd;
  8.     MSG msg;
  9.     WNDCLASS wndclass;

  10.     wndclass.style = CS_HREDRAW | CS_VREDRAW;
  11.     wndclass.lpfnWndProc = WndProc;
  12.     wndclass.cbClsExtra = 0;
  13.     wndclass.cbWndExtra = 0;
  14.     wndclass.hInstance = hInstance;
  15.     wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  16.     wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  17.     wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  18.     wndclass.lpszMenuName = NULL;
  19.     wndclass.lpszClassName = szAppName;

  20.     if (!RegisterClass(&wndclass))
  21.     {
  22.         MessageBox(NULL, TEXT("这个程序需要在 Windows NT 才能执行!"), szAppName, MB_ICONERROR);
  23.         return 0;
  24.     }

  25.     hwnd = CreateWindow(szAppName,
  26.         TEXT("鱼C工作室"),
  27.         WS_OVERLAPPEDWINDOW | WM_HSCROLL | WM_VSCROLL,
  28.         200,
  29.         100,
  30.         300,
  31.         200,
  32.         NULL,
  33.         NULL,
  34.         hInstance,
  35.         NULL);

  36.     ShowWindow(hwnd, iCmdShow);
  37.     UpdateWindow(hwnd);

  38.     while (GetMessage(&msg, NULL, 0, 0))
  39.     {
  40.         TranslateMessage(&msg);
  41.         DispatchMessage(&msg);
  42.     }

  43.     return msg.wParam;
  44. }

  45. LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  46. {
  47.     HDC hdc;
  48.     PAINTSTRUCT ps;
  49.     RECT rect;

  50.     static TCHAR str[300][200];
  51.     int i, j, t;
  52.     size_t it;
  53.     TEXTMETRIC tm;
  54.     static int cxChar, cyChar, cxCou, cyCou;

  55.     switch (message)
  56.     {
  57.     case WM_SIZE:
  58.         hdc = GetDC(hwnd);
  59.         SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
  60.         GetTextMetrics(hdc, &tm);
  61.         GetClientRect(hwnd, &rect);
  62.         cxChar = tm.tmAveCharWidth;
  63.         cyChar = tm.tmHeight;
  64.         cxCou = (rect.right - rect.left) / cxChar;
  65.         cyCou = (rect.bottom - rect.top) / cyChar;

  66.         for (i = 0; i < 300; i++)
  67.         {
  68.             StringCchPrintf(&str[i][0], 200, TEXT("%d"), i + 1);
  69.             StringCchLength(&str[i][0], 200, &it);
  70.             for (j = it, t = 0; j < 200; j++, t++)
  71.             {
  72.                 if (t > 25) t = 0;
  73.                 str[i][j] = 'A' + t;

  74.             }
  75.         }
  76.         ReleaseDC(hwnd, hdc);
  77.         return 0;
  78.     case WM_PAINT:
  79.         hdc = BeginPaint(hwnd, &ps);
  80.         SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
  81.         for (i = 0; i < cyCou; i++)
  82.         {
  83.             for (j = 0; j < cxCou; j++)
  84.             {
  85.                 TextOut(hdc, cxChar*j, cyChar*i, &str[i][j], 1);
  86.             }
  87.         }

  88.         EndPaint(hwnd, &ps);
  89.         return 0;


  90.     case WM_DESTROY:

  91.         PostQuitMessage(0);
  92.         return 0;
  93.     }

  94.     return DefWindowProc(hwnd, message, wParam, lParam);
  95. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2016-8-9 00:30:47 | 显示全部楼层
完整代码。。。。


#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  str[300][200];
        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[i][0], 200, TEXT("%d"), i + 1);
                        StringCchLength(&str[i][0], 200, &it);
                        for (j = it,t=0; j < 200; j++,t++)
                        {
                                if (t > 25) t = 0;
                                str[i][j] = '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[i][j], 1);
                        }
                }

                EndPaint(hwnd, &ps);
                return 0;


        case WM_DESTROY:

                PostQuitMessage(0);
                return 0;
        }

        return DefWindowProc(hwnd, message, wParam, lParam);
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2016-8-9 01:35:16 | 显示全部楼层
谢谢小甲鱼。。。。。
查了一晚上,
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-8-12 17:40:34 | 显示全部楼层
请结贴,并发放赏金
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-8-15 13:36:04 | 显示全部楼层
察看汇编
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-8-18 22:26:28 | 显示全部楼层
看了半天,这是C。。。。。。。。。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-27 05:17

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表