Knowledge Base Nr: 00173 enumwin.cpp - http://www.swe-kaiser.de

Downloads:

MFC: alle controls eines dialogs nach static controls durchsuchen

  
////////////////////////
//im mainframe einbauen

class CMainFrame : public CMDIFrameWnd
{
...
public:
static BOOL CALLBACK MyEnumChildProc(HWND hwnd, LPARAM lParam);
...
}

BOOL CALLBACK CMainFrame::MyEnumChildProc(HWND hwnd, LPARAM lParam)
{
char szClass[100] = {0};
char szText[100] = {0};
char szNewText[100] = {0};

::GetClassName(hwnd, szClass, sizeof(szClass));
if (strcmp("Static", szClass) == 0)
{
::GetWindowText(hwnd, szText, sizeof(szText));
TRACE("wnd:0x%x lparam:%d class:%s wndtext:%s \n", hwnd, lParam, szClass, szText);

//TODO: hier text übersetzen oder ähnliches
sprintf(szNewText, "bla:%s:bla", szText);

::SetWindowText(hwnd, szNewText);
}

return TRUE;
}

////////////////////////
//in views nutzen

#include "MainFrm.h"

void CEnumwinView::OnButton1()
{
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
WNDENUMPROC lpEnumFunc = pMainWnd->MyEnumChildProc;

BOOL bSucc = EnumChildWindows(GetSafeHwnd(), lpEnumFunc, IDD);
ASSERT(bSucc);
}