Jump to content

How to make Windows Explorer to Create a New Folder via CTRL-N?


Zohar
 Share

Recommended Posts

Hello

When we RightClick in windows explorer, select New, and the select Folder,

a new folder is created.

I would like to "trap" the Windows Message that is being sent exactly when I click on the "Folder" MenuItem,

so I can then use SendMessage() along with HotKeySet, to make CTRL-N create a New Folder in windows explorer,

without the need to mess with the rightclick menu, and wait until all the New types of items there will load.

Please note that using KeyStrokes, like Send("!fwf") will indeed create a folder,

but it will still have the delay, because it actually shows the menu+submenu.

so that's why I prefer to SendMessage() along with the message that belongs to that specific menuitem, without even opening it.

I have Spy++.

can anyone direct me?

thank you

Edited by Zohar
Link to comment
Share on other sites

#include <SendMessage.au3>
Opt('MustDeclareVars', 1)

Dim $hProgMan, $hDefView, $hFolderView, $hDll

$hDll = DllOpen('user32.dll')

$hProgMan = _WinAPI_FindWindow('Progman', 'Program Manager', $hDll)
ConsoleWrite(Hex($hProgMan) & @CRLF)

$hDefView = FindWindowEx($hProgMan, 0, 'SHELLDLL_DefView', '', $hDll)
ConsoleWrite(Hex($hDefView) & @CRLF)

$hFolderView = FindWindowEx($hDefView, 0, 'SysListView32', 'FolderView', $hDll)
ConsoleWrite(Hex($hFolderView) & @CRLF)

_SendMessage($hFolderView, 0x0111, 0x01000000, 0) ;0x004D0532
_SendMessage($hDefView, 0x0111, 0x01000000, 0)

Exit


Func _WinAPI_FindWindow($sClassName, $sWindowName, $hUser32 = 'user32.dll')
    Local $aResult

    $aResult = DllCall($hUser32, 'hwnd', 'FindWindow', 'str', $sClassName, 'str', $sWindowName)
    If @error Then Return SetError(@error, 0, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_FindWindow



Func FindWindowEx($hWndParent, $hWndChildAfter, $sClass, $sWindow, $hUser32 = 'user32.dll')
    Local $aResult
    
    $aResult = DllCall($hUser32, 'hwnd', 'FindWindowEx', 'hwnd', $hWndParent, 'hwnd', $hWndChildAfter, 'str', $sClass, 'str', $sWindow)
    If @error Then Return SetError(@error, 0, 0)
    Return $aResult[0]
EndFunc   ;==>FindWindowEx


Func OnAutoItExit()
    DllClose($hDll)
EndFunc

The problem is that the WM_COMMAND always send wParam 0x01000000 and lParam get changed so you'll need to investigate a little bit more about the lParam purpose... I've kept it as 0 in the _SendMessage call.

Link to comment
Share on other sites

Here you can use this:

AutoItSetOption("WinDetectHiddenText", 1)

If Not WinExists("[CLASS:CabinetWClass]") Then Exit(1)
$sText = WinGetText("[CLASS:CabinetWClass]")
$sText = StringSplit($sText, @CRLF)

For $sResult In $sText
    If StringInStr($sResult, "Address: ") Then _Result($sResult)
Next

Func _Result($sResult = "")
    $sString = StringRegExpReplace($sResult, "Address: ", "")
    $sInput = InputBox("Folder View", "What do you want to call the folder", "")
    $sString = $sString & "\" & $sInput
    DirCreate($sString)
EndFunc

The thing with this is it doesn't use any UDF

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Link to comment
Share on other sites

Hi terarink and thank you for your reply.

What you do will indeed work, but by using DirCreate(), you're completely bypassing Windows Explorer.

I could use also "md <foldername>" in DOS in the same way.

My problem is not to create a folder, but to create a folder via Windows Explorer's GUI.

That's why the only way, is to simulate a MenuItem Click on the "Folder" item in the "New" SubMenu.

If anyone knows how to do it, please write..

Edited by Zohar
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...