ファイル名:hinagata.h
#define IDM_OPEN 101
#define IDM_SAVE 102
#define IDM_EXIT 103
#define IDM_HELP 104
#define IDM_ABOUT 105
ファイル名:hinagata.c
#pragma resource "hinagata.res"
#define STRICT
char buf[512];
#include <windows.h>
#include <commdlg.h>
#include <stdio.h>
#include <string.h>
#include "hinagata.h"
#define APPNAME "HINAGATA"
#ifdef WIN32
#define MAXPATH 260
#define MAXNAME 256
#else
#define MAXPATH 80
#define MAXNAME 13
#endif
WORD Version; BOOL NT;
HWND hwndApp;
HINSTANCE hInstApp;
void SetTitleBar(HWND hwnd, char *name){
char buf[14+MAXNAME];
if (name==NULL) sprintf(buf, APPNAME":(無題)");
else sprintf(buf, APPNAME":%s", name);
SetWindowText(hwnd, buf);
}
void readtext (HWND hwnd, char *path, char *name){
SetTitleBar(hwnd, name);
}
void writetext(HWND hwnd, char *path, char *name){}
#ifdef __cplusplus
extern "C"
#endif
long FAR PASCAL MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
switch (message) {
case WM_COMMAND:
switch((WORD)wParam) {/*コントロールID*/
static OPENFILENAME ofn;
static char achFilePath[MAXPATH], achFileTitle[MAXNAME]="noname.txt";
case IDM_SAVE:
case IDM_OPEN:
memset(&ofn, 0, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = "テキスト(*.TXT)\0*.TXT\0全ファイル(*.*)\0*.*\0";
ofn.lpstrCustomFilter = NULL;
ofn.nFilterIndex = 1;
if ((WORD)wParam==IDM_OPEN) achFilePath[0] = 0;
else strcpy(achFilePath,achFileTitle);
ofn.lpstrFile = (LPSTR)achFilePath;
ofn.nMaxFile = sizeof(achFilePath);
ofn.lpstrFileTitle = (LPSTR)achFileTitle;
ofn.nMaxFileTitle = sizeof(achFileTitle);
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = NULL; //ofn.lpstrTitle = "ファイルを開く";
ofn.lpstrDefExt = NULL;
if ((WORD)wParam==IDM_OPEN) ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
else ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
if ((WORD)wParam==IDM_OPEN) {
if(GetOpenFileName((LPOPENFILENAME)&ofn))
readtext(hWnd, achFilePath, achFileTitle);
}else{
if (GetSaveFileName((LPOPENFILENAME)&ofn))
writetext(hWnd, achFilePath, achFileTitle);
}
return 0;
case IDM_EXIT:
SendMessage(hWnd, WM_CLOSE, 0, 0L);
return 0;
case IDM_ABOUT:
MessageBox(hWnd, APPNAME, "バージョン情報", MB_OK);
return 0;
case IDM_HELP:
if (Version>=0x0400) {
char *p;
GetModuleFileName(hInstApp,buf,260);
p=strstr(buf,".EXE");
if (p) strcpy(p,".HLP");
else strcpy(buf,APPNAME".HLP");
WinHelp(hWnd, buf, HELP_CONTENTS, 0L);
}else WinHelp(hWnd, APPNAME".hlp", HELP_CONTENTS, 0L);
return 0;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
BOOL InitApplication(HINSTANCE hInstance){
WNDCLASS wc;
wc.style = 0;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
//wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIcon = LoadIcon(hInstance, "HinagataIcon");
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
//wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = "HinagataMenu";
wc.lpszClassName = "HinagataWClass";
return RegisterClass(&wc);
}
void GetWindowsVersion(void){
// 0x300: Windows 3.00
// 0x30a: Windows 3.10
// 0x30b: Windows 3.11
// 0x35f: Windows 95 (16bit) (3.95)
// 0x400: Windows 95 (32bit) (4.00)
// 0x362: Windows 98 (16bit) (3.98)
// 0x40a: Windows 98 (32bit) (4.10)
WORD DosVersion = HIWORD(GetVersion());
Version = LOWORD(GetVersion());
Version = (WORD)((LOBYTE(Version)<<8) + HIBYTE(Version));
#ifdef WIN32
if (DosVersion & 0x8000) NT=0; else NT=1;
#else
if (Version==0x35f && DosVersion >=0x70a) Version+=3;
#endif
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow){
GetWindowsVersion();
hwndApp = CreateWindow(
"HinagataWClass", APPNAME, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
if (!hwndApp) return FALSE;
ShowWindow(hwndApp, nCmdShow);
UpdateWindow(hwndApp);
return TRUE;
}
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
MSG msg;
HACCEL hAccel=LoadAccelerators(hInstance, "HinagataAccel");
hInstApp=hInstance;
if (!hPrevInstance)
if (!InitApplication(hInstance))
return FALSE;
if (!InitInstance(hInstance, nCmdShow))
return FALSE;
while (GetMessage(&msg, NULL, 0, 0)) {
if (!TranslateAccelerator(hwndApp, hAccel, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
ファイル名:hinagata.rc
//#include <windows.h>
#include "hinagata.h"
HinagataIcon ICON "hinagata.ICO"
HinagataMenu MENU
BEGIN
POPUP "ファイル(\036F\037フ)"
BEGIN
MENUITEM "開く(\036O\037ヒ)...", IDM_OPEN
MENUITEM "保存(\036S\037セ)", IDM_SAVE
MENUITEM SEPARATOR
MENUITEM "終了(\036X\037シ)", IDM_EXIT
END
POPUP "ヘルプ(\036H\037ヘ)"
BEGIN
MENUITEM "ヘルプの表示(\036H\037ヘ)... F1", IDM_HELP
MENUITEM "バージョン情報(\036A\037シ)...", IDM_ABOUT
END
END
HinagataAccel ACCELERATORS
BEGIN
VK_F1, IDM_HELP, VIRTKEY
END
ファイル名:hinagata.def
NAME Hinagata
DESCRIPTION 'Microsoft Windows サンプル アプリケーション'
EXETYPE WINDOWS
STUB 'WINSTUB.EXE'
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
HEAPSIZE 1024
STACKSIZE 8192
EXPORTS
MainWndProc @1 ; ウィンドウ処理関数の名前
戻る