| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 831 人关注过本帖
标题:用API创建一个简单的WINDOWS窗口出错
只看楼主 加入收藏
初中毕业
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-7-2
收藏
 问题点数:0 回复次数:2 
用API创建一个简单的WINDOWS窗口出错
#include "stdio.h"
#include "windows.h"



LRESULT CALLBACK wndproc(
                         HWND hwnd,
                         UINT uMsg,
                         WPARAM wParam,
                         LPARAM lParam
                         );
HINSTANCE hInstance;

class win
{
public:
    BOOL W_class();
    BOOL create();
};


BOOL win::W_class()
{
WNDCLASS wdnclass;//设计窗口
    wdnclass.style=CS_HREDRAW|CS_VREDRAW;;//窗口
    wdnclass.lpfnWndProc=wndproc;//窗口指针很重要
    wdnclass.cbClsExtra=0;//通常为0
    wdnclass.cbWndExtra=0;//通常为0
    wdnclass.hInstance=hInstance;//句柄
    wdnclass.hIcon=LoadIcon(NULL,IDI_ERROR);//图标句柄
    wdnclass.hCursor=LoadCursor(NULL,IDC_CROSS);//光标句柄
    wdnclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);//背色句柄
    wdnclass.lpszMenuName=NULL;
    wdnclass.lpszClassName="zhuzi";//类的名字

      return (RegisterClass(&wdnclass));//注册窗口
}

BOOL win::create()
{    
    HWND hwnd;
    hwnd=CreateWindow("zhuzi","猪",WS_OVERLAPPEDWINDOW,
        200,200,600,400,NULL,NULL,
     hInstance,NULL);
    //显示窗口
    ShowWindow(hwnd,SW_SHOWNORMAL);
    UpdateWindow(hwnd);
    return hwnd;
}


 



int WINAPI WinMain(
  HINSTANCE hInstance,      // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,          // command line
  int nCmdShow              // show state
)
{
    win window
    if(!window.W_class())
        return 0;
    if(!window.create())
        return 0;
    




    //消息循环
    MSG msg;
    while(GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);//接收消息
        DispatchMessage(&msg);//将接收的消息处理
    }
    return 0;
}

//过程函数
LRESULT CALLBACK wndproc(
                         HWND hwnd,
                         UINT uMsg,
                         WPARAM wParam,
                         LPARAM lParam
                         )
{
    HDC hdc;
    PAINTSTRUCT ps;
    switch(uMsg)
    {
    case WM_PAINT:
        hdc=BeginPaint(hwnd,&ps);
        TextOut(hdc,0,0,"猪",strlen("猪"));
        EndPaint(hwnd,&ps);
        break;
    case WM_CHAR:
        char szchar[20];
        sprintf(szchar,"ch%d",wParam);
    MessageBox(hwnd,szchar,"zhuzi",MB_OK);
    break;
    case WM_LBUTTONDOWN:
        if(IDYES==MessageBox(hwnd,"猪编程","zhuzi",MB_YESNO))
        {
            HDC hDC;
        hDC=GetDC(hwnd);
        TextOut(hDC,150,150,"猪万岁",strlen("猪万岁"));
        ReleaseDC(hwnd,hDC);
        }
        break;
    case WM_CLOSE:
        if(IDYES==MessageBox(hwnd,"真的退出","zhuzi",MB_YESNO))
        {
            DestroyWindow(hwnd);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd,uMsg,wParam,lParam);
        break;
    }
    return 0;
}
出现:::
 error C2440: 'return' : cannot convert from 'struct HWND__ *' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\diyige.cpp(69) : error C2143: syntax error : missing ';' before 'if'
执行 cl.exe 时出错.
请高手改改到底那里错了~~~谢谢~~我是菜鸟
搜索更多相关主题的帖子: API WINDOWS 窗口 wdnclass windows 
2008-07-29 22:22
Neil_wyh
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-4-20
收藏
得分:0 
我看的是用C语言写的
挺好的
写过好几遍,都没错
2008-07-29 23:05
DGBoy
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-8-4
收藏
得分:0 
呵呵!
BOOL win::create()
{   
    HWND hwnd;
    hwnd=CreateWindow("zhuzi","猪",WS_OVERLAPPEDWINDOW,
        200,200,600,400,NULL,NULL,
     hInstance,NULL);
    //显示窗口
    ShowWindow(hwnd,SW_SHOWNORMAL);
    UpdateWindow(hwnd);
    return hwnd;
}

改成;return ture/false或者,把BOOL,改成HWND
2008-08-04 10:57
快速回复:用API创建一个简单的WINDOWS窗口出错
数据加载中...
 
   



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

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