怎么用C语言窗口中同时加入按钮控件和文本
以下是C语言代码 怎么在里面加入文本控件和下拉菜单控件 拜谢!
#include<windows.h>
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM ) ;
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow )
{
static TCHAR szAppName[] = TEXT( "CreateChildWindow" ) ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.lpfnWndProc = WndProc ;
wndclass.lpszClassName = szAppName ;
wndclass.style = CS_VREDRAW | CS_HREDRAW ;
wndclass.hInstance = hInstance ;
wndclass.hCursor = LoadCursor( NULL, IDC_ARROW ) ;
wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION ) ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH ) ;
wndclass.lpszMenuName = NULL ;
if( !RegisterClass(&wndclass) )
{
MessageBox( NULL, TEXT("无法注册窗口类!"), szAppName, MB_OK | MB_ICONERROR ) ;
return 0 ;
}
hwnd = CreateWindow( szAppName, TEXT("6灯窗口"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
800, 600,
NULL, NULL, hInstance, NULL ) ;
ShowWindow( hwnd, iCmdShow ) ;
UpdateWindow( hwnd ) ;
while( GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage( &msg ) ;
DispatchMessage( &msg ) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
static HWND btnHwnd ;
switch(message)
{
case WM_CREATE:
btnHwnd = CreateWindow( TEXT("button"), TEXT("协议"),
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
10, 10,
100, 30,
hwnd,
(HMENU)1,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE ),
NULL ) ;
btnHwnd = CreateWindow( TEXT("button"), TEXT("非协议"),
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
10, 40,
100, 30,
hwnd,
(HMENU)1,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE ),
NULL ) ;
btnHwnd = CreateWindow( TEXT("button"), TEXT("字符"),
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
10, 70,
100, 30,
hwnd,
(HMENU)1,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE ),
NULL ) ;
btnHwnd = CreateWindow( TEXT("button"), TEXT("十六进制"),
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
10, 100,
100, 30,
hwnd,
(HMENU)1,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE ),
NULL ) ;
btnHwnd = CreateWindow( TEXT("button"), TEXT("灯1"),
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
10, 300,
100, 30,
hwnd,
(HMENU)1,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE ),
NULL ) ;
btnHwnd = CreateWindow( TEXT("button"), TEXT("灯2"),
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
10, 330,
100, 30,
hwnd,
(HMENU)1,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE ),
NULL ) ;
btnHwnd = CreateWindow( TEXT("button"), TEXT("灯3"),
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
10, 360,
100, 30,
hwnd,
(HMENU)1,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE ),
NULL ) ;
btnHwnd = CreateWindow( TEXT("button"), TEXT("灯4"),
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
10, 390,
100, 30,
hwnd,
(HMENU)1,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE ),
NULL ) ;
btnHwnd = CreateWindow( TEXT("button"), TEXT("灯5"),
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
10, 420,
100, 30,
hwnd,
(HMENU)1,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE ),
NULL ) ;btnHwnd = CreateWindow( TEXT("button"), TEXT("灯6"),
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
10, 450,
100, 30,
hwnd,
(HMENU)1,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE ),
NULL ) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage( 0 ) ;
return 0 ;
}
return DefWindowProc( hwnd, message, wParam, lParam ) ;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
引用来自“痞子汤”的评论
误入迷途的学生,o(︶︿︶)o 唉
误入迷途的学生,o(︶︿︶)o 唉
如果就是想单纯用C写出来,该怎么写呢。
回复
@囧囧you神 : 原理可以了解下,还是不要自己去写
真佩服你这样的人,我连个WinMain函数都不会写
谢谢
引用来自“earthdog”的评论
你这样一个个创建太麻烦了,用VC的对话框资源吧。里面有你想要的这些控件,而且实例化也方便很多。