设为首页收藏本站

新微赢技术网

 找回密码
 注册
搜索
热搜: 回贴
查看: 1207|回复: 1
打印 上一主题 下一主题

请教高手,我是初学者,问题出在哪,谢谢啦!

[复制链接]
跳转到指定楼层
1#
发表于 2009-11-4 00:54:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
# include <windows.h>
# include <stdio.h>

LRESULT CALLBACK WinSunProc(
    HWND hwnd,
    UINT uMag,
    WPARAM wParam,
    LPARAM lParam
)


int WINAPI WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow
)
{
    WNDCLASS wndcls;
    wndcls.cbClsExtra=0;
    wndcls.cbWndExtra=0;
    wndcls.hbrBackgroud=(HBRUSH)GetStockObject(BLACK_BRUSH);
    wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
    wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
    wndcls.hInstance=hInstance;
    wndcls.lpfnWndProc=WinSunProc;
    wndcls.lpszClassName="radio983";
    wndcls.lpszMenuName=NULL;
    wndcls.style=CS_HREDRAW | CS_VREDRAW;
    RegristerCLASS(&wndcls);

    HWND Hwnd;
    Hwnd=CreateWindow("radio983","抄袭编程",WS_OVERLAPPEDWINDOW,
        0,0,800,600,NULL,NULL,hInstance,NULL);
    ShowWindow(Hwnd,SW_SHOWNORMAL);
    UpdateWindow(Hwnd);

    MSG msg;
    while(GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}

LRESULT CALLBACK WinSunProc(
    HWND hwnd,
    UINT uMag,
    WPARAM wParam,
    LPARAM lParam
)
{
    switch(uMag)
    {
    case WM_CHAR:
        char szChar[20];
        sprintf(szChar,"char is %d,wParam);
        MessageBox(hwnd,szChar,"radio983",0);
        break;
    case WM_LBUTTONDOWN:
        MessageBox(hwnd,"mouse clicked","radio983",0);
        HDC=hdc;
        TextOut(hdc,0,50,"抄袭",strlen("抄袭"));
        ReleaseDc(hwnd,hdc);
        break;
    case WM_PAINT:
        HDC=hDC;
        PAINTSTRUCT ps;
        hDc=BeginPaint(hwnd,&ps);
        TextOut(hDc,0,0,"偷袭",strlen("偷袭"));
        EndPaint(hwnd,&ps);
        break;
    case WN_CLOSE:
        if(IDYES==MessageBox(hwnd,"是否真得结束?","radio983",MB_YESNO))
        {
            DestroyWindow(hwnd);
        }
        break;
    case WN_DESTORY:
        PostQuitMessage(0);
        break;
    default:
        return DfeWindowProc(hwnd,uMag,wParam,lParam);
    }
    return 0;
}

————————————————————————————————————————————
--------------------Configuration: winmain - Win32 Debug--------------------
Compiling...
winmain.cpp
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(12) : warning C4518: 'int ' : storage-class or type specifier(s) unexpected here; ignored
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(12) : error C2143: syntax error : missing ';' before '__stdcall'
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(22) : error C2039: 'hbrBackgroud' : is not a member of 'tagWNDCLASSA'
        d:\vc98\include\winuser.h(1184) : see declaration of 'tagWNDCLASSA'
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(30) : error C2065: 'RegristerCLASS' : undeclared identifier
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(58) : error C2001: newline in constant
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(59) : error C2146: syntax error : missing ')' before identifier 'MessageBoxA'
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(63) : error C2513: 'struct HDC__ *' : no variable declared before '='
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(63) : error C2065: 'hdc' : undeclared identifier
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(65) : error C2065: 'ReleaseDc' : undeclared identifier
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(68) : error C2513: 'struct HDC__ *' : no variable declared before '='
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(68) : error C2065: 'hDC' : undeclared identifier
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(70) : error C2065: 'hDc' : undeclared identifier
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(70) : error C2440: '=' : cannot convert from 'struct HDC__ *' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(74) : error C2065: 'WN_CLOSE' : undeclared identifier
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(74) : error C2051: case expression not constant
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(80) : error C2065: 'WN_DESTORY' : undeclared identifier
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(80) : error C2051: case expression not constant
D:\Program Files\MSDev98\MyProjects\lesson1\winmain.cpp(84) : error C2065: 'DfeWindowProc' : undeclared identifier
执行 cl.exe 时出错.

winmain.exe - 1 error(s), 0 warning(s)
2#
发表于 2009-11-4 00:54:25 | 只看该作者
# include <windows.h>
# include <stdio.h>

LRESULT CALLBACK WinSunProc(
    HWND hwnd,
    UINT uMag,
    WPARAM wParam,
    LPARAM lParam
);//函数的声明,要;号


int WINAPI WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow
)
{
    WNDCLASS wndcls;
    wndcls.cbClsExtra=0;
    wndcls.cbWndExtra=0;
    wndcls.hbrBackground =(HBRUSH)GetStockObject(BLACK_BRUSH);//你单词错了
    wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
    wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
    wndcls.hInstance=hInstance;
    wndcls.lpfnWndProc=WinSunProc;
    wndcls.lpszClassName="radio983";
    wndcls.lpszMenuName=NULL;
    wndcls.style=CS_HREDRAW | CS_VREDRAW;
    RegisterClass(&wndcls);//你单词错了

    HWND Hwnd;
    Hwnd=CreateWindow("radio983","抄袭编程",WS_OVERLAPPEDWINDOW,
        0,0,800,600,NULL,NULL,hInstance,NULL);
    ShowWindow(Hwnd,SW_SHOWNORMAL);
    UpdateWindow(Hwnd);

    MSG msg;
    while(GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}

LRESULT CALLBACK WinSunProc(
    HWND hwnd,
    UINT uMag,
    WPARAM wParam,
    LPARAM lParam
)
{
    switch(uMag)
    {
    case WM_CHAR:
        char szChar[20];
        sprintf(szChar,"char is %d",wParam);//掉了"
        MessageBox(hwnd,szChar,"radio983",0);
        break;
    case WM_LBUTTONDOWN:
        MessageBox(hwnd,"mouse clicked","radio983",0);
        HDC hdc;//定义句柄,但是没有初始化、
        hdc=GetDC(hwnd);
        TextOut(hdc,0,50,"抄袭",strlen("抄袭"));
        ReleaseDC(hwnd,hdc);
        break;
    case WM_PAINT:
        HDC hDC;
        PAINTSTRUCT ps;
        hDC=BeginPaint(hwnd,&ps);
        TextOut(hDC,0,0,"偷袭",strlen("偷袭"));
        EndPaint(hwnd,&ps);
        break;
    case WM_CLOSE:
        if(IDYES==MessageBox(hwnd,"是否真得结束?","radio983",MB_YESNO))
        {
            DestroyWindow(hwnd);
        }
        break;
    case WM_DESTROY :
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd,uMag,wParam,lParam);
    }
    return 0;
}
回复 支持 反对

使用道具 举报

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

本版积分规则

申请友链|小黑屋|最新主题|手机版|新微赢技术网 ( 苏ICP备08020429号 )  

GMT+8, 2024-11-18 21:41 , Processed in 0.077421 second(s), 9 queries , Gzip On, Memcache On.

Powered by xuexi

© 2001-2013 HaiAn.Com.Cn Inc. 寰耽

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