Purpose : New folder creation function in Windows Explorer (Desktop) (Icon coordinate setting + label correction)
I am wondering how to create a new folder like Windows Explorer (Desktop).
I want to know the same function as "Right click on desktop → New → Folder".
What I want is to make it to specific coordinates.
++ It would be better if you could also modify the label.
This is how I did it.
CreateDirectory → FindWindow (Desktop Listview) → SendMessage (LVM_SETITEMPOSITION)
But when I do CreateDirectory it appears too slow on the desktop.
(Default 1000ms or more)
So I tried SHChangeNotify but it appears slow.
That source code functions to move the mouse to a specific location on the desktop and press a shortcut to create a folder with that coordinate.
However, I can see the folder appearing slow and moving (SendMessage (LVM_SETITEMPOSITION)).
// this is Console Application
HWND hDesk = FindWindow(NULL, L"Program Manager");
HWND hDesk2 = FindWindowEx(hDesk, NULL, L"SHELLDLL_DefView", NULL);
HWND hListView = FindWindowEx(hDesk2, NULL, L"SysListView32", NULL);
int iconCount = (int)SendMessage(hListView, LVM_GETITEMCOUNT, NULL, NULL);
printf("컨트롤(Control) + F2\n");
RegisterHotKey(NULL, 1, MOD_CONTROL, VK_F2);
MSG msg;
while (GetMessage(&msg, 0, 0, 0))
{
PeekMessage(&msg, 0, 0, 0, 0x0001);
switch (msg.message)
{
case WM_HOTKEY:
if (msg.wParam == 1)
{
printf("ㅇㅋ 누름 (Hotkey Event)\n");
int a = SendMessage(hListView, LVM_GETITEMCOUNT, 0, 0);
int b;
int ms = GetTickCount();
CreateDirectory(L"C:\\Users\\root\\Desktop\\new Folder", NULL);
//SendMessage(hListView, LVM_REDRAWITEMS, 0, a+5);
//SendMessage(hListView, LVM_UPDATE, a, 0);
//SHChangeNotify(SHCNE_MKDIR, SHCNF_IDLIST| SHCNF_PATHW, L"C:\\Users\\root\\Desktop", NULL);
while (true)
{
b = SendMessage(hListView, LVM_GETITEMCOUNT, 0, 0);
if (a != b) {
ms = GetTickCount() - ms;
break;
}
}
Sleep(1);
POINT mouse;
GetCursorPos(&mouse);
SendMessage(hListView, LVM_SETITEMPOSITION, b - 1, MAKEWPARAM(mouse.x, mouse.y));
SendMessage(hListView, LVM_EDITLABEL, b - 1, 0);
}
}
}
I thought CreateDirectory was the problem and tried to create a directory using NtCreateFile (User Space / Ring3), but it is still slow.
The icon still appears slow on the desktop.
Is there WinAPI / DesktopAPI / COM / ATL for this?