CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2012
    Posts
    14

    Exclamation Windows Function

    FindWindow(NULL,"Windows Task Manager");
    not working in c language any one tell me why here i use title of task manager i know first perameter i can also use but i wanna use second one i use dev c++ compiler and also add user32.a lib in project when i call that function its return NULL thx

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Windows Function

    If you are programming in Windows then you must read MSDN documentation about all Windows APIs you are using.
    From MSDN:
    FindWindow
    The FindWindow function retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search.

    To search child windows, beginning with a specified child window, use the FindWindowEx function.

    HWND FindWindow(
    LPCTSTR lpClassName, // class name
    LPCTSTR lpWindowName // window name
    );

    ...
    Return Values
    If the function succeeds, the return value is a handle to the window that has the specified class name and window name.

    If the function fails, the return value is NULL. To get extended error information, call GetLastError.
    So what does GetLastError return?
    Victor Nijegorodov

  3. #3
    Join Date
    May 2012
    Posts
    14

    Re: Windows Function

    error = the specified module could not be found

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Windows Function

    Well, this code
    Code:
    	HWND hWnd = ::FindWindow(NULL, "Windows Task Manager");
    does work for me in a console VC++ application, MBCS build.
    If your build is UNICODE then you must pass in the wide char string:
    Code:
    	HWND hWnd = ::FindWindow(NULL, L"Windows Task Manager");
    The only requirement for success, however is Task Manager must run.
    Victor Nijegorodov

  5. #5
    Join Date
    May 2012
    Posts
    14

    Re: Windows Function

    thx for it ur last line my answer but i have one noob type question this function work when window open at desktop?????
    basically findwindow mean find window but i think its requires

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Windows Function

    If window is closed then its handle is closed too. Therefore FindWindow cannot find it (how would it possible to find what not exists!?)
    If Task Manager is minimized to tray its main window is closed, thus FindWindow cannot find it.
    Victor Nijegorodov

  7. #7
    Join Date
    May 2012
    Posts
    14

    Re: Windows Function

    yes u r right i solve my prblem thx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured