 |
|
 |
This is a really neat framework. Probably the most thorough since I started looking for an MFC Control Panel solution a week ago. It suffers from one problem, though, and EVERY downloadable sample I can find that uses MFC has the SAME problem:
On Windows 2000 once you open the Control Panel with your custom applet .cpl in %SystemRoot%\system32, you cannot erase the .cpl or replace it with a newer version (for testing purposes). Windows 2000 tells me "Access Denied" every time I try to do it and I have to re-boot Windows 2000 in order to replace it.
On Windows XP it is no problem to erase or replace the .cpl file. And yes, I did grab the latest version (v1.25) from your website
Could the system be holding some of the resources open for some reason? Is there a trick with CWinApp that's needed to get the app to really end? I've built non-MFC samples that do not exhibit this behavior.
|
|
|
|
 |
|
 |
This is nothing really to do with the framework but with how Windows 2000 caches handles to running control panel applets. It is OS behaviour and will affect control panel applets developed in any framework / compiler!.
Here's a couple of things to do to avoid having to reboot.
1. Close the applet and also close the control panel applet before you try to delete the cpl file.
2. Use applet registration instead of copying to the windows system directory when testing / developing, Win2k does not seem to have as much lock problems when you do this.
As you have observed, XP seems to have resolved this "behaviour".
|
|
|
|
 |
|
 |
Thanks for the quick reply PJ. Of course, (1.) was done each time to no avail. I'll check out (2.) some more. This problem does not happen with non-MFC control panel applets (that don't use registration) and that's driving me crazy.
Using 'regsvr32' and 'regsvr32 /u' on the .cpl works and allows me to delete the .cpl file when run from the build output directory on Win2K (SP4). The only problem is that the icon that appears in the control panel is the generic Windows icon you see when Windows doesn't recognize the file type. When I put the .cpl in the system32 directory the icon is displayed correctly (but then I can't delete the .cpl file, etc.) I guess this is acceptable since the CP applet I'm writing will be used primarily on Windows XP. The only reason I've been running it on Win2K as well is because that's my development machine and it's quicker to hammer out the small problems there than copying it to the XP machine every time I change something. As long as the applet runs on Win2K, and it does, it doesn't really matter what icon is shown.
One final thing re. 123 RT_MANIFEST MOVEABLE PURE "res\SomeName.cpl.manifest"... You say this is for the new XP Visual styles. Where is this generated?
Thanks again for this great code.
|
|
|
|
 |
|
 |
Open control panel applet and double click on icon1 "demo applet 1", icon 2 "demo applet 2". Both the applications are opened.
Again open control panel applet,
-double click on "demo applet 2", the pervious running instance is bring to forground and focus is set.
-double click on "demo applet 1", focus is removed from control panel but the previous instance is not set to focus ??
Why is this ?
How do i get it set to foreground when double clicked on its applet ?
|
|
|
|
 |
|
 |
First thing to do is make sure you have the latest version from my web site as there have been a lot of updates since I posted this article to codeproject.
|
|
|
|
 |
|
 |
I used the latest version from your site, it has the same behaviour.
"Applet 1" doesn't popup where as "Applet 2" works perfectly fine.
I am looking into it, will post it here if could crack it.
Regards,
Vijay Chegu
|
|
|
|
 |
|
 |
OK, got it.
The problem was that when we get double click notification, system passes us the HWND. We need to create a dialog box with this hwnd as the parent. When this is done, our dialog box pops up if an instance is already existing.
Infact u have added a comment also at the place that as CDialog::m_pParentWnd is protected member variable, you are not using it.
I made a few changes and it works.
Unfortunately these changes will break the polymorphism u have used.
here is the method i changed.
ofcourse we need to do a
#include "DemoDlg.h" in cpl_pp.cpp and
change the constructor to
CDemoDlg(CWnd *pParent = NULL);
in demodlg.h and demodlg.cpp
LRESULT CControlPanelApplet::OnRun(CWnd* pParentWnd)
{
LRESULT lResult = 1; //Assume failure
if (_tcscmp(m_pUIClass->m_lpszClassName, _T("CDemoDlg")) == 0 ){
CDialog* pDialog = new CDemoDlg(pParentWnd);
if (pDialog) {
pDialog->DoModal();
delete pDialog;
}
lResult = 0;
} else {
CWnd *pWnd = (CWnd*) m_pUIClass->CreateObject();
if (pWnd) {
lResult = 0; //Success;
if (pWnd->IsKindOf(RUNTIME_CLASS(CPropertySheet)))
{
CPropertySheet* pSheet = (CPropertySheet*) pWnd;
pSheet->Construct(m_sName, pParentWnd, m_nPageNumber);
pSheet->DoModal();
}
}
//Don't forget to tidy up the memory used
delete pWnd;
}
return lResult;
}
Excuse me if u dont like my tinkering with ur code.
|
|
|
|
 |
|
 |
Just to let you know that I have released a update on my web site (www.naughter.com) which addresses this issue without the need to break the polymorphic behaviour of the OnRun function
|
|
|
|
 |
|
 |
Thanx for the credit u have given on ur page .
http://www.naughter.com/cpl_pp.html
--->
V1.23 (4 June 2003)
Creation of CDialog based applets now correctly observe the parent window as passed into it. Thanks to Vijay Chegu for suggesting the fix for this.
<----
I am elated
-Vijay Chegu
|
|
|
|
 |
|
 |
1. To make CPlApplet STATIC CALLBACK member of app class.
2. To add applet registartion :
#define IDS_REG_KEY_CPL _T("Software\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls")
BOOL CCplApp::RegisterCplApplet( BOOL bRegister ,
BOOL bForAllUsers )
{
BOOL bRet = FALSE;
TCHAR szAppPath[ _MAX_PATH ];
VERIFY( ::GetModuleFileName( m_hInstance, szAppPath, _MAX_FNAME ) );
OSVERSIONINFO osvi;
::ZeroMemory( &osvi, sizeof( OSVERSIONINFO ) );
osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
::GetVersionEx( &osvi );
if( ( osvi.dwPlatformId == VER_PLATFORM_WIN32_NT &&
osvi.dwMajorVersion >= 5 ) ||
( osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS &&
( osvi.dwMinorVersion >= 90 || osvi.dwMajorVersion > 4 ) ) )
{
CRegKey cReg;
LONG nRet = -1;
HKEY hKey = ( bForAllUsers ? HKEY_LOCAL_MACHINE :
HKEY_CURRENT_USER );
if( cReg.Create( hKey, IDS_REG_KEY_CPL ) == ERROR_SUCCESS )
{
if( bRegister )
nRet = cReg.SetStringValue( m_pszAppName, szAppPath );
else
nRet = cReg.DeleteValue( m_pszAppName );
cReg.Close();
}
bRet = ( nRet == ERROR_SUCCESS );
}
else
{
bRet = ::WritePrivateProfileString( _T( "MMCPL" ),
(bRegister ? m_pszAppName : NULL),
szAppPath, _T( "control.ini" ) );
}
return bRet;
}
#define __ARMEN_H__
|
|
|
|
 |
|
 |
Just to let you know that I have produced an update on my web site at www.naughter.com which is based on this suggestion
|
|
|
|
 |
|
|
 |
|
 |
Great library, but somehow after I installed it I cant remove it.
How to remove? Thanks.
|
|
|
|
 |
|
 |
return 1 in CControlPanelApplet::OnStop()
|
|
|
|
 |
|
 |
Any idea why the icon stays the same after I change it in Visual Studio? For example, I changed the MFC 2 icon for the second applet to a yellow circle. When I copy the .cpl to the winnt\system32 directory, and run settings->Control Panel, it still shows the MFC 2 icon. The icon does not exist in my project anymore, but it still shows it in the Control Panel window!
Also, I tried adding a few pages to the applet, and the page names are not showing correctly. The page names for pages 3 through 6 are the same as page 3. Each page has a unique name defined by using the resource editor in Visual Studio.
|
|
|
|
 |
|
 |
Always return
pInfo->idIcon = m_nResourceID;
in LRESULT CControlPanelApplet::OnInquire(CPLINFO* pInfo)
|
|
|
|
 |
|
 |
This has to do with the OS caching the info for performance reasons. Best thing to do is get yourself a copy of TweakUI which includes an option to refresh the Windows Icon cache. This will fix this problem / issue.
|
|
|
|
 |