CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2008
    Location
    India
    Posts
    780

    Handle Show Desktop in MFC.

    Hi all,

    I have SDI type application.I want to handle Show Desktop from all options.

    like from Quick Launch option,Wnd+D,Show the Desktopn From TaskBar menu, etc.

    please can u tell me solution for this.

    how can handle all options of show desktop.

    please explain me with example.

    thanks in advance.
    IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

  2. #2
    Join Date
    Nov 2007
    Posts
    53

    Re: Handle Show Desktop in MFC.

    Are you wanting to hook it at a user level? I can help with that if that's what your wanting to do.

    If your looking for information on how ShowWindow works, well I'm not entirely sure myself.
    I would imagine that, since ALL Windows created are HWND based("if you have the HWND, you have everything"), that it just simply sets the window's state, based on a flag.
    WS_VISIBLE is an example. So I'm sure you could modify something using the '|' symbol or binary operations to manually modify the window state. And then at it' core, I'm sure it works directly with GDI functions, or more-specifically, your HDC for the application. I am unsure which method Microsoft uses for ShowWindow at the HDC level. A first guess I would say just hide all the pixels from the buffer image(via skipping a RECT or possibly using an InvalidateRect type of procedure).

    Your question mentions: Quick Launch option,Wnd+D,Show the Desktopn From TaskBar menu.
    Quick Launch , Wnd+D , and the TaskBar one, ALL use the same function(methodically that is). Just run a loop iterating ALL the Visible windows, then execute a ShowWindow on them. Simple as that.

    As far as hooking goes...
    I haven't researched this function specifically, however I have researched the methadology for your question. Keep in mind that doing a "Global Hook" can be considered viral, and so I must stress preceeding my post that you should adhear to all godeguru guidelines when posting here, and ensure you ask appropriate questions therein. (*wink wink*)

    So with that aside, let me tell you the search term you are looking for. It's called User Mode Hooking. Your going to, depending on the function to intercept, be hooking either kernel32.dll or user32.dll in memory. Every application in windows uses these libraries for standard windows functions. That means, if you "hook" this function inside kernel32.dll or user32.dll respectively, you be intercepting this function call prior to the usage by ANY program in windows.

    This is not an easy task, and so I won't even try to explain it all here. Your best bet is to research "DLL Hooking" (other search-engine terms are: "DLL Injection", or "IAT Table Routing", or "Code Cave Patching", etc).

    Basically, depending on your choice in the many available options(Code Cave patching, Page File Overwriting, IAT Table patching, DLL Injection, etc), you will do one of the following things:
    a.) Replace the memory address of ShowWindow() with the address of your equivelant function(same parameters, same return type. Most people return the address of the original function, as to prevent any system errors - you could return 0 if you want to disable ShowWindow entirely). (See "IAT Hooking")
    b.) Patch assembly code after finding a Code Cave within kernel32 or user32.dll in memory, and use assembly op codes to forward ("JMP") to the address of your function(or your assembled code in the code cave - not recommended)
    c.) Inject a DLL into any&all instances of the dll in memory(Global Hook), and use Page File modifcations to modify your access level to the memory pages, then modify the user-mode code to call your function.

    Since your likely a first-timer on this process, I HIGHLY , and again I say HIGHLY, recommend, that you use Microsoft Detours Library(Option 'c' above). It will give you easy access to the methadology presented above. Although it isn't documented well by microsoft, there are plenty of available source examples on the net for this, and Detours is easy once you do it the first time - plus, it will give you work-in knowledge, so you'll be able to understand how it works more easily.

    Keep in mind that each of these methods provide you with a unique set of limitations, and so regardless of your choice, you will absolutely have to tailor the API to your hooked function(Especially for code caves and IAT patching). DLL Injection, depending on your sub-method used(search internet for these), may work on NT O/S or higher only, and may have issues on Vista(ie WriteProcessMemory versus SetWindowsHookEx). So just research exactly what your needing to do, and apply the most suited method with that goal in mind.

    Hope this helps you. I know I've spent days if not weeks on researching this information. Feel free to contact me if you want some "working examples". I may be able to supply you with one or two depending on your exact project.

    Also, here's a website that was written by an utter genious, and straight up a really nice guy. I'm sure he could write a book on his knowledge in this area, and sell it even; but he's awesome enough to share it for free.
    http://www.edgeofnowhere.cc/viewtopic.php?p=2483118
    Last edited by dcyuri7; March 3rd, 2009 at 04:31 PM.

  3. #3
    Join Date
    Jan 2008
    Posts
    48

    Re: Handle Show Desktop in MFC.

    You don't need to hook anything.
    Just use COM (see Google (Groups), where code (C++/Win32) has been posted many times)

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