CrystalDiskInfo icon indicating copy to clipboard operation
CrystalDiskInfo copied to clipboard

Program steals focus while in the taskbar when you change power source

Open ponjadito23 opened this issue 1 year ago • 11 comments

If you connect or disconnect your laptop while CrystalDiskInfo is in the taskbar and you have opened the GUI at least once, whatever program you're using will lose focus.

I discovered it was CrystalDiskInfo because when you press Alt+F4, CrystalDiskInfo would close and the problem no longer happened.

I'm using the latest version (8.17.3).

ponjadito23 avatar Jul 15 '22 19:07 ponjadito23

Sorry, I did not understand the procedure to reproduce it.

Could you please give me a step-by-step procedure? Images or videos would make it easier to understand.

And please attach the text copy (Edit > Copy) and DiskInfo.log. https://crystalmark.info/en/software/crystaldiskinfo/crystaldiskinfo-contact/

hiyohiyo avatar Jul 16 '22 23:07 hiyohiyo

Sure, I'll attach the logs and a video showing the problem.

DiskInfo64S.log

CrystalDiskInfo Edit Copy.txt

https://user-images.githubusercontent.com/17890647/179829291-63fadbe1-76ee-4913-b339-253a3fd7d582.mp4

ponjadito23 avatar Jul 19 '22 19:07 ponjadito23

Thank you for your detailed explanation. I will investigate this weekend to determine the cause.

hiyohiyo avatar Jul 22 '22 11:07 hiyohiyo

I could not reproduce the problem in my environment. I have fixed the suspicious part and would appreciate it if you could test it.

https://crystalmark.info/download/zz/CrystalDiskInfo8_17_5Beta2.zip


LRESULT CDiskInfoDlg::OnPowerBroadcast(WPARAM wParam, LPARAM lParam)
{
	switch(wParam)
	{
	case PBT_APMRESUMESUSPEND:
		SetTimer(TIMER_FORCE_REFRESH, 5 * 1000, 0);
		return TRUE;
		break;
	default:
		break;
	}

        // from TRUE to FALSE
	return FALSE;
}

hiyohiyo avatar Jul 23 '22 00:07 hiyohiyo

Thanks. I've tested it and it keeps happening. But now I'm curious if it only happens on this machine, I'll try on another.

ponjadito23 avatar Jul 23 '22 14:07 ponjadito23

Ok, I've tested the stable version on another computer and it doesn't happen there.

I've done extra tests on my main machine and I've noticed that the GUI window reloads when switching power. I also checked the resource usage on Process Explorer and the memory seems to spike briefly even when I've not opened the GUI at least once, so no focus steal yet. And all of this only seems to happen if explorer.exe is running.

I'll attach some screenshots of the mem spikes on both the Shizuku version I'm using and the beta you sent me.

Shizuku mem spike Standard mem spike

ponjadito23 avatar Jul 23 '22 15:07 ponjadito23

Thank you for your testing... I am investigating but have not yet identified the cause.

Does this problem also occur when not resident?

hiyohiyo avatar Jul 24 '22 07:07 hiyohiyo

No, It only occurs while resident and if I have opened it's window at least once.

ponjadito23 avatar Jul 25 '22 14:07 ponjadito23

Thank you. I will investigate resident-related processes.

hiyohiyo avatar Jul 25 '22 22:07 hiyohiyo

It may fix stealing focus problem. https://crystalmark.info/download/zz/CrystalDiskInfo8_18_0Beta5.zip

I'd be happy to test it for you.

Reference: How to show a MFC dialog without stealing focus on the other window https://stackoverflow.com/questions/2122278/how-to-show-a-mfc-dialog-without-stealing-focus-on-the-other-window

hiyohiyo avatar Feb 19 '23 08:02 hiyohiyo

It still happens :(

I've previously tried debugging the program and was able to find the line of code that causes the focus steal. It seems that it executes every time I plug or unplug the computer, even if I don't open the UI even once so that it doesn't steal focus. I created two dumps before the program executes it when plugging/unplugging, the first one without opening the UI and the second one after opening and closing it once.

DiskInfo dumps.zip

ponjadito23 avatar Feb 22 '23 14:02 ponjadito23