Advertisement Jump to content
Sign in to follow this  
GetWindowRect

OPENFILENAME structure issue.

This topic is 4905 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to figure out how to use the OPENFILENAME structure to open multiple files instead of one. On this link here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/commondialogboxlibrary/aboutcommondialogboxes/openandsaveasdialogboxes.asp it says the explorer-style version of multiple file selections: Explorer-style dialog boxes - The directory and file name strings are NULL separated, with an extra NULL character after the last file name. This format enables the Explorer-style dialog boxes to return long file names that include spaces. When I put the filename into my file variable, it is terminated rather than seperated since it uses NULL to seperate. So instead of getting a full list of files opened, I am getting only the directory (the first item to get put into the field). Is there a way to actually retrieve this string, or since NULL or '\0' terminates a char it will not work with a char*? Here is a full code example of what I have so far, it errors out because the string is null terminated rather than seperated by NULLs.
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		case WM_CREATE:
			HWND hBtn;
			hBtn = CreateWindow("BUTTON", "Open", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 8, 8, 88, 58, hWnd, (HMENU)101, GetModuleHandle(NULL), NULL);
			break;
		case WM_COMMAND:
			if(HIWORD(wParam)==BN_CLICKED)
			{
				if(LOWORD(wParam)==101)
				{
					char file[256];
					file[0] = '\0';
				
					char dir[255];

					int  offset = 0;

					OPENFILENAME ofn;
					ZeroMemory(&ofn, sizeof(ofn));

					ofn.lStructSize = sizeof(OPENFILENAME);
					ofn.Flags = OFN_ALLOWMULTISELECT | OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
					ofn.hwndOwner = hWnd;
					ofn.lpstrFile = (char*)file;
					ofn.lpstrFilter = "Wav Files (*.wav)\0*.wav\0\0";
					ofn.lpstrDefExt = "*.wav";
					ofn.lpstrInitialDir = "c:\\windows\\media\\";
					ofn.nMaxFile = 256;
					ofn.nFilterIndex = 1;
					ofn.lpstrFileTitle = NULL;
					ofn.nMaxFileTitle = 0;

					GetOpenFileName(&ofn);
					
					if(file[0]!='\0')
					{
						offset = ofn.nFileOffset;
						int maxItems = sscanf((const char*)file, (const char*)'\0', &dir);
						int i = 0;
					}
				}
			}
			break;
	}
	return DefWindowProc(hWnd, msg, wParam, lParam);
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow)
{
	WNDCLASS w;
	MSG msg;

	w.cbClsExtra = 0;
	w.cbWndExtra = 0;
	w.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
	w.hCursor = NULL;
	w.hIcon = NULL;
	w.hInstance = hInstance;
	w.lpfnWndProc = WndProc;
	w.lpszClassName = "test";
	w.lpszMenuName = NULL;
	w.style = 0;
	RegisterClass(&w);
	HWND hWnd = CreateWindow("test", "test", WS_OVERLAPPEDWINDOW, 100, 100, 100, 100, NULL, NULL, hInstance, NULL);
	ShowWindow(hWnd, iCmdShow);
	UpdateWindow(hWnd);

	while(GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return 0;
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!