各控件的动态创建

C++代码
#pragma comment(lib, "comctl32.lib")   
#include <commctrl.h>  

1、按钮

C++代码
HWND hButton = CreateWindow(TEXT("BUTTON"), szText, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd, (HMENU)0, hInst, 0);  

2、静态文本

C++代码
HWND hStatic = CreateWindow(TEXT("STATIC"), szText, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd, (HMENU)0, g_hInst, 0);  

3、编辑框

C++代码
HWND hEdit = CreateWindow(TEXT("EDIT"), szText, WS_CHILD | WS_VISIBLE | WS_BORDER, 0, 0, 0, 0, hwnd, (HMENU)0, g_hInst, 0);  

4、下拉框

C++代码
HWND hComboBox = CreateWindow(TEXT("COMBOBOX"), szText, WS_CHILD | WS_VISIBLE | CBS_DropDOWNLIST | CBS_SORT | WS_VSCROLL, 0, 0, 0, 0, hwnd, (HMENU)0, g_hInst, 0);  

5、Radio

C++代码
HWND hRadio = CreateWindow(TEXT("BUTTON"), szText, WS_CHILD | WS_VISIBLE | WS_GROUP | BS_AUTORADIOBUTTON, 0, 0, 0, 0, hwnd, (HMENU)0, g_hInst, 0);  

6、ListView

C++代码HWND hList = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("SysListView32"), 0, WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SINGLESEL, 0, 0, 0, 0, _hWnd, (HMENU)WM_IDC_LIST, g_hInst, 0);      
SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSelect | LVS_EX_GRIDLINES | LVS_EX_CHECKBOXES); 

你可能感兴趣的:(各控件的动态创建)