|
楼主 |
发表于 2013-12-29 01:05:58
|
显示全部楼层
四川省成都市
// VC++ MFC- CListCtrl* List;
- BOOL CallBack(HWND hWnd,LPARAM lParam);
- BOOL 枚举窗口Dlg::OnInitDialog()
- {
- CDialogEx::OnInitDialog();
- SetIcon(m_hIcon, TRUE);
- SetIcon(m_hIcon, FALSE);
- List= &ListView1;
- ListView1.SetView(LVS_REPORT);
- DWORD dwStyle = ListView1.GetExtendedStyle();
- dwStyle |= LVS_EX_FULLROWSELECT;
- dwStyle |= LVS_EX_GRIDLINES;
- ListView1.SetExtendedStyle(dwStyle);
- ListView1.InsertColumn(0,L"hWnd",LVCFMT_LEFT,60);
- ListView1.InsertColumn(1,L"ClassName",LVCFMT_LEFT,60);
- ListView1.InsertColumn(2,L"TextName",LVCFMT_LEFT,60);
- EnumWindows((WNDENUMPROC)&CallBack,0);
- return TRUE;
- }
- wchar_t *str2wstrptr(const char *pStr)
- {
- PSTR pMultiByteStr = (PSTR)pStr;
- PWSTR pWideCharStr;
- int nLenOfWideCharStr;
- nLenOfWideCharStr = MultiByteToWideChar( CP_ACP, 0, pMultiByteStr, -1, NULL, 0);
- pWideCharStr = (PWSTR)malloc(nLenOfWideCharStr * sizeof(WCHAR));
- MultiByteToWideChar( CP_ACP, 0, pMultiByteStr, -1, pWideCharStr, nLenOfWideCharStr );
- return pWideCharStr;
- }
- BOOL CallBack(HWND hWnd,LPARAM lParam)
- {
- wchar_t buff_te[255];
- wchar_t buff_cl[255];
- char buff_hWnd[255];
- itoa((int)hWnd,buff_hWnd,255);
- GetWindowText(hWnd,buff_te,255);
- GetClassName(hWnd,buff_cl,255);
- int i=List->InsertItem(List->GetItemCount()+1,str2wstrptr(buff_hWnd));
- List->SetItemText(i,1,buff_cl);
- List->SetItemText(i,2,buff_te);
- List->Update(i);
- return TRUE;
- }
复制代码 |
|