#include <windows.h>
#include <vfw.h>
#include "resource.h"
#include "driff.h"
#pragma comment(linker,"/subsystem:windows")
HINSTANCE hAppInst;
TCHAR szTitle[256];
TCHAR szWindowClass[256];
ATOM MyRegisterClass(HINSTANCE hInst);
BOOL InitInstance(HINSTANCE hInst,int nCmdSw);
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam);
void GetWinRect(HWND hWnd,int* x,int* y);
int APIENTRY WinMain(HINSTANCE hInst,HINSTANCE hpInst,LPSTR lpArgv,int nCmdSw)
{
MSG msg; HACCEL hAccelTable;
LoadString(hInst,IDS_APP_TITLE,szTitle,256);
LoadString(hInst,IDC_DG,szWindowClass,256);
MyRegisterClass(hInst);
if(!InitInstance(hInst,nCmdSw)) {
return FALSE;
}
hAccelTable = LoadAccelerators(hInst,(LPCTSTR)IDC_DG);
while(GetMessage(&msg,NULL,0,0)) {
if(!TranslateAccelerator (msg.hwnd,hAccelTable,&msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInst)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInst;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_DG;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = NULL;
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInst,int nCmdSw)
{
HWND hWnd;
hAppInst = hInst;
hWnd = CreateWindow(szWindowClass,szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,0,
CW_USEDEFAULT,0,
NULL,NULL,hInst,NULL);
if(!hWnd) return FALSE;
ShowWindow(hWnd,nCmdSw);
UpdateWindow(hWnd);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
static HWND hEdit;
static int wx,wy,wex,wey;
switch(msg) {
case WM_CREATE:
GetWinRect(hWnd,&wx,&wy);
hEdit = CreateWindow("EDIT",
NULL,
WS_CHILD | WS_THICKFRAME | WS_VISIBLE |
ES_MULTILINE | ES_WANTRETURN |
ES_AUTOHSCROLL | ES_AUTOVSCROLL | WS_HSCROLL,
wx-200,-3,
200+5,wy+5,
hWnd,
(HMENU)ID_EDIT,
hAppInst,
NULL);
SendMessage(hEdit,EM_SETLIMITTEXT,(WPARAM)1024*64,0);
set_win(hWnd,hEdit);
dg_DDib = DrawDibOpen();
break;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDM_EXIT: DestroyWindow(hWnd); break;
case IDM_OPEN: dg_fileopen(hWnd); break;
case IDM_CLOSE: dg_close(); break;
case IDM_ISAVE: dg_isave(hWnd); break;
case IDM_DWG1: set_wavedraw(DGW_NORMAL); break;
case IDM_DWG2: set_wavedraw(DGW_FFT); break;
case IDM_DWG3: dg_wavein(hWnd); break;
}
InvalidateRect(hWnd,NULL,TRUE);
break;
case MM_WOM_DONE: break;
case MM_WIM_DATA:
dg_windraw(hWnd);
break;
case WM_PAINT:
break;
case WM_SIZE:
GetWinRect(hWnd,&wx,&wy);
GetWinRect(hEdit,&wex,&wey);
if(wex>wx) wex=wx;
if(wex<5) wex=5;
MoveWindow(hEdit,wx-wex,-3,wex+5,wy+5,TRUE);
InvalidateRect(hWnd,NULL,TRUE);
SendMessage(hWnd,WM_PAINT,0,0);
break;
case WM_DESTROY:
dg_close();
DrawDibClose(dg_DDib);
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd,msg,wParam,lParam);
}
void GetWinRect(HWND hWnd,int* x,int* y)
{
RECT rc;
GetClientRect(hWnd,&rc);
*x = rc.right - rc.left;
*y = rc.bottom - rc.top;
return;
}