Home > OS >  Win32 program how to obtain only digital catalogue
Win32 program how to obtain only digital catalogue

Time:04-17

Platform: Windows
Language: C
IDE: Visual Studio 2019 Community

I'm doing a reading and writing Windows configuration file (*. Ini) small programs, the configuration file directory is pure Numbers, not the pure digital directory without configuration file, the program used in the FindFirstFile and FindNextFile enumerated by a given directory, and then get a given directory contains only numeric characters subdirectory name, in a drop-down list box (combo box, ComboBox),
The following is the code:
 LRESULT CALLBACK WndProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM) 
{
HDC HDC.
PAINTSTRUCT ps;
The static HWND hComboBox;

The switch (the message)
{
Case WM_CREATE message handler:
HComboBox=CreateWindow (WC_COMBOBOX,
The TEXT (" "),
CBS_DROPDOWN | WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_SORT,
In 90, 23, 130, 400,
HWND, NULL, NULL, NULL);

The static TCHAR Folder [MAX_PATH];
WIN32_FIND_DATA FFD.
HANDLE hFind=INVALID_HANDLE_VALUE;
DWORD dwError=0;
Retrieves the hr=SHGetFolderPathW (CSIDL_MYDOCUMENTS 0, 0, 0, Folder).
If (SUCCEEDED (hr))
{
StringCchCat (Folder, MAX_PATH, TEXT (" \ \ work "));

If (DirectoryExists (Folder))
{
StringCchCat (Folder, MAX_PATH, TEXT (" \ \ * "));
HFind=FindFirstFile (Folder, & amp; FFD);
}
The else
{
MessageBox (HWND, TEXT (" directory does not exist. "), TEXT (" error "), MB_ICONERROR);
}

If (INVALID_HANDLE_VALUE=hFind https://bbs.csdn.net/topics/=
{
return 0;
}

Do
{
If (FFD) cFileName [0]=='. ') continue;//to skip the current directory ". ", the higher level directory ".. "And hidden directory

If (FFD) dwFileAttributes & amp; FILE_ATTRIBUTE_DIRECTORY)//as long as the directory, don't file
{
BOOL onlyDigit=TRUE;

for (int i=0; I & lt; Sizeof (FFD. CFileName); I++)
{
If (FFD) cFileName [I] <'0' | | FFD. CFileName [I] & gt; '9')
{
OnlyDigit=FALSE;
}
}

If (onlyDigit)
{
//will be only number inside the directory name in the drop-down list box
SendMessage (hComboBox, (UINT) CB_ADDSTRING, (WPARAM) 0, (LPARAM) FFD. CFileName);
}
}
}
While (FindNextFile (hFind, & amp; FFD)!=0);

FindClose (hFind);
}
The else
{
MessageBox (HWND, TEXT (" Failed to get the special folder. "), TEXT (" ERROR "), MB_ICONERROR);
}
[other code snippet]


In the above the do... Inside the while loop, first using the
 if (FFD) cFileName [0]=='. ') continue; 
to filter out the current directory. "", on one level", "and hide the directory, and then use the
 if (FFD) cFileName [I] <'0' | | FFD. CFileName [I] & gt; '9') 
traverse the directory name of each character, if contains non-numeric characters, will skip the directory name, dealing with a directory name,

However, after the program is running, ComboBox inside what also have no, is empty,

Don't know where is the code above is wrong, or there is a better way to judge whether directory name pure digital, also please tell bosses,

Before and WinForm to do this small program in C #, now change to C and Win32 GDI, suddenly feel face in C # Windows directory, file, string handling more relaxed many, but under the Windows 10 WinForm can't compatible with Windows 7 (need to install the corresponding. NetFramework), but also to call C # inside GetPrivateProfileString the Windows API function to read and write ini files, so use C to write Win32,

String processing problems now, for a while do not know what to get, if the string is in pure C language string handling ok (like the above code should be can normal operation), but now is in the Windows environment, save the children...

CodePudding user response:

Program design problem of a class, the development of language should not be sent to the corresponding section?
I think, in the first Ln59 SendMessage () up and down the breakpoint, see if it is triggered, to identify the problems in finding judgment, or a list control; And then finally determine the problem again,
  • Related