| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 516 人关注过本帖
标题:入门的窗口问题
只看楼主 加入收藏
guer168
Rank: 2
等 级:论坛游民
帖 子:46
专家分:37
注 册:2010-3-19
结帖率:75%
收藏
已结贴  问题点数:20 回复次数:2 
入门的窗口问题
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunProc(
     HWND hwnd,
     UINT uMsg,
     WPARAM wParam,
     LPARAM lParam
);
int WINAPI WinMain(
  HINSTANCE hInstance,      // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,          // command line
  int nCmdShow              // show state
)
{
    WNDCLASS wndcls;
    wndcls.cbClsExtra=0;
    wndcls.cbWndExtra=0;
    wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
    wndcls.hCursor=LoadCursor(NULL,IDI_ERROR);
    wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
    wndcls.hInstance=hInstance;
    wndcls.lpfnWndProc=WinSunProc;
    wndcls.lpszClassName="Weixin2003";
    wndcls.lpszMenuName=NULL;
    wndcls.style=CS_HREDRAW | CS_VREDRAW;
    RegisterClass(&wndcls);

    HWND hwnd;
    hwnd=CreateWindow("Weixin2003","214646321454",WS_OVERLAPPEDWINDOW,0,0,200,200,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 uMsg,
     WPARAM wParam,
     LPARAM lParam
)
{
    switch(uMsg)
    {
    case WM_CHAR:
        char szChar[20];
        sprintf(szChar,"char is %d",wParam);
        MessageBox(hwnd,szChar,"weixin1",0);
        break;
    case WM_LBUTTONDOWN:
        MessageBox(hwnd,"mouse clicked","weixin2",0);
        HDC hdc;
        hdc=GetDC(hwnd);
        TextOut(hwnd,0,50,"465446",strlen("465446"));
        ReleaseDC(hwnd,hdc);
        break;
    case WM_PAINT:
        HDC hDC;
        PAINTSTRUCT ps;
        hDC=BeginPaint(hwnd,&ps);
        TextOut(hDC,0,0,"787997",strlen("787997"));
        EndPaint(hwnd,&ps);
        break;
    case WM_CLOSE:
        if(IDYES==MessageBox(hwnd,"是真要退出?","Weixin",MB_YESNO))
        {
            DestroyWindow(hwnd);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd,uMsg,wParam,lParam);
         
    }
    return 0;
}

}

--------------------Configuration: WinMain - Win32 Debug--------------------
Compiling...
WinMain.cpp
D:\VC\WinMain\WinMain.cpp(49) : error C2601: 'WinSunProc' : local function definitions are illegal
D:\VC\WinMain\WinMain.cpp(72) : error C2018: unknown character '0xa3'
D:\VC\WinMain\WinMain.cpp(72) : error C2018: unknown character '0xac'
执行 cl.exe 时出错.

WinMain.exe - 1 error(s), 0 warning(s)
这里为什么说WinSunProc是非法定义呢?像这样的问题又要如何去找错误在哪里并改过来呢!我希望高手能告诉我方法。
搜索更多相关主题的帖子: 入门 窗口 
2010-05-27 13:06
ciweitou163
Rank: 7Rank: 7Rank: 7
来 自:河北 石家庄
等 级:黑侠
威 望:1
帖 子:144
专家分:528
注 册:2008-10-4
收藏
得分:10 
程序代码:
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunProc(
     HWND hwnd, 
     UINT uMsg, 
     WPARAM wParam, 
     LPARAM lParam
);
int WINAPI WinMain(
  HINSTANCE hInstance,      // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,          // command line
  int nCmdShow              // show state
)
{
    WNDCLASS wndcls;
    wndcls.cbClsExtra=0;
    wndcls.cbWndExtra=0;
    wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
    wndcls.hCursor=LoadCursor(NULL,IDI_ERROR);
    wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
    wndcls.hInstance=hInstance;
    wndcls.lpfnWndProc=WinSunProc;
    wndcls.lpszClassName="Weixin2003";
    wndcls.lpszMenuName=NULL;
    wndcls.style=CS_HREDRAW | CS_VREDRAW;
    RegisterClass(&wndcls);

    HWND hwnd;
    hwnd=CreateWindow("Weixin2003","214646321454",WS_OVERLAPPEDWINDOW,0,0,200,200,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 uMsg, 
     WPARAM wParam, 
     LPARAM lParam
)
{
    switch(uMsg)
    {
    case WM_CHAR:
        char szChar[20];
        sprintf(szChar,"char is %d",wParam);
        MessageBox(hwnd,szChar,"weixin1",0);
        break;
    case WM_LBUTTONDOWN:
        MessageBox(hwnd,"mouse clicked","weixin2",0);
        HDC hdc;
        hdc=GetDC(hwnd);
        TextOut(hwnd,0,50,"465446",strlen("465446"));
        ReleaseDC(hwnd,hdc);
        break;
    case WM_PAINT:
        HDC hDC;
        PAINTSTRUCT ps;
        hDC=BeginPaint(hwnd,&ps);
        TextOut(hDC,0,0,"787997",strlen("787997"));
        EndPaint(hwnd,&ps);
        break;
    case WM_CLOSE:
        if(IDYES==MessageBox(hwnd,"是真要退出?""Weixin",MB_YESNO))
        {
            DestroyWindow(hwnd);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd,uMsg,wParam,lParam);
         
    }
    return 0;
}

函数不能嵌套定义。可以调用。


  • 满眼生机转化钧;天工人巧日争新。
2010-05-27 19:31
南国利剑
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:29
帖 子:1165
专家分:3536
注 册:2010-4-12
收藏
得分:10 
函数不能嵌套定义!
这个值得注意!

南国利剑
2010-05-28 00:22
快速回复:入门的窗口问题
数据加载中...
 
   



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

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