请问如何用c语言做一个图形界面呢比如一个迷宫游戏的界面

请问如何用c语言做一个图形界面呢比如一个迷宫游戏的界面,第1张

图形界面接口因系统(windows /Linux)而不一样。

在windows下因为系统是用C开发的,标准API接口就是C接口,称好windows API

这就是常说的API编程

int WINAPI WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nCmdShow)

{

WNDCLASSEX wcex;

wcexcbSize = sizeof(WNDCLASSEX);

wcexstyle = CS_HREDRAW | CS_VREDRAW;

wcexlpfnWndProc = WndProc;

wcexcbClsExtra = 0;

wcexcbWndExtra = 0;

wcexhInstance = hInstance;

wcexhIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));

wcexhCursor = LoadCursor(NULL, IDC_ARROW);

wcexhbrBackground = (HBRUSH)(COLOR_WINDOW+1);

wcexlpszMenuName = NULL;

wcexlpszClassName = szWindowClass;

wcexhIconSm = LoadIcon(wcexhInstance, MAKEINTRESOURCE(IDI_APPLICATION));

if (!RegisterClassEx(&wcex))

{

MessageBox(NULL,

_T("Call to RegisterClassEx failed!"),

_T("Win32 Guided Tour"),

NULL);

return 1;

}

hInst = hInstance; // Store instance handle in our global variable

// The parameters to CreateWindow explained:

// szWindowClass: the name of the application

// szTitle: the text that appears in the title bar

// WS_OVERLAPPEDWINDOW: the type of window to create

// CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y)

// 500, 100: initial size (width, length)

// NULL: the parent of this window

// NULL: this application dows not have a menu bar

// hInstance: the first parameter from WinMain

// NULL: not used in this application

HWND hWnd = CreateWindow(

szWindowClass,

szTitle,

WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT, CW_USEDEFAULT,

500, 100,

NULL,

NULL,

hInstance,

NULL

);

if (!hWnd)

{

MessageBox(NULL,

_T("Call to CreateWindow failed!"),

_T("Win32 Guided Tour"),

NULL);

return 1;

}

// The parameters to ShowWindow explained:

// hWnd: the value returned from CreateWindow

// nCmdShow: the fourth parameter from WinMain

ShowWindow(hWnd,

nCmdShow);

UpdateWindow(hWnd);

// Main message loop:

MSG msg;

while (GetMessage(&msg, NULL, 0, 0))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

return (int) msgwParam;

}

>

主要是你的输出有点问题,还有这种情况学习下switch的用法。我帮你重写了下轮廓,具体的实现你来写吧。

#pragma warning(disable:4996)

#include <stdioh>

#include <stdlibh>

#include <windowsh>

#include<conioh>

char map[10][10] = { "#########",

"# ##",

"# # #",

"## ## #",

"#0# ## #",

"# # # #",

"# # # #",

"# # ###",

"#########" };

void print()

{

int i, j;

for (i = 0; i < 10; i++)

{

for (j = 0; j < 10; j++)

{

printf("%c", map[i][j]);

}

printf("\n");

}

}

int main()

{

char s;

int i, j, n, m, x = 4, y = 1, w, p = 5, q = 5;

system("cls");

print();

while (1)

{

s=getch();

switch (s)

{

case 'w':在这里加上你的处理代码就可以 break;

case 'a':break;

case 's':break;

case 'd':break;

default:printf("wrong");

}

}

return 0;

}

以上就是关于请问如何用c语言做一个图形界面呢比如一个迷宫游戏的界面全部的内容,包括:请问如何用c语言做一个图形界面呢比如一个迷宫游戏的界面、c语言的迷宫问题、请问这个c语言迷宫程序哪里有问题按wasd也没用等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9970026.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存