vc api中CreateWindow 函数的详细用法跟解释。
展开全部
《Windows程序设计》这本书很好,C+API+VC
RC文件由VC维护,我们只需要在VC界面插入资源,某些特殊情况下,也可以自己用记事本打开RC文件进行修改。
1.创建主窗口,myclassname是自己用WNDCLASS注册的类名
//参数依次是:类名-窗口标题-窗口样式-x-y-width-height-父窗口-菜单ID-实例句柄-CREATESTURCT指针
hwnd = CreateWindow(TEXT("myclassname"),TEXT("未命名"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
2.创建子窗口:必须有WS_CHILD样式,必须指定父窗口
//edit static button listbox 是系统预先定义好的类名
//对button指定不同的样式,可有单选按钮、多选按钮、复选框等等形式
//对static指定不同的样式,可显示矩形区域、静态文字、加载图标、位图等
CreateWindow(TEXT("edit"),TEXT("ES_LEFT"),WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_MULTILINE|ES_LEFT,0,0,cxChar*20,2*cyChar,hwnd,(HMENU)12,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("GROUPBOX"),WS_CHILD|WS_VISIBLE|BS_GROUPBOX,0,3*cyChar,60,4*cyChar,hwnd,(HMENU)0,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("RADIOBUTTON"),WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,0,8*cyChar,60,cyChar,hwnd,(HMENU)1,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("AUTORADIOBUTTON"),WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,0,10*cyChar,60,cyChar,hwnd,(HMENU)2,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("AUTOCHECKBOX"),WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,0,12*cyChar,12*cxChar,cyChar,hwnd,(HMENU)3,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("CHECKBOX"),WS_CHILD|WS_VISIBLE|BS_CHECKBOX,0,14*cyChar,12*cxChar,cyChar,hwnd,(HMENU)4,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("3STATE"),WS_CHILD|WS_VISIBLE|BS_3STATE,0,16*cyChar,12*cxChar,cyChar,hwnd,(HMENU)5,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("AUTO3STATE"),WS_CHILD|WS_VISIBLE|BS_AUTO3STATE,0,18*cyChar,12*cxChar,cyChar,hwnd,(HMENU)6,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("PUSHBUTTON"),WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,0,20*cyChar,12*cxChar,cyChar,hwnd,(HMENU)7,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("DEFPUSHBUTTON"),WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,0,22*cyChar,12*cxChar,cyChar,hwnd,(HMENU)8,hInst,NULL);
CreateWindow(TEXT("static"),TEXT("SS_LEFT"),WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL|SS_LEFT,0,24*cyChar,12*cxChar,cyChar,hwnd,(HMENU)9,hInst,NULL);
CreateWindow(TEXT("static"),TEXT("SS_BLACKRECT"),WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL|SS_BLACKRECT,0,26*cyChar,12*cxChar,cyChar,hwnd,(HMENU)10,hInst,NULL);
CreateWindow(TEXT("static"),TEXT("SS_BLACKFRAME"),WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL|SS_BLACKFRAME,0,28*cyChar,12*cxChar,cyChar,hwnd,(HMENU)11,hInst,NULL);
RC文件由VC维护,我们只需要在VC界面插入资源,某些特殊情况下,也可以自己用记事本打开RC文件进行修改。
1.创建主窗口,myclassname是自己用WNDCLASS注册的类名
//参数依次是:类名-窗口标题-窗口样式-x-y-width-height-父窗口-菜单ID-实例句柄-CREATESTURCT指针
hwnd = CreateWindow(TEXT("myclassname"),TEXT("未命名"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
2.创建子窗口:必须有WS_CHILD样式,必须指定父窗口
//edit static button listbox 是系统预先定义好的类名
//对button指定不同的样式,可有单选按钮、多选按钮、复选框等等形式
//对static指定不同的样式,可显示矩形区域、静态文字、加载图标、位图等
CreateWindow(TEXT("edit"),TEXT("ES_LEFT"),WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_MULTILINE|ES_LEFT,0,0,cxChar*20,2*cyChar,hwnd,(HMENU)12,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("GROUPBOX"),WS_CHILD|WS_VISIBLE|BS_GROUPBOX,0,3*cyChar,60,4*cyChar,hwnd,(HMENU)0,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("RADIOBUTTON"),WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,0,8*cyChar,60,cyChar,hwnd,(HMENU)1,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("AUTORADIOBUTTON"),WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,0,10*cyChar,60,cyChar,hwnd,(HMENU)2,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("AUTOCHECKBOX"),WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,0,12*cyChar,12*cxChar,cyChar,hwnd,(HMENU)3,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("CHECKBOX"),WS_CHILD|WS_VISIBLE|BS_CHECKBOX,0,14*cyChar,12*cxChar,cyChar,hwnd,(HMENU)4,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("3STATE"),WS_CHILD|WS_VISIBLE|BS_3STATE,0,16*cyChar,12*cxChar,cyChar,hwnd,(HMENU)5,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("AUTO3STATE"),WS_CHILD|WS_VISIBLE|BS_AUTO3STATE,0,18*cyChar,12*cxChar,cyChar,hwnd,(HMENU)6,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("PUSHBUTTON"),WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,0,20*cyChar,12*cxChar,cyChar,hwnd,(HMENU)7,hInst,NULL);
CreateWindow(TEXT("button"),TEXT("DEFPUSHBUTTON"),WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,0,22*cyChar,12*cxChar,cyChar,hwnd,(HMENU)8,hInst,NULL);
CreateWindow(TEXT("static"),TEXT("SS_LEFT"),WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL|SS_LEFT,0,24*cyChar,12*cxChar,cyChar,hwnd,(HMENU)9,hInst,NULL);
CreateWindow(TEXT("static"),TEXT("SS_BLACKRECT"),WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL|SS_BLACKRECT,0,26*cyChar,12*cxChar,cyChar,hwnd,(HMENU)10,hInst,NULL);
CreateWindow(TEXT("static"),TEXT("SS_BLACKFRAME"),WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL|SS_BLACKFRAME,0,28*cyChar,12*cxChar,cyChar,hwnd,(HMENU)11,hInst,NULL);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询