| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 783 人关注过本帖
标题:窗口问题(回答了给100分)
只看楼主 加入收藏
XIAO荣
Rank: 2
等 级:论坛游民
帖 子:87
专家分:20
注 册:2009-2-26
结帖率:100%
收藏
已结贴  问题点数:100 回复次数:4 
窗口问题(回答了给100分)
程序我是照书编的。。。运行时有17个错误,请帮忙解决下。

#include<Windows.h>
long FAR PASCAL WndProc(HWND,WORD,WORD,LONG);
int PASCAL WinMain(HANDLE hInstance,HANDLE hPrevInstance,LPSTR lpszCmdParam,int nComShow)
{
    HWND hwnd;
    MSG msg;
    if(!hPrevInstance)
    {
        wc.style=NULL;
        wc.lpfnWndProc=WndProc;
        wc.cbClsExtra=0;
        wc.cbWndExtra=0;
        wc.hInstance=hInstance;
        wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
        wc.hCursor=LoadCursor(NULL,IDC_ARROW);
        wc.hbrBackgroud=GetStockObject(WHITE_BRUSH);
        wc.lpszMenuName=NULL;
        wc.lpszClassName="Class_W1";
        RegisterClass(&wc);
    }
    hwnd=GreateWindow(
        "Class_W1,
        "Hello,World-Windows style",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL
        );
    ShowWindow(hwnd,nComdShow);
    UpdateWindow(hwnd);
    while(GetMessage(&msg,NULL,NULL,NULL))
        DispatchMessage(&msg);
    return msg,wParam;
}
long FAR PASCAL WndProc(HWND hwnd,WORD message,WORD wParam,LONG lParam)
{
    switch(message)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return(DefWindowProc(hwnd,message,wParam,lParam));
        return NULL;
    }    
}
E:\C++程序\基础\窗口.cpp(4) : error C2731: 'WinMain' : function cannot be overloaded
        E:\C++程序\基础\窗口.cpp(3) : see declaration of 'WinMain'
E:\C++程序\基础\窗口.cpp(9) : error C2065: 'wc' : undeclared identifier
E:\C++程序\基础\窗口.cpp(9) : error C2228: left of '.style' must have class/struct/union type
E:\C++程序\基础\窗口.cpp(10) : error C2228: left of '.lpfnWndProc' must have class/struct/union type
E:\C++程序\基础\窗口.cpp(11) : error C2228: left of '.cbClsExtra' must have class/struct/union type
E:\C++程序\基础\窗口.cpp(12) : error C2228: left of '.cbWndExtra' must have class/struct/union type
E:\C++程序\基础\窗口.cpp(13) : error C2228: left of '.hInstance' must have class/struct/union type
E:\C++程序\基础\窗口.cpp(14) : error C2228: left of '.hIcon' must have class/struct/union type
E:\C++程序\基础\窗口.cpp(15) : error C2228: left of '.hCursor' must have class/struct/union type
E:\C++程序\基础\窗口.cpp(16) : error C2228: left of '.hbrBackgroud' must have class/struct/union type
E:\C++程序\基础\窗口.cpp(17) : error C2228: left of '.lpszMenuName' must have class/struct/union type
E:\C++程序\基础\窗口.cpp(18) : error C2228: left of '.lpszClassName' must have class/struct/union type
E:\C++程序\基础\窗口.cpp(21) : error C2065: 'GreateWindow' : undeclared identifier
E:\C++程序\基础\窗口.cpp(22) : error C2001: newline in constant
E:\C++程序\基础\窗口.cpp(33) : error C2440: '=' : cannot convert from 'int' to 'struct HWND__ *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\C++程序\基础\窗口.cpp(34) : error C2065: 'nComdShow' : undeclared identifier
E:\C++程序\基础\窗口.cpp(38) : error C2065: 'wParam' : undeclared identifier
Error executing cl.exe.

[ 本帖最后由 XIAO荣 于 2009-8-22 10:50 编辑 ]
搜索更多相关主题的帖子: 窗口 
2009-08-22 10:40
sherwin
Rank: 2
来 自:大连
等 级:论坛游民
帖 子:25
专家分:96
注 册:2009-7-5
收藏
得分:60 
#include<Windows.h>
long FAR PASCAL WndProc(HWND,WORD,WORD,LONG);
int APIENTRY WinMain(HANDLE hInstance,HANDLE hPrevInstance,LPSTR lpszCmdParam,int nComShow) //一般写nCmdShow
{
    WNDCLASSEX wc;          //定义一个窗口类的对象
    HWND hwnd;
    MSG msg;
    if(!hPrevInstance)
    {
        wc.style=NULL;
        wc.lpfnWndProc=WndProc;
        wc.cbClsExtra=0;
        wc.cbWndExtra=0;
        wc.hInstance=hInstance;
        wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
        wc.hCursor=LoadCursor(NULL,IDC_ARROW);
        wc.hbrBackgroud=GetStockObject(WHITE_BRUSH);
        wc.lpszMenuName=NULL;
        wc.lpszClassName="Class_W1";
        RegisterClass(&wc);
    }
    hwnd=CreateWindowEx(         //CreateWindowEx  最后的Ex是扩展的意思,因为他是Win16的CreateWindow函数的扩展,楼主把C写成G了
        "Class_W1",              //少个引号,楼主应该先好好检查一下啊
        "Hello,World-Windows style",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL
        );
    ShowWindow(hwnd,nCmdShow); //将nComdShow改为nCmdShow,应该与WinMain函数的参数一致
    UpdateWindow(hwnd);
    while(GetMessage(&msg,NULL,NULL,NULL))
    {  
        TranslateMessage(&msg);//转化键盘消息
        DispatchMessage(&msg);
    }
    return msg.wParam; //逗号改成".",因为wParan是MSG的一个成员
}
long FAR PASCAL WndProc(HWND hwnd,WORD message,WORD wParam,LONG lParam)
{
    switch(message)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return(DefWindowProc(hwnd,message,wParam,lParam));
        return NULL;              //多余
    }   
}

成长。。。
2009-08-22 12:37
sherwin
Rank: 2
来 自:大连
等 级:论坛游民
帖 子:25
专家分:96
注 册:2009-7-5
收藏
得分:0 
我没有运行,这台电脑没VC,也不知道是否找到了所有的问题,有什么问题再说。

成长。。。
2009-08-22 12:40
mfkblue
Rank: 5Rank: 5
等 级:职业侠客
帖 子:472
专家分:343
注 册:2008-12-21
收藏
得分:40 
错的太多,自己对照着改下,窗口是出来了
#include<Windows.h>
long FAR PASCAL WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
                   LPSTR lpszCmdParam,int nComdShow)
{
    HWND hwnd;
    MSG msg;
    WNDCLASS wc;
    if(!hPrevInstance)
    {
        wc.style=NULL;
        wc.lpfnWndProc=WndProc;
        wc.cbClsExtra=0;
        wc.cbWndExtra=0;
        wc.hInstance=hInstance;
        wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
        wc.hCursor=LoadCursor(NULL,IDC_ARROW);
        wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
        wc.lpszMenuName=NULL;
        wc.lpszClassName="Class_W1";
        RegisterClass(&wc);
    }
    hwnd=CreateWindow(
        "Class_W1",
        "Hello,World-Windows style",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL
        );
    ShowWindow(hwnd,nComdShow);
    UpdateWindow(hwnd);
    while(GetMessage(&msg,NULL,NULL,NULL))
        DispatchMessage(&msg);
    return 0;

}
long FAR PASCAL WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
   
   
    switch(message)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return(DefWindowProc(hwnd,message,wParam,lParam));
        
    }   
}
2009-08-22 16:21
快速回复:窗口问题(回答了给100分)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.045589 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved