C语言中设置按钮的方法
在c语言中怎样设置一个有具体作用的按钮。我想设置一个具有“开始执行”作用的按钮用ShellExecute函数在Windows里面调用么?...
在c语言中怎样设置一个有具体作用的按钮。我想设置一个具有“开始执行”作用的按钮
用ShellExecute函数在Windows里面调用么? 展开
用ShellExecute函数在Windows里面调用么? 展开
展开全部
Windows 窗体程序是基于消息机制的,所有控件,它的本质都是一个窗体,都是使用 CreateWindows 函数来创建,不过类名,则需要指定为系统预先注册的控件类,比如,你要创建一个按钮控件,就要这样子 CreateWindows( "BUTTON", "按钮标题" ),CreateWindows 这个函数你应该用了不少了吧,其余的参数可以参考 MSDN,但是类名我们指定了 “BUTTON”,说明我们要创建一个按钮,每个按钮都有一个唯一的 ID,通过你的消息处理函数,可以知道哪个按钮发生了什么事件,详细讲的话,非常多,你可以参考 MSDN,或者《Windows 程序设计》这本书 。
展开全部
#include <windows.h>
#define ChuangKouGuanBi(msg) (msg==WM_CLOSE)
#define ChuangJianWanCheng(msg) (WM_CREATE==msg)
#define ChuangKouDaXiaoGaiBian(msg) (msg==WM_SIZE)
#define ChongZhiKongJian(hwnd,x,y,x2,y2) MoveWindow(hwnd,x,y,x2,y2,true);
typedef _Bool bool;
#define false ((bool)0)
#define true ((bool)1)
typedef struct
{
int x,y,z;
}ZuoBiaoXing;
typedef struct TuXingJieKouXing__
{
int x,y;
int **bp,**p;
}*TuXingJieKouXing;
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;
}
}
ZuoBiaoXing KongJianDaXiao(HWND hwnd)
{
ZuoBiaoXing zrect;
if(hwnd)
{
RECT rrect;
GetClientRect(hwnd,&rrect);
zrect.x=rrect.right;
zrect.y=rrect.bottom;
}
else
{
zrect.x=GetSystemMetrics(SM_CXSCREEN);
zrect.y=GetSystemMetrics(SM_CYSCREEN);
}
return zrect;
}
bool MoRenXiaoXiChuLi(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam,TuXingJieKouXing tp)
{
static HDC hdc=0;
if(tp&&hdc)
{
int i,j;
for(i=0;i<tp->x;i++)
{
for(j=0;j<tp->y;j++)
{
if(tp->bp[i][j]!=tp->p[i][j])
{
tp->bp[i][j]=tp->p[i][j];
SetPixel(hdc,i,j,tp->p[i][j]);
}
}
}
}
if(ChuangKouGuanBi(message))
{
return true;
}
else if(ChuangJianWanCheng(message))
{
hdc=GetDC(hwnd);
ReleaseDC(hwnd,hdc);
return true;
}
else
{
return (bool)DefWindowProc(hwnd,message,wParam,lParam);
}
}
bool GuanBiChuangKou(HWND hwnd)
{
return (bool)DestroyWindow(hwnd);
}
void TuiChuXiaoXiXunHuan()
{
PostQuitMessage(0);
}
HWND ChuangJianAnNiu(hwnd,s)
{
return CreateWindow(
"button",
"",
WS_CHILD|
WS_VISIBLE|
BS_NOTIFY|
((s==0)?BS_GROUPBOX:0)|
((s==1)?BS_PUSHBUTTON:0)|
((s==2)?BS_RADIOBUTTON:0)|
((s==3)?BS_3STATE:0),
0,0,
0,0,
hwnd,
0,0,0
);
}
bool SheZhiKongJianWenZi(HWND hwnd,char *s)
{
return (bool)SetWindowText(hwnd,s);
}
bool WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
static HWND an1;
if(ChuangKouGuanBi(message))
{
GuanBiChuangKou(an1);
GuanBiChuangKou(hwnd);
TuiChuXiaoXiXunHuan();
}
else if(ChuangJianWanCheng(message))
{
an1=ChuangJianAnNiu(hwnd,1);
SheZhiKongJianWenZi(an1,"按钮");
}
else if(ChuangKouDaXiaoGaiBian(message))
{
ChongZhiKongJian(an1,0,0,100,100);
}
return MoRenXiaoXiChuLi(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());
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询