I want to get the first HWND owned by a ProcessID. Everything runs but it always shows the dialog box saying "No windows found" but i know it is there since i can see on on the screen.
(I find it hard to debug in windows programs since i cant put printf everywhere, how is printf debugging done while writing windows programs?)
Code://Global variables DWORD processID = NULL; DWORD tempID = NULL; HWND myHWND = NULL; BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lparam) { //Getting the ProcessID for that the HWND belongs to tempID=GetWindowThreadProcessId(hwnd,NULL); //If the ID is the same as my process id if (tempID == processID){ //Take this hwnd as the one i want myHWND = hwnd; //Quit the Enum when the first window is found return (FALSE); } //Otherwise run again return (TRUE); } -------------------------------------------------------- This code runs when i hit a button //Returns processID from functions that first runs CreateProcess and then GetProcessID and returns it processID = startup(); //Iterate every windows to find the first one that belongs to my process EnumWindows(&EnumWindowsProc,NULL); //If the global variabel have recived a value the IF expression got executed in EnumWindowProc if (myHWND != NULL) //Visual confirmation of my the HWND SetDlgItemInt(hwnd, IDC_NUMBER, (DWORD)myHWND, FALSE); else //Found no windows for this process MessageBox(hwnd, "No windows found!", "Warning", MB_OK);



LinkBack URL
About LinkBacks


