Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
DirectX游戏的窗口GUI似乎有故障_C_Windows_Directx - Fatal编程技术网

DirectX游戏的窗口GUI似乎有故障

DirectX游戏的窗口GUI似乎有故障,c,windows,directx,C,Windows,Directx,我想在Windows10中使用DirectX开发一个游戏。我用代码块写代码。以下代码将抛出如下错误: undefined reference to `GetStockObject@4' 这个Windowsfunction有什么问题?我不必单独初始化或编写这个函数,不是吗?注释掉错误代码将编译代码,但没有gui。。。 以下是代码: #include <windows.h> #include"Frame.h" //global definitions BOOL done; int Sp

我想在Windows10中使用DirectX开发一个游戏。我用代码块写代码。以下代码将抛出如下错误:

undefined reference to `GetStockObject@4'
这个Windowsfunction有什么问题?我不必单独初始化或编写这个函数,不是吗?注释掉错误代码将编译代码,但没有gui。。。 以下是代码:

#include <windows.h>
#include"Frame.h"
//global definitions
BOOL done;
int Spiel_Zustand;
HWND hwnd;

//Function:CallBack
LRESULT CALLBACK WindowProc (HWND hwnd,UINT message, WPARAM wparam,LPARAM lparam)
{
    switch(message)
    {
    case WM_DESTROY :
    {
        done=TRUE;
        PostQuitMessage(0);
        return 0;
    }
    break;
    case WM_KEYDOWN:
        switch(wparam)
        {
        case VK_ESCAPE:
        {
            PostMessage(hwnd,WM_CLOSE,0,0);
            return 0;
        }
        break;
        }
        break;
    default:
        break;

    }//End of switch
    return DefWindowProc(hwnd,message,wparam,lparam);
}//End of CallBack

//Function:Start
int WINAPI WinMain(HINSTANCE hinst,HINSTANCE hprevinst,LPSTR lpcmdline,int ncmdshow)
{
    WNDCLASSEX winclass;
    MSG message;
    const char szclassname[]="Klassenname";
    DWORD loop_start_time;
    winclass.cbSize=sizeof(WNDCLASSEX);
    winclass.style=CS_HREDRAW|CS_VREDRAW;
    winclass.lpfnWndProc=WindowProc;
    winclass.cbClsExtra=0;
    winclass.cbWndExtra=0;
    winclass.hInstance=hinst;
    winclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    winclass.hCursor=LoadCursor(NULL,IDC_ARROW);
    winclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);//this will throw out error
    winclass.lpszClassName=szclassname;
    winclass.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
    if(!RegisterClassEx(&winclass))
        return 0;
    //Create handle of windows ans save it globally
    if(!(hwnd=CreateWindowEx(NULL,szclassname,"3D Gameprograming - Title",WS_POPUPWINDOW|WS_VISIBLE,0,0,400,300,NULL,NULL,hinst,NULL)))
        return 0;
    done=FALSE;
    Spiel_Zustand=SPIEL_AUSWAHL;
    //Phase 1.1:
    Spiel_Initialisieren();
    //Phase 1.2:: Main Looping
    while(!done)
    {
        //Any message to handle?
        while(GetMessage(&message,NULL,0,0))
        {
            TranslateMessage(&message);
            DispatchMessage(&message);
        }
        //Start time of Main Loop
        loop_start_time=GetTickCount;
        switch(Spiel_Zustand)
        {
        case SPIEL_AUSWAHL:
        {
            //[....]
            Spiel_Zustand=SPIEL_START;
        }
        break;
        case SPIEL_START:
        {
            //[...]
            Spiel_Zustand=SPIEL_LAEUFT;
        }
        break;
        case SPIEL_LAEUFT:
        {
            //waiting for User input
            //Manage User input
            //Artificial Intelligence and game logic
            //Rendering Frame
        } break;
        case SPIEL_NEUSTART:
        {
            //[...]
            Spiel_Zustand=SPIEL_START;
        }
        break;
        default:
            break;
        }//End of switch
        //Restricting Frame rate
        while((GetTickCount()-loop_start_time)<40);
    }//End of Main Looping
    //Phase 1.3
    Spiel_Beenden();
    return message.wParam;
}//End of Start


//Phase 2.1
int Spiel_Initialisieren(void)
{
//ToDO:initializations etc..
    return 1;
}
//Phase 2.2
int Spiel_Beenden(void)
{
    //ToDO:Free Memory etc..
    return 1;
}
#包括
#包括“Frame.h”
//全球定义
布尔多;
国际斯皮尔祖斯坦酒店;
HWND-HWND;
//函数:回调
LRESULT回调WindowProc(HWND-HWND,UINT消息,WPARAM-WPARAM,LPARAM-LPARAM)
{
开关(信息)
{
案例WM_销毁:
{
完成=正确;
PostQuitMessage(0);
返回0;
}
打破
案例WM_键控:
交换机(wparam)
{
案件VK_逃逸:
{
PostMessage(hwnd,WM_-CLOSE,0,0);
返回0;
}
打破
}
打破
违约:
打破
}//开关末端
返回DefWindowProc(hwnd、message、wparam、lparam);
}//回调结束
//功能:启动
int-WINAPI WinMain(HINSTANCE-hinst、HINSTANCE-hprevinst、LPSTR-lpcmdline、int-ncmdshow)
{
WNDCLASSEX绞车;
消息;
const char szclassname[]=“Klassename”;
DWORD循环开始时间;
winclass.cbSize=sizeof(WNDCLASSEX);
winclass.style=CS|HREDRAW | CS|u VREDRAW;
winclass.lpfnWndProc=WindowProc;
winclass.cbClsExtra=0;
winclass.cbWndExtra=0;
winclass.hInstance=hinst;
winclass.hIcon=LoadIcon(空,IDI_应用程序);
winclass.hCursor=LoadCursor(空,IDC_箭头);
winclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);//这将抛出错误
winclass.lpszClassName=szclassname;
winclass.hIconSm=LoadIcon(空,IDI_应用程序);
if(!RegisterClass(&winclass))
返回0;
//创建windows ans的句柄并全局保存
如果(!(hwnd=CreateWindowEx(NULL,szclassname,“3D游戏编程-标题”,WS_POPUPWINDOW | WS_VISIBLE,0,040300,NULL,NULL,hinst,NULL)))
返回0;
完成=错误;
斯皮尔·祖斯坦德=斯皮尔·奥斯瓦尔;
//第1.1阶段:
Spiel_initialiseren();
//阶段1.2:主循环
而(!完成)
{
//有消息要处理吗?
while(GetMessage(&message,NULL,0,0))
{
翻译消息(和消息);
DispatchMessage(&message);
}
//主回路启动时间
循环开始时间=GetTickCount;
开关(Spiel_Zustand)
{
斯皮尔·奥斯瓦尔案:
{
//[....]
Spiel_Zustand=Spiel_START;
}
打破
案件开始:
{
//[...]
斯皮尔·祖斯坦德=斯皮尔·劳夫特;
}
打破
斯皮尔·劳夫特案:
{
//等待用户输入
//管理用户输入
//人工智能与博弈逻辑
//渲染帧
}中断;
案例SPIEL_Neu Start:
{
//[...]
Spiel_Zustand=Spiel_START;
}
打破
违约:
打破
}//开关末端
//限制帧速率

而((GetTickCount()-loop\u start\u time)在编译
-lgdi32


GetStockObject
来自gdi32.dll。您正在将其导入库与程序链接,对吗?如果要在(GetMessage()){}
循环时执行下面的代码,请阅读GetMessage和PeekMessage之间的区别。