win32 Notes
2022-09-19
I'm gonna probably add to this over time
Spawn a console:AllocConsole(); FILE* fDummy; freopen_s(&fDummy, "CONOUT$", "w", stdout);
Get the number of lines scrolled with the mousewheel:
case WM_MOUSEWHEEL: { UINT scrollLines; SystemParametersInfoA(SPI_GETWHEELSCROLLLINES, 0, &scrollLines, 0); short deltaLines = (short)scrollLines * (GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA); //result return 0; }
This code will open a folder select dialog and print the path of the selected folder, followed by the names of all the files and folders within that folder:
#include <shobjidl_core.h> #include <Shlguid.h> //... IFileDialog *pfd; IShellItem *psi, *fpsi; PWSTR path = NULL; IEnumShellItems *pes; if (SUCCEEDED(CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, &IID_IFileOpenDialog, &pfd))){ pfd->lpVtbl->SetOptions(pfd, FOS_PICKFOLDERS); pfd->lpVtbl->Show(pfd, hwnd); if (SUCCEEDED(pfd->lpVtbl->GetResult(pfd, &psi))){ if (SUCCEEDED(psi->lpVtbl->GetDisplayName(psi, SIGDN_FILESYSPATH, &path))){ print_wstr(path); //prints folder path CoTaskMemFree(path); if (SUCCEEDED(psi->lpVtbl->BindToHandler(psi, NULL, &BHID_EnumItems, &IID_IEnumShellItems, &pes))){ while (S_OK == pes->lpVtbl->Next(pes, 1, &fpsi, NULL)){ if (SUCCEEDED(fpsi->lpVtbl->GetDisplayName(fpsi, SIGDN_PARENTRELATIVEPARSING, &path))){ print_wstr(path); //prints item name CoTaskMemFree(path); } fpsi->lpVtbl->Release(fpsi); } pes->lpVtbl->Release(pes); } } psi->lpVtbl->Release(psi); } pfd->lpVtbl->Release(pfd); }The print_wstr function is just for demonstration. Also, the strings returned by GetDisplayName are NULL terminated.