Plain WinAPI?
#include <windows.h>
#include <stdio.h> // needed for fopen
#pragma comment(linker, "comdlg32.lib") // needed for GetOpenFileName
#pragma comment(linker, "gdi32.lib") // needed for GetStockObject
#pragma warn(disable:2216) // retval never used
#pragma warn(disable:2118) // parameter .. is not referenced
#define winX 200 // main window x, y, width and height
#define winY 200
#define winW 700
#define winH 700
HWND hEdit; // global handle to the edit control
HINSTANCE hInst; // global instance handle
void ReadFile2EditControl(char* filename) { // does what its name says
FILE *ofp = fopen(filename, "rb");
if (ofp) {
fseek(ofp, 0, SEEK_END); // GetFileSize() won't work, so let's do it the archaic C way
int fLen=ftell(ofp); // position at end equals length of file
fseek(ofp, 0, SEEK_SET); // go back to start
PSTR pstrBuffer=malloc(fLen+1); // buffer includes a zero delimiter
if (pstrBuffer) {
fread (pstrBuffer, 1, fLen, ofp); // read content into buffer
pstrBuffer[fLen] = '\0'; // set the delimiter explicitly
SetWindowText (hEdit, pstrBuffer) ; // put text into the edit control
free (pstrBuffer) ;
}
fclose (ofp) ;
}
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg) {
case WM_CREATE:
{
int htMenu=0;
#define mOpen 101
#define mSave 102
#define hasmenu 1 // 0 = no menu
#if hasmenu
HMENU hMenu, hSubMenu;
hMenu=CreateMenu(); // create the main menu
hSubMenu=CreateMenu(); // create a sub-menu
AppendMenu(hMenu, MF_POPUP, (int)hSubMenu, "&File"); // add it to the main menu
AppendMenu(hSubMenu, MF_STRING, mOpen, "&Open"); // and add
AppendMenu(hSubMenu, MF_STRING, mSave, "&Save"); // two items
SetMenu(hwnd, hMenu); // attach menu to main window
htMenu=GetSystemMetrics(SM_CYMENU);
#endif
hEdit=CreateWindowEx(WS_EX_CLIENTEDGE, "edit", NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | ES_MULTILINE,
2, 1, winW-12, winH-htMenu-33, hwnd, (HMENU)103, hInst, NULL); // we have added an edit control
SendMessage(hEdit, EM_LIMITTEXT, 0, 0); // no limit
SetFocus(hEdit); // make sure you can start typing right away
SendMessage(hEdit, WM_SETFONT, (int)GetStockObject(ANSI_FIXED_FONT), 0); // SYSTEM_FIXED_FONT is bold and larger
}
break;
case WM_COMMAND:
if ((short)wParam==mOpen)
{
char fileName[MAX_PATH]="\x0000";
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter ="Sources and Headers\0*.c;*.h;*.as?\0\0";
ofn.lpstrFile = fileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if (GetOpenFileName(&ofn)) ReadFile2EditControl(fileName);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
MSG msg;
WNDCLASS wc;
HWND hwnd;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.lpszClassName = "MyClass";
wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE+1);
wc.lpszMenuName = NULL;
wc.lpfnWndProc = WndProc;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
RegisterClass(&wc);
hInst = hInstance;
hwnd = CreateWindow(wc.lpszClassName, "Hello World",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
winX, winY, winW, winH,
NULL, NULL, hInstance, NULL);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}