如何用C语言写一个button按钮
3个回答
推荐于2018-03-05
展开全部
#include <windows.h>
typedef _Bool bool;
#define false ((bool)0)
#define true ((bool)1)
HWND ChuangJianChuangKou(char *a,bool(*b)(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam),bool c,int x,int y)
{
HWND hwnd;
static TCHAR szAppName[] = TEXT("Mz Game") ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC ;
wndclass.lpszClassName = szAppName ;
wndclass.lpszMenuName = NULL ;
wndclass.hbrBackground =(HBRUSH)GetStockObject(6);
wndclass.lpfnWndProc = (WNDPROC)b;
wndclass.cbWndExtra = 0 ;
wndclass.cbClsExtra = 0 ;
wndclass.hInstance = 0;
wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION ) ;
wndclass.hCursor = LoadCursor( NULL, IDC_ARROW ) ;
if(!RegisterClass(&wndclass))
{
return (HWND)0;
}
hwnd=CreateWindow(
szAppName,
a,
c?WS_OVERLAPPEDWINDOW:WS_POPUP,
(GetSystemMetrics (SM_CXSCREEN)-x)/2,
(GetSystemMetrics (SM_CYSCREEN)-y)/2,
x,
y,
0,
0,
0,
0
);
ShowWindow(hwnd,1);
UpdateWindow(hwnd);
return hwnd;
}
bool GengXinChuangKou()
{
static MSG msg;
if(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
return true;
}
else
{
return false;
}
}
bool WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
return MoRenChuLi(hwnd,message,wParam,lParam,0);
}
WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
ChuangJianChuangKou("sss",WndProc,true,KongJianDaXiao(0).x/2,KongJianDaXiao(0).y/2);
while(GengXinChuangKou());
}
typedef _Bool bool;
#define false ((bool)0)
#define true ((bool)1)
HWND ChuangJianChuangKou(char *a,bool(*b)(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam),bool c,int x,int y)
{
HWND hwnd;
static TCHAR szAppName[] = TEXT("Mz Game") ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC ;
wndclass.lpszClassName = szAppName ;
wndclass.lpszMenuName = NULL ;
wndclass.hbrBackground =(HBRUSH)GetStockObject(6);
wndclass.lpfnWndProc = (WNDPROC)b;
wndclass.cbWndExtra = 0 ;
wndclass.cbClsExtra = 0 ;
wndclass.hInstance = 0;
wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION ) ;
wndclass.hCursor = LoadCursor( NULL, IDC_ARROW ) ;
if(!RegisterClass(&wndclass))
{
return (HWND)0;
}
hwnd=CreateWindow(
szAppName,
a,
c?WS_OVERLAPPEDWINDOW:WS_POPUP,
(GetSystemMetrics (SM_CXSCREEN)-x)/2,
(GetSystemMetrics (SM_CYSCREEN)-y)/2,
x,
y,
0,
0,
0,
0
);
ShowWindow(hwnd,1);
UpdateWindow(hwnd);
return hwnd;
}
bool GengXinChuangKou()
{
static MSG msg;
if(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
return true;
}
else
{
return false;
}
}
bool WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
return MoRenChuLi(hwnd,message,wParam,lParam,0);
}
WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
ChuangJianChuangKou("sss",WndProc,true,KongJianDaXiao(0).x/2,KongJianDaXiao(0).y/2);
while(GengXinChuangKou());
}
展开全部
自己用画矩形函数画两个颜色不一样的矩形。实时检测鼠标移动,看是否到按钮区域,如果到按钮区域了,就做相关动作就行
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
太简单了,你自己设计一个窗口,然后弹出showdialog就是没有button的提示对话框了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询