Thread: common dialog controls

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    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();
    	}
    }
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    Thank you. That solved the problem.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Common Dialog boxes GetOpenFileName()
    By A10 in forum Windows Programming
    Replies: 3
    Last Post: 09-02-2008, 08:56 PM
  2. Win32 Common Controls in C++, how do i make and use them?
    By C+noob in forum Windows Programming
    Replies: 6
    Last Post: 01-09-2006, 11:53 AM
  3. Edit controls of a dialog from another dialog...
    By Snake in forum Windows Programming
    Replies: 9
    Last Post: 07-01-2005, 02:18 PM
  4. make Child Dialog not Popup?
    By Zeusbwr in forum Windows Programming
    Replies: 5
    Last Post: 04-08-2005, 02:42 PM
  5. Diff between window controls and dialog controls
    By Garfield in forum Windows Programming
    Replies: 13
    Last Post: 01-18-2002, 05:49 AM