what im trying to is make it when the person clicks the button to open a file it brings up that little window that has directory listings and what not and lets them browse arround looking for the file they want to open.
what im trying to is make it when the person clicks the button to open a file it brings up that little window that has directory listings and what not and lets them browse arround looking for the file they want to open.
Look up the OPENFILENAME struct on MSDN..
Set the members that you need (lStructSize, hInstance,lpstrFilter, lpstrFile, nMaxFile, Flags....etc)
The use GetOpenFileName()
On return of that function, the structure you sent will contain the info you need to open the file
I believe i have answered this question before:
Originally posted by Okiesmokie
heres a function i made that i used in my text-editor that brings up the open file dialog box, and lets the use pick a file to open, then loads it to the edit box
Code:void FileOpen(HWND hwnd, HWND hEdit) { #define MAX_PATHSIZE 256 OPENFILENAME ofn; char FileName[MAX_PATHSIZE] = ""; HANDLE hFile; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; ofn.lpstrFile = FileName; ofn.nMaxFile = MAX_PATHSIZE; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "txt"; if(GetOpenFileName(&ofn)) { } hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if(hFile != INVALID_HANDLE_VALUE) { DWORD dwFileSize; dwFileSize = GetFileSize(hFile, NULL); if(dwFileSize != 0xFFFFFFFF) { LPSTR FileText; SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Opening..."); FileText = (LPSTR)GlobalAlloc(GPTR, dwFileSize + 1); if(FileText != NULL) { DWORD dwRead; if(ReadFile(hFile, FileText, dwFileSize, &dwRead, NULL)) { FileText[dwFileSize] = 0; // Set the NULL terminator SetWindowText(hEdit, FileText); } GlobalFree(FileText); } } CloseHandle(hFile); } }
"There are three kinds of people in the world...
Those that can count and those that can't."