
C语言如何从代码变成软件,如何变成带有按钮的对话框软件?
如题,我想做一个如图的游戏软件,但是只会写代码,不会做成如图的窗口界面,请问下各位大侠应该怎样把写好的程序做成如图哪样的窗口界面呢?是不是要用到哪些函数呢?如果可能的话,...
如题,我想做一个如图的游戏软件,但是只会写代码,不会做成如图的窗口界面,请问下各位大侠应该怎样把写好的程序做成如图哪样的窗口界面呢?是不是要用到哪些函数呢?如果可能的话,请把代码也写出来,我可以附加分的!!最要紧的是要告诉我如何做成如图的界面~~~谢谢啦~~~
展开
2个回答
展开全部
你是c语言的初学者吗?
你意思是你编的dos那种界面,想换成windows界面,
那你就要在vc6里面新建MFC appwisard
下面给你一个用c++语言生成一个简单的点击弹出对话框示例代码:
用c语言写界面实在太麻烦了,太难了。
如果你没有学过c++,那我给你个最实际的办法,你在vc里面把你的代码生成dll,
然后在vb里面调用。
vb很容易做windows界面这是众所周知的。
#include <windows.h>
#include <string.h>
#include <iostream>
LRESULT CALLBACK
MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
/* The window handle for the "Click Me" button. */
static HWND hwndButton = 0;
static int cx, cy;/* Height and width of our button. */
HDC hdc;/* A device context used for drawing */
PAINTSTRUCT ps;/* Also used during window drawing */
RECT rc;/* A rectangle used during drawing */
switch (nMsg)
{
case WM_CREATE:
{
TEXTMETRIC tm;
hdc = GetDC (hwnd);
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
GetTextMetrics (hdc, &tm);
cx = tm.tmAveCharWidth * 30;
cy = (tm.tmHeight + tm.tmExternalLeading) * 2;
ReleaseDC (hwnd, hdc);
/* Now create the button */
hwndButton = CreateWindow (
"button",/* Builtin button class */
"Click Here",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0, cx, cy,
hwnd,/* Parent is this window. */
(HMENU) 1,/* Control ID: 1 */
((LPCREATESTRUCT) lParam)->hInstance,
NULL
);
return 0;
break;
}
case WM_DESTROY:
PostQuitMessage (0);
return 0;
break;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps);
GetClientRect (hwnd, &rc);
rc.bottom = rc.bottom / 2;
DrawText (hdc, "Hello, World!", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint (hwnd, &ps);
return 0;
break;
case WM_SIZE:
if (hwndButton &&
(wParam == SIZEFULLSCREEN ||
wParam == SIZENORMAL)
)
{
rc.left = (LOWORD(lParam) - cx) / 2;
rc.top = HIWORD(lParam) * 3 / 4 - cy / 2;
MoveWindow (
hwndButton,
rc.left, rc.top, cx, cy, TRUE);
}
break;
case WM_COMMAND:
if (LOWORD(wParam) == 1 &&
HIWORD(wParam) == BN_CLICKED &&
(HWND) lParam == hwndButton)
{
DestroyWindow (hwnd);
}
return 0;
break;
}
return DefWindowProc (hwnd, nMsg, wParam, lParam);
}
int STDCALL;
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
HWND hwndMain;/* Handle for the main window. */
MSG msg;/* A Win32 message structure. */
WNDCLASSEX wndclass;/* A window class structure. */
char*szMainWndClass = "WinTestWin";
memset (&wndclass, 0, sizeof(WNDCLASSEX));
wndclass.lpszClassName = szMainWndClass;
wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = MainWndProc;
wndclass.hInstance = hInst;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
RegisterClassEx (&wndclass);
hwndMain = CreateWindow (
szMainWndClass,/* Class name */
"Hello",/* Caption */
WS_OVERLAPPEDWINDOW,/* Style */
CW_USEDEFAULT,/* Initial x (use default) */
CW_USEDEFAULT,/* Initial y (use default) */
CW_USEDEFAULT,/* Initial x size (use default) */
CW_USEDEFAULT,/* Initial y size (use default) */
NULL,/* No parent window */
NULL,/* No menu */
hInst,/* This program instance */
NULL/* Creation parameters */
);
ShowWindow (hwndMain, nShow);
UpdateWindow (hwndMain);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
你意思是你编的dos那种界面,想换成windows界面,
那你就要在vc6里面新建MFC appwisard
下面给你一个用c++语言生成一个简单的点击弹出对话框示例代码:
用c语言写界面实在太麻烦了,太难了。
如果你没有学过c++,那我给你个最实际的办法,你在vc里面把你的代码生成dll,
然后在vb里面调用。
vb很容易做windows界面这是众所周知的。
#include <windows.h>
#include <string.h>
#include <iostream>
LRESULT CALLBACK
MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
/* The window handle for the "Click Me" button. */
static HWND hwndButton = 0;
static int cx, cy;/* Height and width of our button. */
HDC hdc;/* A device context used for drawing */
PAINTSTRUCT ps;/* Also used during window drawing */
RECT rc;/* A rectangle used during drawing */
switch (nMsg)
{
case WM_CREATE:
{
TEXTMETRIC tm;
hdc = GetDC (hwnd);
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
GetTextMetrics (hdc, &tm);
cx = tm.tmAveCharWidth * 30;
cy = (tm.tmHeight + tm.tmExternalLeading) * 2;
ReleaseDC (hwnd, hdc);
/* Now create the button */
hwndButton = CreateWindow (
"button",/* Builtin button class */
"Click Here",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0, cx, cy,
hwnd,/* Parent is this window. */
(HMENU) 1,/* Control ID: 1 */
((LPCREATESTRUCT) lParam)->hInstance,
NULL
);
return 0;
break;
}
case WM_DESTROY:
PostQuitMessage (0);
return 0;
break;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps);
GetClientRect (hwnd, &rc);
rc.bottom = rc.bottom / 2;
DrawText (hdc, "Hello, World!", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint (hwnd, &ps);
return 0;
break;
case WM_SIZE:
if (hwndButton &&
(wParam == SIZEFULLSCREEN ||
wParam == SIZENORMAL)
)
{
rc.left = (LOWORD(lParam) - cx) / 2;
rc.top = HIWORD(lParam) * 3 / 4 - cy / 2;
MoveWindow (
hwndButton,
rc.left, rc.top, cx, cy, TRUE);
}
break;
case WM_COMMAND:
if (LOWORD(wParam) == 1 &&
HIWORD(wParam) == BN_CLICKED &&
(HWND) lParam == hwndButton)
{
DestroyWindow (hwnd);
}
return 0;
break;
}
return DefWindowProc (hwnd, nMsg, wParam, lParam);
}
int STDCALL;
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
HWND hwndMain;/* Handle for the main window. */
MSG msg;/* A Win32 message structure. */
WNDCLASSEX wndclass;/* A window class structure. */
char*szMainWndClass = "WinTestWin";
memset (&wndclass, 0, sizeof(WNDCLASSEX));
wndclass.lpszClassName = szMainWndClass;
wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = MainWndProc;
wndclass.hInstance = hInst;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
RegisterClassEx (&wndclass);
hwndMain = CreateWindow (
szMainWndClass,/* Class name */
"Hello",/* Caption */
WS_OVERLAPPEDWINDOW,/* Style */
CW_USEDEFAULT,/* Initial x (use default) */
CW_USEDEFAULT,/* Initial y (use default) */
CW_USEDEFAULT,/* Initial x size (use default) */
CW_USEDEFAULT,/* Initial y size (use default) */
NULL,/* No parent window */
NULL,/* No menu */
hInst,/* This program instance */
NULL/* Creation parameters */
);
ShowWindow (hwndMain, nShow);
UpdateWindow (hwndMain);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
展开全部
如果你要编写Windows上面的程序,那么可以学习WindowsAPI。什么叫API?就是应用程序接口。
他是一个函数库,已经定义好了的函数,你要做的只是用其他语言调用这些函数,比如C、C++。为什么可以用C编写Windows程序,也可以用C++?原因就在于此。
说直观点,在WindowsAPI中有一系列的函数,用于文件管理、内存管理、进程、消息机制等等。
比如MessageBox就是一个输出消息的函数。你编译以下代码,最后生成exe的可执行文件,双击看看,就是一个简单的消息窗口。
#include <windows.h>
#pragma comment (lib, "User32.lib")
int WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
// 调用API函数 MessageBox
MessageBox(NULL,
TEXT("开始学习Windows编程"),
TEXT("消息对话框"),
MB_OK);
return 0;
}
关于API的书籍很多,你搜Windows编程或者WindowsAPI就行了,我这就不打广告了。
至于MFC,是以C++类的形式封装了Windows的API。可以简化工作。 不过还是建议从API学起,因为它才是基础,才能让你了解这个功能到底是怎么实现的。
他是一个函数库,已经定义好了的函数,你要做的只是用其他语言调用这些函数,比如C、C++。为什么可以用C编写Windows程序,也可以用C++?原因就在于此。
说直观点,在WindowsAPI中有一系列的函数,用于文件管理、内存管理、进程、消息机制等等。
比如MessageBox就是一个输出消息的函数。你编译以下代码,最后生成exe的可执行文件,双击看看,就是一个简单的消息窗口。
#include <windows.h>
#pragma comment (lib, "User32.lib")
int WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
// 调用API函数 MessageBox
MessageBox(NULL,
TEXT("开始学习Windows编程"),
TEXT("消息对话框"),
MB_OK);
return 0;
}
关于API的书籍很多,你搜Windows编程或者WindowsAPI就行了,我这就不打广告了。
至于MFC,是以C++类的形式封装了Windows的API。可以简化工作。 不过还是建议从API学起,因为它才是基础,才能让你了解这个功能到底是怎么实现的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询