| 网站首页 | 业界新闻 | 群组 | 人才 | 技术文章 | 下载频道 | 博客 | 代码贴 | 编程论坛
绝地游戏外挂辅助教学千里之行 始于足下
共有 219 人关注过本帖
标题:C语言窗口问题
只看楼主 收藏
ssl002
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2017-6-13
结帖率:100%
  已结贴   问题点数:25  回复次数:10   
C语言窗口问题
程序代码:
#include<windows.h>
#include<stdio.h>
LRESULT CALLBACK WinSunProc
(
HWND hwnd,
UINT uMsg,
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(WHITE_BRUSH);
    wndcls.hCursor=LoadIcon(NULL,IDC_CROSS);
    wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
    wndcls.hInstance=hInstance;
    wndcls.lpszMenuName=NULL;
    wndcls.style=CS_HREDRAW|CS_VREDRAW;
    RegisterClass(&wndcls);
    HWND hwnd;
    hwnd=CreateWindow
        (
        "Visual C++ Game",
        "Visual C++ 游戏开发",
        WS_OVERLAPPEDWINDOW,
        200,
        200,
        600,
        400,
        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

                            )
{
    char tmsg[128]={0};
    int num1,num2,num3,num4,num5;
    num1=3+8;
    num2=10-7;
    num3=100*33;
    num4=155/5;
    num5=9%2;

    sprintf(tmsg,"3+8=%d 10-7=%d 100*33=%d 155/5=%d 9%%2=%d",num1,num2,num3,num4,num5);
    switch(uMsg)
    {
    case WM_PAINT:
        HDC hDC;
        PAINTSTRUCT ps;
        hDC=BeginPaint(hwnd,&ps);
        TextOut(hDC,150,0,tmsg,strlen(tmsg));
        EndPaint(hwnd,&ps);
        break;
    case WM_CLOSE:
        if(IDYES==MessageBox(hwnd,"是否真的结束?","游戏开发",MB_YESNO))
        {
            DestroyWindow(hwnd);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd,uMsg,wParam,lParam);
    }
    return 0;
}

cfree运行显示无法定位文件
VC++显示error LNK2001: unresolved external symbol _main
Debug/SuanShuYuFuZhi.exe : fatal error LNK1120: 1 unresolved externals
有解决办法吗?
2017-10-12 19:24
ssl002
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2017-6-13
  得分:0 
有人看吗?
2017-10-12 20:02
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:版主
威 望:366
帖 子:12471
专家分:49080
注 册:2012-10-18
  得分:0 
unresolved external symbol _main
既然有这个提示  表明你建立的是控制台程序 自然无法玩窗体程序

DO IT YOURSELF !
2017-10-12 20:28
LG隐
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:59
专家分:151
注 册:2016-4-20
  得分:0 
我在vs2013上面,改了链接器和系统里的东西可以生成解决方案了,但是无法调试。而且你那个winmain的w应该大写吧是不,,我也不知道就是好奇试了试
2017-10-12 22:55
LG隐
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:59
专家分:151
注 册:2016-4-20
  得分:0 
我建立的win32项目不是控制台
2017-10-12 22:56
吹水佬
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:117
帖 子:4834
专家分:19862
注 册:2014-5-20
  得分:0 
//最基本的窗口
#include <windows.h>

LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    switch(Message)
    {
        case WM_DESTROY:
        {
            PostQuitMessage(0);
            break;
        }
        default:
            return DefWindowProc(hwnd, Message, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG msg;
    memset(&wc,0,sizeof(wc));
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.lpfnWndProc = WndProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszClassName = "WindowClass";
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
        return 0;
    }
    hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Caption",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          640,
                          480,
                          NULL,NULL,hInstance,NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, "创建窗口失败!","错误!",MB_ICONEXCLAMATION|MB_OK);
        return 0;
    }
    while(GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}
2017-10-13 05:32
ssl002
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2017-6-13
  得分:0 
回复 3楼 wp231957
谢谢,不过感觉没什么关系,因为楼下的窗口打开了。
2017-10-13 13:47
ssl002
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2017-6-13
  得分:0 
回复 4楼 LG隐
谢谢,不过大写也不能运行。
2017-10-13 13:48
ssl002
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2017-6-13
  得分:0 
回复 6楼 吹水佬
谢谢,这是一个可以运行的窗口,但我不知道我的窗口为什么不能运行,哪儿错了?
2017-10-13 13:49
吹水佬
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:117
帖 子:4834
专家分:19862
注 册:2014-5-20
  得分:25 
以下是引用ssl002在2017-10-13 13:49:28的发言:

谢谢,这是一个可以运行的窗口,但我不知道我的窗口为什么不能运行,哪儿错了?

简单改了一下,对照看看。
有些地方用到 GDI API 的代码需Gdi32.lib、Gdi32.dll支持,如GetStockObject()、TextOut(),暂忽略。
#include<stdio.h>
#include<windows.h>

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

//int WINAPI winMain
int WINAPI WinMain
(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
{
    WNDCLASS wndcls;
    wndcls.cbClsExtra=0;
    wndcls.cbWndExtra=0;
    //wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    wndcls.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
    //wndcls.hCursor=LoadIcon(NULL,IDC_CROSS);
    wndcls.hCursor=LoadCursor(NULL,IDC_ARROW);
    //wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
    wndcls.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    wndcls.hInstance=hInstance;
    wndcls.lpszMenuName=NULL;
    //wndcls.style=CS_HREDRAW|CS_VREDRAW;
    wndcls.style=0;
    wndcls.lpszClassName="Visual C++ Game"; //与CreateWindow()的第1个参数一致
    wndcls.lpfnWndProc=WinSunProc; //窗口过程
    if(!RegisterClass(&wndcls))
    {
        MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
        return 0;
    }
    HWND hwnd;
    hwnd=CreateWindow
         (
             "Visual C++ Game",
             "Visual C++ 游戏开发",
             WS_OVERLAPPEDWINDOW,
             200,
             200,
             600,
             400,
             NULL,
             NULL,
             hInstance,
             NULL);
    if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
        return 0;
    }
    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

)
{
    char tmsg[128]= {0};
    int num1,num2,num3,num4,num5;
    num1=3+8;
    num2=10-7;
    num3=100*33;
    num4=155/5;
    num5=9%2;

    sprintf(tmsg,"3+8=%d 10-7=%d 100*33=%d 155/5=%d 9%%2=%d",num1,num2,num3,num4,num5);
    switch(uMsg)
    {
            case WM_PAINT:
                /*
                HDC hDC;
                PAINTSTRUCT ps;
                hDC=BeginPaint(hwnd,&ps);
                TextOut(hDC,150,0,tmsg,strlen(tmsg));
                EndPaint(hwnd,&ps);
                */
                break;
        case WM_CLOSE:
            if(IDYES==MessageBox(hwnd,"是否真的结束?","游戏开发",MB_YESNO))
            {
                DestroyWindow(hwnd);
            }
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            break;
            //return DefWindowProc(hwnd,uMsg,wParam,lParam);
    }
    return DefWindowProc(hwnd,uMsg,wParam,lParam);
    //return 0;
}

2017-10-13 15:49







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

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