A month or two back, I had to write a launcher app that would allow/disallow the running of select installers based on various conditions and config files. Since this would run prior to any of the MSIs, and thus couldn’t assume the presence of any dependencies like .NET or the VC++ runtime, I wrote it [...]
Entries Tagged as 'Win32/MFC'
VC++ 2008 with MFC and GDI+ dependency
June 30th, 2010 · 1 Comment
Tags: C++ · VC++ Orcas · Win32/MFC
Article : Deploying MFC applications via ClickOnce
January 13th, 2008 · 3 Comments
Recently I had the task of deploying an MFC application suite along with its dependencies via ClickOnce. Visual Studio does not directly support deployment of MFC applications (even if it’s compiled with /clr) and one of the suggested solutions I found on the web was to have a stub C# executable which would launch the [...]
Tags: C++ · CLR/.NET BCL · Win32/MFC
Creating an unmovable dialog
September 4th, 2007 · 4 Comments
Someone recently asked in the MSDN forums how to create an unmovable dialog using MFC. The simplest way to do this is to remove SC_MOVE from the dialog’s system menu. This can be easily done in OnInitDialog :- CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { pSysMenu->RemoveMenu(SC_MOVE, MF_BYCOMMAND); } Obviously, you need to think [...]
Tags: Win32/MFC
New article : Drag/Drop a non-existent file into Windows Explorer
September 18th, 2006 · 7 Comments
Here’s an article I wrote for The Code Project that shows how you can drag and drop a virtual file (one that does not physically exist on disk) from your app into Windows Explorer. It’s useful for scenarios like extracting a file from an archive or where the source file is on a remote machine. [...]
Tags: Win32/MFC
The SHCreateDirectoryEx API function
March 10th, 2006 · 3 Comments
Very frequently in the forums, someone posts a question asking for a function that will create a full directory path for them. For example, they may want to create c:\a\b\c\d\e\f with one call, where the intermediate folders may not exist. The answer, if you are on Win 2000 or later, is to use the SHCreateDirectoryEx [...]
Tags: Win32/MFC
Selecting a default folder with SHBrowseForFolder
February 17th, 2006 · 5 Comments
Today, there was an article posted on the Code Project website that showed how to use SHBrowseForFolder, and there was a question from a reader in the forum, asking how a default folder can be specified. This is pretty easy to do, and all you need to do is to set the BIF_VALIDATE flag, specify [...]
Tags: Win32/MFC
Get the Office 2003 style menus/toolbars in your MFC apps using Windows Forms
February 15th, 2006 · 4 Comments
This is my latest Code Project article, and it shows you how to use the Windows Forms 2.0 MenuStrip and ToolStrip controls in your MFC applications to give them an Office 2003 look and feel. These Forms controls are pretty well written, and if you change the XP theme/style, they change accordingly, just like Word [...]
Tags: C++/CLI · VC++ 2005 · Win32/MFC
Is MFC dead? Does MFC have a future?
July 28th, 2005 · 40 Comments
“Is MFC dead?” is arguably the most common question appearing on the VC++ newsgroups along with variants like “Does MFC have a future?” and “Can MFC applications run on Longhorn?”. A short answer would be, “No, MFC is not dead, and you can continue to develop applications using MFC and be assured that they will [...]
The PathCompactPath function
July 20th, 2005 · 4 Comments
PathCompactPath is a not-so-well-known function that truncates a file path to fit within a specific pixel-width and uses ellipses to show that it’s been truncated. Here’s some sample code that shows how you can use it :- #ifndef UNICODE #define _tcout cout #else #define _tcout wcout #endif void TruncateShow(LPCTSTR buff, UINT pixels) { TCHAR tmpbuff[MAX_PATH*4] [...]
Tags: Win32/MFC
Locking splitter windows
July 12th, 2005 · 2 Comments
Earlier today, someone asked on the vc.mfc NG how he can lock his splitter windows. I replied to him asking him to handle WM_SETCURSOR, WM_LBUTTONDOWN and WM_LBUTTONUP in a CSplitterWnd derived class and to call the base class implementation only if locking is disabled. Later, I decided to try it out and found that there [...]
Tags: Win32/MFC
There’s nothing wrong in posting messages!
July 1st, 2005 · 2 Comments
Mike Dunn said that to me a few minutes ago and I thought that, taken out of perspective, that sentence is pretty funny Well, for those who didn’t get it yet, we weren’t talking about posting messages on a bulletin board or Instant Messenger messages; we were talking about posting Win32 messages! It happened this [...]
Tags: Win32/MFC
GetProcessImageFileName/QueryDosDevice trivia
June 20th, 2005 · 10 Comments
If you’ve ever used GetProcessImageFileName, you’d have been a little stunned to see filenames like \Device\HarddiskVolume1\Program Files\Abc.exe – though when you think of it, it’s not all that surprising, because these are the real paths as far as the OS is concerned, all that kiddy-type C-drive, D-drive usage is mere eye-candy for us non-kernel-programmer types. [...]
Tags: Win32/MFC
GetProcAddress in Unicode builds
June 14th, 2005 · 6 Comments
If you have code like this :- GetProcAddress(hModComCtl,_T(“DllGetVersion”)); It won’t compile when UNICODE is defined. This is so because there are no separate GetProcAddressW/GetProcAddressA functions. The second argument to GetProcAddress is an LPCSTR (const char*), because exported names in Win32 modules are stored as ANSI strings. The right way to write the above line would [...]
Tags: Win32/MFC
IsAppThemed and IsThemeActive just don’t work
June 2nd, 2005 · 3 Comments
I was most annoyed when I found that IsAppThemed and IsThemeActive do not work as expected. Instead of returning the themed status of the running application, both functions return the themed status of the system (pretty much useless for my specific requirement). After some googling, I found a posting from a fellow-MVP, Jeff Partch, who [...]
Tags: Win32/MFC
Retrieving network adapter info using the IP Helper API
May 30th, 2005 · 5 Comments
Here’s a code snippet that enumerates the currently enabled network adapters and shows some info for each adapter :- PIP_ADAPTER_INFO pAdapterInfo = NULL; ULONG OutBufLen = 0; //Get the required size of the buffer if( GetAdaptersInfo(NULL, &OutBufLen) == ERROR_BUFFER_OVERFLOW ) { int divisor = sizeof IP_ADAPTER_INFO; /*** Uncomment for VC++ 2005 Beta 2 if( sizeof [...]
Tags: Win32/MFC
Accessing version information is so damn hard
May 25th, 2005 · 3 Comments
I am unable to fathom why there is no straightforward API to access version information from the running process. To retrieve any kind of version information, you need to call 3 APIs – GetFileVersionInfoSize, GetFileVersionInfo and VerQueryValue. Actually make that 4 APIs, since you also need to call GetModuleFileName to get the full path of [...]
Tags: Win32/MFC
Send mail without specifying an SMTP server
April 25th, 2005 · 10 Comments
Frequently, this question pops up in newsgroups and forums where people ask how they can detect the user’s SMTP server (usually to send a mail from the app without using MAPI). I always reply with my solution of querying the MX record for the target domain and then SMTP-chatting to that server directly – it’s [...]
/Wp64 and casting pointers to DWORDs
February 25th, 2005 · 4 Comments
Most of my coding has been on 32 bit Windows and there has been this subconscious assumption I’ve always made that I could safely cast any pointer to a DWORD. I gotta change that now I guess though it’s tough to stop assuming my subconscious assumptions cause they are – well, subconscious assumptions (bad joke [...]
Tags: Win32/MFC
Errata – RCW issue when returning a BSTR
January 26th, 2005 · 3 Comments
I hate being proved wrong as much as the next guy, but I owe it to my blog readers to correct a confusion that I’ve put into their minds due to a short sighted blog entry I made several months ago. For those of you who remember, I made a blog entry titled RCW issue [...]
Tags: CLR/.NET BCL · Win32/MFC
Using MessageBoxIndirect to show message boxes with custom icons
January 11th, 2005 · 5 Comments
MessageBoxIndirect is a little known API function defined in user32.dll, that lets you customize message boxes just that little bit more (and it’s highly probable that MessageBox itself uses MessageBoxIndirect internally). Here’s some sample code that shows how you can show a message box with a custom icon :- MSGBOXPARAMS params = {0}; params.cbSize = [...]
Tags: Win32/MFC