home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
MQSRC.LZH
/
MLE_WP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-05-05
|
4KB
|
142 lines
#define INCL_WIN
#include <os2.h>
#include <process.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mq.h"
static FILE *openfile(HWND hwnd)
{
DLF FileData;
HFILE hf;
USHORT rc;
memset(&FileData, 0, sizeof(FileData));
FileData.rgbAction = 0;
FileData.rgbFlags = 0x0010;
FileData.phFile = &hf;
FileData.pszExt = "\\*";
FileData.pszTitle = "File Selector";
FileData.pszInstructions = "Please choose a TEXT file to read";
rc = WtiDlgFile(hwnd, &FileData);
if( rc == 4 )
return(fdopen(hf, "rb"));
else{
return(NULL);
}
}
MRESULT EXPENTRY MleWinProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
{
FILE *fin;
INSTANCE *inst = WinQueryWindowPtr(hwnd, 0);
switch(msg){
case WM_ERASEBACKGROUND:
return((MRESULT)TRUE);
case WM_SIZE:
if(inst) WinSetWindowPos(inst->hwndMLE, 0,
5,5,
SHORT1FROMMP(mp2)-10,
SHORT2FROMMP(mp2)-10,
SWP_SIZE | SWP_MOVE);
break;
case WM_COMMAND:
switch( SHORT1FROMMP(mp1)){
case IDM_OPEN:
fin = openfile(hwnd);
if(fin && inst->hmqWork){
WinPostQueueMsg(inst->hmqWork, WMU_LOADFILE, (MPARAM)fin, 0);
}
break;
case IDM_CLEAR:
WinPostQueueMsg(inst->hmqWork, WMU_CLEAR, 0, 0);
break;
case IDM_HALT:
inst->running = FALSE;
break;
}
break;
case WMU_DONEFILE:
#if 0
if( MBID_YES == WinMessageBox(HWND_DESKTOP, hwnd,
"Finished. Load another file?",
"Sample App", 0, MB_YESNO | MB_ICONQUESTION)){
WinPostMsg(hwnd, WM_COMMAND, MPFROMSHORT(IDM_OPEN), 0);
}
#endif
break;
case WM_CLOSE:
inst->running = FALSE;
WinPostQueueMsg(inst->hmqWork, WM_QUIT, 0, 0);
return(0); /* this cases the window NOT to close. We will
* close when the other thread sends us a WMU_CLOSE
*/
break;
case WMU_CLOSE:
free(inst->stack);
free(inst);
WinDestroyWindow(inst->hwndFrame);
break;
default:
return(WinDefWindowProc(hwnd, msg, mp1, mp2));
}
return(0);
}
void OpenNewMleWin(HWND hwnd)
{
INSTANCE *inst;
ULONG flstyle;
SWP swp;
static SHORT x = 0;
static int num = 0;
char title[15];
inst = malloc(sizeof(INSTANCE));
if(!inst)
return;
sprintf(title, "Child #%u", ++num);
flstyle = FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER | FCF_MINMAX | FCF_MENU;
inst->hwndFrame = WinCreateStdWindow(hwnd, 0L, &flstyle,
"MyMLE", title, 0L, 0, ID_CHILD, &inst->hwndClient);
if(!inst->hwndFrame)
return;
DosSemSet(&inst->semReady);
inst->stack = malloc(0x1800);
_beginthread(WorkThread, inst->stack, 0x1800, inst);
DosSemRequest(&inst->semReady, -1L); /* wait till thread is ready */
/* set "window words" to our instance data. This will later
* be retrieved by WinQueryWindowPtr()
*/
WinSetWindowPtr(inst->hwndClient, 0, inst);
/* make child fit in parent: */
WinQueryWindowPos(hwnd, &swp);
swp.x = swp.y = x;
x += 10;
if(x > swp.cx-20)
x = 0;
swp.cx = swp.cx * 2 / 3;
swp.cy = swp.cy * 2 / 3;
WinSetWindowPos(inst->hwndFrame, 0, swp.x, swp.y, swp.cx, swp.cy,
SWP_SIZE | SWP_MOVE);
WinQueryWindowPos(inst->hwndClient, &swp);
inst->hwndMLE = WinCreateWindow(inst->hwndClient, WC_MLE, NULL,
MLS_BORDER | WS_VISIBLE | MLS_VSCROLL | MLS_HSCROLL,
5, 5,
swp.cx-10, swp.cy-10,
inst->hwndClient,
HWND_TOP, ID_MLE, NULL, NULL);
WinShowWindow(inst->hwndFrame, TRUE);
WinSetFocus(HWND_DESKTOP, inst->hwndMLE);
}