Visual C++ :: CFileDialog - Overriding Default Behavior Of Selecting Initial Directory
Oct 31, 2013
There was an "impovement" since Windows 7 in algorithm for selecting the initial directory, which is described here OPENFILENAME structure. Briefly:
Windows 7:
If lpstrInitialDir has the same value as was passed the first time the application used an Open or Save As dialog box, the path most recently selected by the user is used as the initial directory. Otherwise, if lpstrFile contains a path, that path is the initial directory.
Otherwise, if lpstrInitialDir is not NULL, it specifies the initial directory. If lpstrInitialDir is NULL and the current directory contains any files of the specified filter types, the initial directory is the current directory. Otherwise, the initial directory is the personal files directory of the current user. Otherwise, the initial directory is the Desktop folder.
The problem that this behavior is not what users of my program expect. Another constraint is that I need to use old CFileDialog dialog, not Common File Dialogs. I've tried to use advises described on StackOverflow and on MSDN. This solution by EllisMiller works perfectly:
Specifying a full path (including filename) in lpstrFile. The filename of course shows up in the filename box which is annoying. I ended up using a filename of "." and adding a bit of code to clear the filename combobox once the dialog is open.
BUT I can't figure how to clear the filename combobox. I've tried to add hook procedure, enumerate windows and clear text, but this didn't work for me. So, my question is: how can I clear text in the filename combobox of CFileDialog?
I have subclassed CFileDialog. I need to select both file and folder on certain case only. Suppose I have a folder selected and it is containing desired file type. Then in such situation, On clicking open button will not open the selected folder. But just close the CFileDialog with IDOK.
For doing this I need to provide my own implementation for Open button handler. I am not getting how I can do this.
I have built the wave tool and now am trying to run my source code through it. But it just doesn't want to find the include directory. I just don't understand. Here's my command:
Perhaps it how I built it since there is no info on how to do this? I just ran ../b2.exe from the boost_1_53_0/tools directory.
I'm running CYGWIN_NT-6.1-WOW64 TARDIS 1.7.18(0.263/5/3) 2013-04-19 10:39 i686 Cygwin with a g++ version of 4.5.3. g++ has no problem finding the default include directory (I don't have to specify the -I switch). The -I switch doesn't seem to work for any of the other include directories that I wan to use either, but I want this cleared up before I get into that since it might be related.
When I create a list control I can assign an image list to it with the ListView_SetImageList().
By default, when just created there is no image list assigned as can be checked with ListView_GetImageList().
Now, what should happen when I do following call:
Create list control. Create an image list Get the current image list Assign an image list to list control Display some items Assign an old image list to list control.
Does strings on the list control should be indented?
I haven't seen this before but on Windows 7 Home Professional and VC 2012 in one particular app, a CFileDialog displays only the rightmost 11 characters plus the extension of the default file name. The rest of the name is there and you can scroll left in the file name edit to display it all, but initially the text is shifted left so it doesn't all display.
In my attempt to capture multiple files using CFileDialog I discovered that there is a limit on the number of characters in the file name buffer. [URL]
I have used this code to get the file names and it works fine up to the point where the buffer is full. NB: m_vcsPathnames and m_vcsFilenames are std::vector<CString> types.
Code: // get a list of the files to process wchar_t szFilters[]= _T("All Files (*.*)|*.*||"); // Create an Open dialog; the default file name extension "*.*" CFileDialog fileDlg(TRUE, _T(""), _T("*.*"), OFN_FILEMUSTEXIST| OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, szFilters, this); m_vcsPathnames.resize(0);
[code]....
Is there any possible work around for this limitation, other than completely writing my own CFileDialogExx class ?
I have an assignment which includes overriding the prefix and postfix operators, and my teacher has provided what the output from the program should be. I've written the code and it's nearly perfect, except for one tiny error I can't seem to get right.
This is (most of) the code from the header--I left out a few of the parts that aren't relevant to my question:
Code: using namespace std; #include<string> #include<iostream> class NumDays { private: int hours;
[Code] ....
The two problem lines are supposed to be outputting 12 and 1.5, respectively, but are instead showing 13 and 1.625. I know that hours is being changed to 12 at the end of the overriden prefix operation in the line above them, so I don't understand why it returns to 13 again. What I need to change?
I create two memory manager called CMemManager1 and CMemMangaer2, using different algorithms to allocate buffer. Now I want to control which memory manager to be used, when calling new.
I try to add a parameter bUseWhichMemManager to the constructor, but in overrided new function, there are no way to access the parameter. Is there a way to pass more parameters to new operator, such as:
How would I go about selecting a subitem in a listview control with just pure Win32 API? I know it's possible with MFC... but I can't use MFC for this project. Right now, when you click on a subitem , it selects only the first column of the row . I used the following by referring internet. But its not working.
HTML Code: iSlected=SendMessage(hList,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); ListView_SetItemState(hList,iSlected,LVIS_FOCUSED|LVIS_SELECTED,0x000F);
I want to select 1 element from each vector without duplication of any combinations. Essentially only when all combinations are done with 1st element in first vector ,only then it should move to next element in first vector.
Say i have elements :[123] [456] [789]
my combinations should be like 147 148 149 157 158 159 167 168 169 247....
Also, I cant have any repetitions and only after all combinations of 1 are done only then the loop has to move to next combination ie 247 combination and so on.
I tried NCK (n choose k) command but it gave me random combinations. How should i go about it with using minimal for loops?
I am trying to develop a GUI using MFC, but I am having trouble using CFiledialog to save a file. The problem is, the file is not getting saved to the folder when I use the CFiledialog. Below is the code I am using.
I'm very new to MFC & VisualC++. I'm using MSVS2010 Pro. I am trying to write/debug a simple form that saves and restores the content of some edit controls. It seems to work as expected, except the file saves only to the Project Folder, regardless of where I browse and select to save the file.
Code: void CMFC_FileDialogDlg::OnBnClickedbtnsave() { this->UpdateData(); CFile f; //Kinda Correct, Works but still saves in Project Folder BOOL b_OpenFileDialog = FALSE;//this doesn't act as bool in CFileDialog?
[Code] ....
My only experience is a little simple VB programming in Excel, so any specific examples??? Also, rules seem to change from version to version? I have to "update" a number of undocumented programs.
I have a WordRecord that contains a LinkedList (both my doing). I have rigorously tested my LinkedList class, and know that it works (heck, I used it in the last project I had!). The problem is that undefined behaviour seems to happen when using the WordRecord, which has a std::string and a LinkedList<unsigned>. (The problem happens with the LinkedList.)
Here is the code:
main.cpp #include <iostream> #include "BinaryTreeNode.h" // here for test purposes #include "LexicographicTree.h" #include "LinkedList.h"//also for test purposes #include "OutputStream.h" #include "WordRecord.h" using namespace std; int main() { // setup the OutputStream to print to "test.txt" OutputStream stream("test.txt"); // create a sampleWordRecord (make it have the word "I" on line 1)
[code]....
One of the requirements for the project is that it must compile on Unix server (I am using Windows, and have tested it in both environments.) I get a core-dump in the Unix environment. On the other hand, the output on-screen in the Windows environment looks right. However, when I open up the text file, I get the following
Sample word record:
WordLines I{14} /* I have no what is happening to sampleWordRecord's LinkedList; I am not trying to modify it, except for where I created the sampleWordRecord! */
I have been using the code below to extract the current user directory in order to read and write to certain files, presumeably independent of whether or not the user has administrative privileges. This has been necessitated in Win 7 because applications installed in the customary C:/Program Files(x86)/ are not allowed full access to files in the installed app root directory. This was working just fine until just this week when suddenly, for the first time, I found that the user directory retrieved was different when the app was run without administrative privileges in 'Start without debugging' configuration, both in Debug and Release configuration. Note that I have tested the identical app on Win2K and Vista and in neither case is it a problem on those OS machines. More mysterious is the fact that this ONLY happens on Win7 (VS2010 Ultimate) when run in the IDE. Run from the windows explorer double click, the app runs just fine in release and debug mode and monitoring the debug version using DbgView indicates that the expected 'Roaming' User directory is retrieved.
For example:
- without debugging (both Debug and Release configuration) the code below produces:
Either this has been the situation from the outset and I just never noticed it (hard to imagine as I've been on this project for 6 months with 50+ builds), a recent Windows update has changed things, a bug, or I'm just plain stupid (not hard to imagine at all).
From a practical standpoint, if this is the way things are to be, my installer will need to install necessary files in both user directories and the app will need to access both depending upon user privileges.
Code: /// This routine retrieves the process's environment block /// using GetEnvironmentStrings, parses that block pointed to /// by the generic international text pointer LPTCH, and returns /// the requested string lpszVarStr as a string. /// Note that the block lpvEnv environment variable substrings /// are separated by NULL byte, and the block is terminated by a NULL byte. /// The header files <windows.h>, <tchar.h>, <stdio.h>, <string>, and /// <iostream> need to be included.
If I don't assign the icon to my executable file (f.e. it's a DOS application), or I have some unknown extension in the file, Windows Explorer assigns the icon to this file.
Is there a way to somehow get this icon? Either from the registry or by any other means.
How to create a directory / folder.( to browse/save my files to a directory.) how to specify the path?
I googled , but i cant able to find appropriate as it is showing all in the C#, C++ , objective C. But not in C.
Here i am writing a sample program to my POS device .problem here is it is not taking mkdir(direct/dir.h header file)function. Any alternative is there to make a directory?
This directory "H:C" does exist, if I comment out the GetDiskFreeSpaceExA line, the program doesn't crash, but it leads to some peculiar results (some uninitialized and random value, but at least it doesn't crash)
I have a DLL developed using pure VC++ (all unmanaged code that doesn't use .NET framework). This DLL will be deployed in different client PCs within a network and will act like an agent.
Now I have establish a communication between this DLL and a WCF web service, that will be deployed in a server PC. The Service will first get a list of PCs either name or IP Address within a network using LDAP (Active Directory) and once, we get the PCs, I have to establish a communication between the web service and the agents that reside in these client PCs,
I'm overriding OnNcPaint to do my own caption painting (in a dialog box). If I call "Default" before I do my painting, the default caption and borders remain (as if I'm not painting at all). If I comment out my call to "Default", my caption looks great, but I get no menu bar (I have a menu on the dialog). If I call "DrawMenu" before or after painting, the dialog is all screwed up (and there is no painting in the nonclient area).
I needed to change Default Text attributes (font and color) . So I wrote following code , UnicodeTextOut function. I called this function once in each 55ms to update the display screen. but I observed that my Screen used to become grey like a crash after sometime . If I use Minimize an Maximize window , the screen was restoring back for some time.
When I thought over the code , I got my mistake that CreateFont initialization should be done once in the program and probably outside the function.
Then I shifted the line hFontUnicode = CreateFont(16, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, _T("Aerial")); in my screen class constructor and made hFontUnicode global .
This solved my problem as expected. Why a system crash after certain no of CreateFont calls ?
However, if one uses this code over and over, one quickly becomes tired of threading one's way all the way from root directory C:. There is undoubtedly some way to designate a starting directory. The most obvious candidate to set such a target is the:
Code: bi.pidlRoot = NULL;
But attempting to set bi.pidlRoot to a CString (directory address) errors because 'no suiitable conversion from CString to LPCITEMIDLIST exists'
How can I set the code to open at a designated address in the directory tree?
I have a semi-working program for doing this task. Here it is:
char c = 0, flag = 0, c_ = 0; while ((c = getchar()) != '.') { if ((c >= '0'&& c <= '9') && (c_ <'0' || c_ >'9')) { if (c == '0') flag = 1; } else putchar(c);
[code].....
But when I enter "000000a123000500" the program returns "0a23000500" instead of "0a123000500". Please change my program to have it do what it need to or give me some hint. Using getchar and putchar only! No massives and pointers!
I am making a product and in which i use a timer. I want when the product is being start the timer will run and when the product is off the timer will stop. If i again start the product the timer will start from its previous value.
I have problem that the timer start from its initial when i start my product.