谁有一个ListBox控件的例子 SDK程序 不用CListBox实现
想只用SDK单文件实现 不想用MFC/VC++下CListBox类实现MSDN上的资料全是关于CListBox类实现的
现在已经创建了一个控件窗口 但是就是不知道该如何声明一个结构变量去控制(不知道数据类型是什么名)
希望有经验的朋友帮帮忙
#include <windows.h> #include <malloc.h> #include <commctrl.h> #define ID_LISTVIEW 117 #define WIN_START_X 100 #define WIN_START_Y 100 #define WIN_WIDTH 600 #define WIN_HEIGHT 600 #pragma comment(lib,"comctl32.lib") LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; HWND CreateListBoxView(HWND hwndParent, LPSTR lpszFileName) ; HINSTANCE g_hinst ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("SineWave") ; MSG msg ; WNDCLASS wndclass; HWND hwnd ; //CListBox *m_list = new CListBox() ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground= (HBRUSH) GetStockObject (LTGRAY_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass)) { MessageBox ( NULL, TEXT ("Program requires Windows NT!"), szAppName, MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow ( szAppName, TEXT ("母本窗口"), WS_OVERLAPPEDWINDOW, WIN_START_X, WIN_START_Y, WIN_WIDTH, WIN_WIDTH, NULL, NULL, hInstance, NULL) ; g_hinst = hInstance ; CreateListBoxView( hwnd, "目录.txt") ; ShowWindow (hwnd, SW_SHOW) ; 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) { HDC hdc ; PAINTSTRUCT ps ; switch (message) { case WM_CREATE: return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; } HWND CreateListBoxView(HWND hwndParent, LPSTR lpszFileName) { RECT rcClient; HWND hwndLV; LVITEM m_listBox ; // Ensure that the common control DLL is loaded. InitCommonControls(); // Get the dimensions of the parent window's client area, and create // the ListBox control. GetClientRect(hwndParent, &rcClient); hwndLV = CreateWindowEx(0, WC_LISTBOXW, TEXT("LIST View"), WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES, 0, 0, rcClient.right, rcClient.bottom, hwndParent, (HMENU)ID_LISTVIEW, g_hinst, NULL); return hwndLV; }