?? maingui.c
字號:
// MainGUI.C
//
// This file include menu functions and the core code of WYMGUI.
//
// Copyright (c) 1995.8 ~ 1998.4, Mr. Wei Yongming.
//
// Last modified date: 1998.04.15.
#include <stdio.h>
#include <conio.h>
#include <io.h>
#include <dos.h>
#include <bios.h>
#include <process.h>
#include <time.h>
#include <stddef.h>
#include <stdlib.h>
#include <malloc.h>
#include <graph.h>
#include <memory.h>
#include <Vmemory.h>
#include <string.h>
#include <direct.h>
#include <ctype.h>
#include <float.h>
#include <math.h>
#include "Common.h"
#include "Support.h"
#include "MainGUI.h"
#include "Dialog.h"
extern STATUSBAR SB[4];
extern struct _videoconfig vc;
const char szMiniGUI[] = "MiniGUI";
const char szDefaultLogo[] = "APP.BMP";
static PNORMALMENUITEM GetNormalMenuItem(PGUIINFO pGUIInfo, WORD wID);
static void RedrawPopupMenuItem(PPOPUPMENUITEM pPopupMenuItem, int iPrev, int iCur);
static void RedrawNormalMenuItem(PNORMALMENUITEM pNormalMenuItem, int iPrev, int iCur, int x, int y, int iWidth);
static void CreateHiliteStringOfPopupMenu(PNORMALMENUITEM pNormalMenuItem, char* achHilite);
static void CreateHiliteStringOfMenuBar(PPOPUPMENUITEM pPopupMenuItem, char* achHilite);
static char GetHiliteAscii(PSTR pStr);
static int GetPositionOfPopupMenuItem(PPOPUPMENUITEM pPopupMenuItem, int iIndex);
static int GetPositionOfNormalMenuItem(PNORMALMENUITEM pNormalMenuItem, int iIndex, int y);
static int GetNextPopupMenu(PPOPUPMENUITEM pPopupMenuItem, int iIndex);
static int GetPreviousPopupMenu(PPOPUPMENUITEM pPopupMenuItem, int iIndex);
static int GetNumOfPopupMenuItem(PPOPUPMENUITEM pPopupMenuItem);
static int GetNextNormalMenuItem(PNORMALMENUITEM pNormalMenuItem, int iIndex);
static int GetPreviousNormalMenuItem(PNORMALMENUITEM pNormalMenuItem, int iIndex);
static int GetNumOfNormalMenuItem(PNORMALMENUITEM pNormalMenuItem);
static int WhichItemMouseIn(PNORMALMENUITEM pNormalMenuItem, int top, int y);
/*
* Function: PGUIINFO GUIPAI CreateMainGUI(char* spCaption, PPOPUPMENUITEM pPopupMenuItem,
PACCELTAB pAccelTab,
int (FAR * MainProc)(PGUIINFO, UINT, WPARAM, LPARAM));
* This function create main GUI:
* (1) Create the message queue;
* (2) Paint the menu bar and no client area;
* (3) Create the status bar.
*
* Parameters:
* spCaption: the caption of the GUI;
* pPopupMenuItem: pointer to the popupmenu;
* pAccelTab: pointer to the accelerator table;
* MainProc: the call back procedure that process message.
* Return:
* success-----the pointer to the structure GUIINFO.
* failure-----NULL.
*
* 1995.8.9.AM.
*
*/
PGUIINFO GUIAPI CreateMainGUI(const char* spCaption,
PPOPUPMENUITEM pPopupMenuItem,
PACCELTAB pAccelTab,
int (FAR * MainProc)(PGUIINFO, UINT, WPARAM, LPARAM))
{
PGUIINFO pGUIInfo;
// Create the mesage queue
if(!(pGUIInfo = (PGUIINFO)malloc(sizeof(GUIINFO))))
return NULL;
pGUIInfo->MQInfo.pMsg = NULL;
if(!CreateMsgQueue(pGUIInfo, MAXQUEUELENGTH))
{
free(pGUIInfo);
return NULL;
}
// set the GUIINFO structure.
strncpy( pGUIInfo->spCaption, spCaption, CAPTIONLENGTH );
pGUIInfo->pPopupMenuItem = pPopupMenuItem;
pGUIInfo->pAccelTab = pAccelTab;
pGUIInfo->MainProc = MainProc;
SetPtrVis(SHOW);
PostMessage(pGUIInfo, MSG_NCCREATE, (WPARAM)pGUIInfo, 0L);
PostMessage(pGUIInfo, MSG_NCPAINT, 0, 0L);
PostMessage(pGUIInfo, MSG_CREATE, (WPARAM)pGUIInfo, 0L);
PostMessage(pGUIInfo, MSG_ERASEBKGND, (WPARAM)(&pGUIInfo->dc.clientrect), 0L);
return pGUIInfo;
}
/*
* Function: void GUIPAI DestroyMainGUI( PGUIINFO pGUIInfo );
* This function Destroy main GUI:
* (1) Release the message queue;
* (2) Release the space that was allocated to GUIINFO structure.
*
* Parameters:
* pGUIInfo: the pointer to the GUIINFO structure.
* Return:
* None
*
* 1995.8.9.AM.
*
*/
void GUIAPI DestroyMainGUI( PGUIINFO pGUIInfo )
{
CreateMsgQueue(pGUIInfo, 0);
free(pGUIInfo);
SetPtrVis(HIDE);
}
int FAR DefaultGUIProc(PGUIINFO pGUIInfo, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static unsigned int uTimes = 767;
switch(uMsg)
{
case MSG_NCCREATE:
uTimes = 767;
break;
case MSG_NCPAINT:
// Draw Menu
DrawMenuBar(pGUIInfo->pPopupMenuItem);
DrawNCArea(pGUIInfo);
DrawStatusBar();
break;
case MSG_DESTROY:
PostMessage(pGUIInfo, MSG_KILLFOCUS, 0, 0L);
PostMessage(pGUIInfo, MSG_DESTROYPANES, 0, 0L);
do
{
MSG msg;
if(GetMessageFromQueue(pGUIInfo, &msg))
{
TranslateAccelerator(pGUIInfo, &msg);
DisptchMessage(pGUIInfo, &msg);
}
else
break;
}while(TRUE);
PostMessage(pGUIInfo, MSG_QUIT, TRUE, 0L);
break;
case MSG_SETFOCUS:
DrawCaption(pGUIInfo, TRUE);
break;
case MSG_KILLFOCUS:
DrawCaption(pGUIInfo, FALSE);
break;
case MSG_ERASEBKGND:
{
PRECT pRect = (PRECT)wParam;
memcpy(&pGUIInfo->dc.cliprect, pRect, sizeof(RECT));
SetPtrVis(HIDE);
_setcolor(COLOR_darkcyan);
_rectangle( _GFILLINTERIOR, pRect->left, pRect->top,
pRect->right, pRect->bottom);
SetPtrVis(SHOW);
PostMessage(pGUIInfo, MSG_PAINT, (WPARAM)(&pGUIInfo->dc), 0L);
}
break;
case MSG_IDLE:
if(SB[0].uTimes != uTimes)
{
STATUSBARDATA SBData;
SBData.fgcolor = 0;
SBData.lpStr = "菜單:F10,<Alt+加速鍵>;主控界面:Alt+F4。";
SetStatusBarInfo(0, &SBData);
uTimes = SB[0].uTimes;
}
break;
case MSG_RBUTTONDOWN:
break;
case MSG_LBUTTONDOWN:
break;
case MSG_CHAR:
break;
default:
break;
}
return 0;
}
/* Function: void GUIAPI GetMessage(PMSG pMsg)
* This function get ascii code and key code.
* Parameters:
* pKeySqn: pointer to KEYSEQUENCE struct.
* Return:
* None.
*
* 1995.8.9.AM.
*
*/
void GUIAPI GetMessage(PMSG pMsg)
{
UINT uKey;
EVENT meEvent;
static BOOL fLBtnDown = FALSE;
static BOOL fRBtnDown = FALSE;
if(uKey = GetKey(NO_WAIT))
{
pMsg->uMsg = KB_KEYDOWN;
pMsg->wParam = uKey;
}
else if(GetMouseEvent(&meEvent))
{
if( meEvent.fsBtn & LEFT_DOWN )
{
fLBtnDown = TRUE;
pMsg->uMsg = ME_LBUTTONDOWN;
pMsg->pt.x = meEvent.hotx;
pMsg->pt.y = meEvent.hoty;
return;
}
else if( fLBtnDown && !(meEvent.fsBtn & LEFT_DOWN) )
{
fLBtnDown = FALSE;
pMsg->uMsg = ME_LBUTTONUP;
pMsg->pt.x = meEvent.hotx;
pMsg->pt.y = meEvent.hoty;
return;
}
if( meEvent.fsBtn & RIGHT_DOWN )
{
fRBtnDown = TRUE;
pMsg->uMsg = ME_RBUTTONDOWN;
pMsg->pt.x = meEvent.hotx;
pMsg->pt.y = meEvent.hoty;
return;
}
else if( fRBtnDown && !(meEvent.fsBtn & RIGHT_DOWN) )
{
fRBtnDown = FALSE;
pMsg->uMsg = ME_RBUTTONUP;
pMsg->pt.x = meEvent.hotx;
pMsg->pt.y = meEvent.hoty;
return;
}
pMsg->uMsg = ME_MOVE;
pMsg->pt.x = meEvent.hotx;
pMsg->pt.y = meEvent.hoty;
return;
}
else
pMsg->uMsg = NULLINPUT;
return;
}
/*
* Function: BOOL GUIAPI CreateMsgQueue( PGUIINFO pGUIInfo, int cMsg )
* This function create a new message queue.
* Parameters:
* cMsg: the longth of message queue.
* Return:
* success-----TRUE.
* failure-----FALSE.
*
* 1995.8.9.AM.
*
*/
BOOL GUIAPI CreateMsgQueue( PGUIINFO pGUIInfo, int cMsg )
{
if(pGUIInfo->MQInfo.pMsg)
free(pGUIInfo->MQInfo.pMsg);
if(cMsg == 0)
return TRUE;
if(!(pGUIInfo->MQInfo.pMsg = (PMSG)malloc(cMsg*(sizeof(MSG)))))
return FALSE; // No enogh memory.
pGUIInfo->MQInfo.cMsg = cMsg;
pGUIInfo->MQInfo.iFront = 0;
pGUIInfo->MQInfo.iRear = 0; // a empty queue.
return TRUE;
}
/*
* Function: BOOL GUIAPI PostMessage( PGUIINFO pGUIInfo, UINT uMsg, WPARAM wParam, LPARAM lParam )
* This function posts(places) a message in the message queue.
* queue.
* Parameters:
* pGUIInfo: the pionter to the GUIINFO structure.
* uMsg: message to post
* wParam: first message parameter
* lParam: seconde message parameter
* Return:
* success-----TRUE.
* failure-----FALSE.
*
* 1995.8.9.AM.
*
*/
BOOL GUIAPI PostMessage( PGUIINFO pGUIInfo, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
int iTemp;
iTemp = pGUIInfo->MQInfo.iRear;
pGUIInfo->MQInfo.iRear = (pGUIInfo->MQInfo.iRear + 1) % pGUIInfo->MQInfo.cMsg;
if(pGUIInfo->MQInfo.iRear == pGUIInfo->MQInfo.iFront)
{
pGUIInfo->MQInfo.iRear = iTemp;
return FALSE; // The message queue is full.
}
(pGUIInfo->MQInfo.pMsg + pGUIInfo->MQInfo.iRear)->uMsg = uMsg;
(pGUIInfo->MQInfo.pMsg + pGUIInfo->MQInfo.iRear)->wParam = wParam;
(pGUIInfo->MQInfo.pMsg + pGUIInfo->MQInfo.iRear)->lParam = lParam;
return TRUE;
}
/*
* Function: BOOL GUIAPI GetMessageFromQueue( PGUIINFO pGUIInfo, PMSG pMsg )
* Using this function, you can get the message from the message queue.
* Parameters:
* pGUIInfo: the pionter to the GUIINFO structure.
* pMsg: pinter to the message structure.
* Return:
* success-----TRUE.
* failure-----FALSE. // No message in the queue.
*
* 1995.8.9.AM.
*
*/
BOOL GUIAPI GetMessageFromQueue( PGUIINFO pGUIInfo, PMSG pMsg )
{
if(pGUIInfo->MQInfo.iFront == pGUIInfo->MQInfo.iRear)
return FALSE; // There is no message in queue.
pGUIInfo->MQInfo.iFront = (pGUIInfo->MQInfo.iFront + 1) % pGUIInfo->MQInfo.cMsg;
pMsg->uMsg = (pGUIInfo->MQInfo.pMsg + pGUIInfo->MQInfo.iFront)->uMsg;
pMsg->wParam = (pGUIInfo->MQInfo.pMsg + pGUIInfo->MQInfo.iFront)->wParam;
pMsg->lParam = (pGUIInfo->MQInfo.pMsg + pGUIInfo->MQInfo.iFront)->lParam;
return TRUE;
}
/*
* Function: BOOL GUIAPI PreProcMessage( PGUIINFO pGUIInfo, PMSG pMsg )
* This function pre-process the message:
* (1) If some event active the menu, then call TrackMenu function;
* (2) If message is other keyboard message, do nothing;
* (3) If message is other mouse message, Translate the mouse message.
* Parameters:
* pGUIInfo: the pionter to the GUIINFO structure.
* pMsg: pinter to the message that will be processed.
* Return:
* processed -----TRUE.
* have not processed-----FALSE.
*
* 1995.8.9.AM.
*
*/
BOOL GUIAPI PreProcMessage( PGUIINFO pGUIInfo, PMSG pMsg, BOOL bNoTrackMenu )
{
int iID;
int iIndex;
BOOL bCaretDisplaying;
int iCaretX, iCaretY;
bCaretDisplaying = IsCaretDisplaying(&iCaretX, &iCaretY);
switch(pMsg->uMsg)
{
case KB_KEYDOWN:
// See weather F10 key was pressed.
if(pMsg->wParam == 0x0144 && !bNoTrackMenu)
{
if(bCaretDisplaying)
UndisplayCaret();
SendMessage(pGUIInfo, MSG_ACTIVEMENU, 0, 0L);
set_cliprgn(0, 0, vc.numxpixels - 1, vc.numypixels - 1);
iID = TrackMenu(pGUIInfo->pPopupMenuItem, 0, FALSE);
set_cliprgn(pGUIInfo->dc.clientrect.left,
pGUIInfo->dc.clientrect.top,
pGUIInfo->dc.clientrect.right,
pGUIInfo->dc.clientrect.bottom);
if( iID > 0)
{
pMsg->uMsg = MSG_COMMAND;
pMsg->wParam = (WPARAM)iID;
pMsg->lParam = 0L;
}
else
pMsg->uMsg = MSG_NULL;
if(bCaretDisplaying)
SetCaretPos(iCaretX, iCaretY);
}
// See if Alt + x key has pressed.
else if((HIBYTE(pMsg->wParam)) == 0x04 && !bNoTrackMenu)
{
iIndex = CanActiveMenuByAltKey(pGUIInfo->pPopupMenuItem, (UINT)pMsg->wParam);
if(bCaretDisplaying)
UndisplayCaret();
if(iIndex >= 0)
{
SendMessage(pGUIInfo, MSG_ACTIVEMENU, iIndex, 0L);
set_cliprgn(0, 0, vc.numxpixels - 1, vc.numypixels - 1);
iID = TrackMenu(pGUIInfo->pPopupMenuItem, iIndex, TRUE);
set_cliprgn(pGUIInfo->dc.clientrect.left,
pGUIInfo->dc.clientrect.top,
pGUIInfo->dc.clientrect.right,
pGUIInfo->dc.clientrect.bottom);
if( iID > 0)
{
pMsg->uMsg = MSG_COMMAND;
pMsg->wParam = (WPARAM)iID;
pMsg->lParam = 0L;
}
else
pMsg->uMsg = MSG_SYSCHAR;
}
else
pMsg->uMsg = MSG_SYSCHAR;
if(bCaretDisplaying)
SetCaretPos(iCaretX, iCaretY);
}
else
{
pMsg->uMsg = MSG_CHAR;
}
break;
case ME_LBUTTONDOWN:
iIndex = CanActiveMenu(pGUIInfo->pPopupMenuItem, &(pMsg->pt));
if(iIndex >= 0)
{
if(bCaretDisplaying)
UndisplayCaret();
SendMessage(pGUIInfo, MSG_ACTIVEMENU, 0, 0L);
set_cliprgn(0, 0, vc.numxpixels - 1, vc.numypixels - 1);
iID = TrackMenu(pGUIInfo->pPopupMenuItem, iIndex, TRUE);
set_cliprgn(pGUIInfo->dc.clientrect.left,
pGUIInfo->dc.clientrect.top,
pGUIInfo->dc.clientrect.right,
pGUIInfo->dc.clientrect.bottom);
if( iID > 0)
{
pMsg->uMsg = MSG_COMMAND;
pMsg->wParam = (WPARAM)iID;
pMsg->lParam = 0L;
}
else
{
if(IsInClientArea(pGUIInfo, pMsg->pt))
pMsg->uMsg = MSG_LBUTTONDOWN;
else
pMsg->uMsg = MSG_NCLBUTTONDOWN;
pMsg->lParam = (LPARAM)(MAKELONG(pMsg->pt.x, pMsg->pt.y));
}
}
else
{
if(IsInClientArea(pGUIInfo, pMsg->pt))
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -