-
common dialog controls
How come when I compile this code it doesn't show the Open File dialog? The samething happens when I try to compile other peoples code including the sunlight tutorial. I'm using the free Borland C++ 5.5 compiler. When I compile this same code with the BC 4.5 compiler it shows the Open File dialog.
Code:
/* Win32 File API example */
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "colors.h"
void readFile(void);
void getFile(void);
int main(void)
{
getFile();
readFile();
getchar();
return 0;
}
/*********************************/
void readFile(void)
{
HANDLE hFile;
LPSTR pszText;
DWORD bytesRead, fileSize;
hFile = CreateFile("file.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if(hFile != INVALID_HANDLE_VALUE)
{
fileSize = GetFileSize(hFile,NULL);
pszText = GlobalAlloc(GPTR, fileSize+1);
ReadFile(hFile,pszText,strlen(pszText),&bytesRead,NULL);
pszText[fileSize] = 0; /* add null terminator */
CloseHandle(hFile);
printf("bytesRead: %d\n", bytesRead);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FGRED | BGBLUE);
printf("%s", pszText);
GlobalFree(pszText);
}
}
/*********************************/
void getFile(void)
{
HWND hwnd;
OPENFILENAME ofn;
char szFileName[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "Text Files (*.txt)\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "txt";
if(GetOpenFileName(&ofn))
{
readFile();
}
}
-
I haven't checked your code but if you are using win9x/nt then you have to amend your bcc32.cfg file (bin directory of your install) by including the following two lines:
Code:
-DWINVER=0x0400
-D_WIN32_WINNT=0x0400
This is because bcc5.5 is setup for use on win2k by default which is unfortunately not documented in the sparse help/readme files.
-
Thank you. That solved the problem.