﻿
import core.sys.windows.windows;

int main() {
	HINSTANCE inst = GetModuleHandleA(null);

	WNDCLASSA wc;
	wc.hInstance = inst;
	wc.lpfnWndProc = &WndProc;
	wc.lpszClassName = "TheClass";
	RegisterClassA(&wc);

	HWND wnd = CreateWindowExA(0, "TheClass", "Test",
		WS_OVERLAPPEDWINDOW, -1, -1, -1, -1, null, null, inst, null);

	ShowWindow(wnd, SW_SHOW);

	MSG msg;
	while(GetMessageA(&msg, null, 0, 0)) {
		TranslateMessage(&msg);
		DispatchMessageA(&msg);
	}

	return msg.wParam;
}

extern(Windows)
LRESULT WndProc(HWND wnd, uint msg, WPARAM w, LPARAM l) {
	switch(msg) {
	case WM_CREATE:
		char[MAX_PATH] fileBuf = void;
		fileBuf[0] = '\0';

		OPENFILENAMEA ofn;
		ofn.lStructSize = OPENFILENAMEA.sizeof;
		ofn.hwndOwner = wnd;
		ofn.hInstance = GetModuleHandleA(null);
		ofn.lpstrFilter = "*.*";
		ofn.lpstrFile = fileBuf.ptr;
		ofn.nMaxFile = MAX_PATH;

		GetOpenFileNameA(&ofn);

		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProcA(wnd, msg, w, l);
	}

	return 0;
}
