Skip to content

Commit 648368b

Browse files
committed
fix marquee progress bar, use file specific icon
1 parent a13f63d commit 648368b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ If you want to read source code, you can find there & learn about following thin
4040
* Copying & pasting text from/to clipboard
4141
* Simple progress dialog using Windows [TaskDialog][] common control
4242
* Basic drag & drop to handle files dropped on window, using [DragAcceptFiles][] function
43+
* Retrieving Windows registered file icon using [SHGetFileInfo][] function
4344

4445
TODOs
4546
=====
@@ -77,3 +78,4 @@ a compiled binary, for any purpose, commercial or non-commercial, and by any mea
7778
[VS]: https://visualstudio.microsoft.com/vs/
7879
[TaskDialog]: https://learn.microsoft.com/en-us/windows/win32/controls/task-dialogs-overview
7980
[DragAcceptFiles]: https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-dragacceptfiles
81+
[SHGetFileInfo]: https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shgetfileinfow

ScreenBuddy.c

+19-2
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,7 @@ static HRESULT CALLBACK Buddy_TaskCallback(HWND TaskWindow, UINT Message, WPARAM
15571557
{
15581558
case TDN_CREATED:
15591559
Buddy->ProgressWindow = TaskWindow;
1560+
SendMessageW(TaskWindow, TDM_SET_PROGRESS_BAR_MARQUEE, TRUE, 0);
15601561
break;
15611562
}
15621563
return S_OK;
@@ -1588,6 +1589,9 @@ static void Buddy_SendFile(ScreenBuddy* Buddy, wchar_t* FileName)
15881589
}
15891590
else
15901591
{
1592+
SHFILEINFOW FileInfo;
1593+
DWORD_PTR IconOk = SHGetFileInfoW(FileName, 0, &FileInfo, sizeof(FileInfo), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES);
1594+
15911595
PathStripPathW(FileName);
15921596

15931597
TASKDIALOGCONFIG Config =
@@ -1597,7 +1601,7 @@ static void Buddy_SendFile(ScreenBuddy* Buddy, wchar_t* FileName)
15971601
.dwFlags = TDF_USE_HICON_MAIN | TDF_ALLOW_DIALOG_CANCELLATION | TDF_SHOW_MARQUEE_PROGRESS_BAR | TDF_CAN_BE_MINIMIZED | TDF_SIZE_TO_CONTENT,
15981602
.dwCommonButtons = TDCBF_CANCEL_BUTTON,
15991603
.pszWindowTitle = BUDDY_TITLE,
1600-
.hMainIcon = Buddy->Icon,
1604+
.hMainIcon = IconOk ? FileInfo.hIcon : Buddy->Icon,
16011605
.pszMainInstruction = FileName,
16021606
.pszContent = L"Sending file...",
16031607
.nDefaultButton = IDCANCEL,
@@ -1610,6 +1614,11 @@ static void Buddy_SendFile(ScreenBuddy* Buddy, wchar_t* FileName)
16101614

16111615
Buddy->ProgressWindow = NULL;
16121616
Buddy->FileHandle = NULL;
1617+
1618+
if (IconOk)
1619+
{
1620+
DestroyIcon(FileInfo.hIcon);
1621+
}
16131622
}
16141623
}
16151624

@@ -2242,6 +2251,9 @@ static void Buddy_NetworkEvent(ScreenBuddy* Buddy)
22422251

22432252
if (Buddy->FileHandle)
22442253
{
2254+
SHFILEINFOW FileInfo;
2255+
DWORD_PTR IconOk = SHGetFileInfoW(FileName, 0, &FileInfo, sizeof(FileInfo), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES);
2256+
22452257
PathStripPathW(FileName);
22462258

22472259
Buddy->FileProgress = 0;
@@ -2258,7 +2270,7 @@ static void Buddy_NetworkEvent(ScreenBuddy* Buddy)
22582270
.dwFlags = TDF_USE_HICON_MAIN | TDF_ALLOW_DIALOG_CANCELLATION | TDF_SHOW_MARQUEE_PROGRESS_BAR | TDF_CAN_BE_MINIMIZED | TDF_SIZE_TO_CONTENT,
22592271
.dwCommonButtons = TDCBF_CANCEL_BUTTON,
22602272
.pszWindowTitle = BUDDY_TITLE,
2261-
.hMainIcon = Buddy->Icon,
2273+
.hMainIcon = IconOk ? FileInfo.hIcon : Buddy->Icon,
22622274
.pszMainInstruction = FileName,
22632275
.pszContent = L"Receiving file...",
22642276
.nDefaultButton = IDCANCEL,
@@ -2271,6 +2283,11 @@ static void Buddy_NetworkEvent(ScreenBuddy* Buddy)
22712283
TaskDialogIndirect(&Config, NULL, NULL, NULL);
22722284
Buddy->ProgressWindow = NULL;
22732285

2286+
if (IconOk)
2287+
{
2288+
DestroyIcon(FileInfo.hIcon);
2289+
}
2290+
22742291
if (Buddy->FileHandle)
22752292
{
22762293
CloseHandle(Buddy->FileHandle);

0 commit comments

Comments
 (0)