I do not know how to list all windows that are open using EnumWindows. Or is it another function? Anyhow, what do I use for a callback function with EnumWindows and put the titles in a ListBox(I know how to use LB_ADDSTRING);?
I do not know how to list all windows that are open using EnumWindows. Or is it another function? Anyhow, what do I use for a callback function with EnumWindows and put the titles in a ListBox(I know how to use LB_ADDSTRING);?
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
The reply I gave here works (I tried it with Dev C++ and MSVC). Make sure that you declare EnumWinProc() before it's used, that you don't define functions with semi-colons after their argument lists, that you declare variables before they're used in functions and that function definitions are in global scope rather than embedded in other functions. I couldn't tell from the code you posted if the code you were using contained these errors or that was just the way you posted it.
zen
I am not getting the linker errors I did before, but now I did:
case WM_CREATE:
lBox = CreateWindow(
"LISTBOX",
"",
WS_CHILD | WS_VISIBLE,
0,
0,
200,
200,
hwnd,
(HMENU)IDC_LIST1,
hInst,
NULL
);
BOOL CALLBACK EnumWinProc(HWND hWnd,LPARAM lParam)
{
HWND lBox= (HWND)lParam;
CHAR lpWinName[MAX_PATH];
GetWindowText(hwnd,lpWinName,MAX_PATH);
if(strlen(lpWinName))
SendMessage(lBox,LB_ADDSTRING,
0,(LPARAM)lpWinName);
return TRUE;
}
EnumWindows(EnumWinProc,(LPARAM)lBox);
and the COMPILER errors are:
92 enmwnd.cpp
parse error before `{'
103 enmwnd.cpp
`EnumWinProc' undeclared (first use this function)
103 enmwnd.cpp
(Each undeclared identifier is reported only once
103 enmwnd.cpp
for each function it appears in.)
104 enmwnd.cpp
break statement not within loop or switch
105 enmwnd.cpp
case label `2' not within a switch statement
105 enmwnd.cpp
confused by earlier errors, bailing out
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
I made a sort of a task manager like a week ago. want me to give you the code or something?
and by the way, the errors you're getting are not within the code you gave.
Yes,please. Will you please let me see some code. I don't steal another person's code.I just use it to learn.
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
that's the entire thing, I didn't feel like cutting pieces out...Code:#include <windows.h> #include "resource.h" BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM); BOOL CALLBACK RenameDlgProc(HWND, UINT, WPARAM, LPARAM); HWND hwndList; char title[MAX_PATH] = {0}; BOOL CALLBACK EnumWinProc(HWND hwnd,LPARAM lParam) { hwndList = (HWND)lParam; CHAR lpWinName[MAX_PATH]; GetWindowText(hwnd,lpWinName,MAX_PATH); if(strlen(lpWinName)) SendMessage(hwndList,LB_ADDSTRING,0,(LPARAM)lpWinName); return TRUE; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nCmdShow) { DialogBox(hInstance, (char *)IDD_MAINDLG, NULL, DlgProc); return 0; } BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { int index; HWND hTitle; switch(Message) { case WM_INITDIALOG: hwndList = CreateWindow("listbox","", WS_CHILD | WS_VISIBLE | LBS_STANDARD, 0,0,450,260,hwnd,NULL, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), 0); EnumWindows(EnumWinProc,(LPARAM)hwndList); return TRUE; case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_VIEW: index = SendMessage(hwndList, LB_GETCURSEL, 0, 0); SendMessage(hwndList, LB_GETTEXT, index, (LPARAM)title); hTitle = FindWindow(NULL, title); ShowWindow(hTitle, WS_MAXIMIZE); return TRUE; case IDC_REFRESHL: SendMessage(hwndList, LB_RESETCONTENT, 0, 0); EnumWindows(EnumWinProc,(LPARAM)hwndList); return TRUE; case IDC_DISABLE: index = SendMessage(hwndList, LB_GETCURSEL, 0, 0); SendMessage(hwndList, LB_GETTEXT, index, (LPARAM)title); hTitle = FindWindow(NULL, title); EnableWindow(hTitle, FALSE); return TRUE; case IDCLOSE: index = SendMessage(hwndList, LB_GETCURSEL, 0, 0); SendMessage(hwndList, LB_GETTEXT, index, (LPARAM)title); hTitle = FindWindow(NULL, title); SendMessage(hTitle, WM_CLOSE, 0, 0); SendMessage(hTitle, WM_DESTROY, 0, 0); SendMessage(hwndList, LB_RESETCONTENT, 0, 0); EnumWindows(EnumWinProc,(LPARAM)hwndList); return TRUE; case IDRENAME: index = SendMessage(hwndList, LB_GETCURSEL, 0, 0); SendMessage(hwndList, LB_GETTEXT, index, (LPARAM)title); DialogBox((HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), (char *)IDD_RENAME, NULL, RenameDlgProc); return TRUE; case IDCANCEL: EndDialog(hwnd,0); return TRUE; } return TRUE; } return FALSE; } BOOL CALLBACK RenameDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { HWND hTitle; char newtitle[MAX_PATH]; switch(Message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: switch(LOWORD(wParam)) { case IDOK: GetDlgItemText(hwnd, IDC_EDIT1, newtitle, MAX_PATH); hTitle = FindWindow(NULL, title); SetWindowText(hTitle, newtitle); SendMessage(hwndList, LB_RESETCONTENT, 0, 0); EnumWindows(EnumWinProc,(LPARAM)hwndList); case IDCANCEL: EndDialog(hwnd,0); return TRUE; } return TRUE; } return FALSE; }
Last edited by -KEN-; 11-04-2001 at 03:28 PM.