📄 maingui.c
字号:
pMsg->uMsg = MSG_LBUTTONDOWN;
else
pMsg->uMsg = MSG_NCLBUTTONDOWN;
pMsg->lParam = (LPARAM)(MAKELONG(pMsg->pt.x, pMsg->pt.y));
}
break;
case ME_LBUTTONUP:
if(IsInClientArea(pGUIInfo, pMsg->pt))
pMsg->uMsg = MSG_LBUTTONUP;
else
pMsg->uMsg = MSG_NCLBUTTONUP;
pMsg->lParam = (LPARAM)(MAKELONG(pMsg->pt.x, pMsg->pt.y));
break;
case ME_RBUTTONUP:
if(IsInClientArea(pGUIInfo, pMsg->pt))
pMsg->uMsg = MSG_RBUTTONUP;
else
pMsg->uMsg = MSG_NCRBUTTONUP;
pMsg->lParam = (LPARAM)(MAKELONG(pMsg->pt.x, pMsg->pt.y));
break;
case ME_RBUTTONDOWN:
if(IsInClientArea(pGUIInfo, pMsg->pt))
pMsg->uMsg = MSG_RBUTTONDOWN;
else
pMsg->uMsg = MSG_NCRBUTTONDOWN;
pMsg->lParam = (LPARAM)(MAKELONG(pMsg->pt.x, pMsg->pt.y));
break;
case ME_MOVE:
pMsg->uMsg = MSG_MOUSEMOVE;
pMsg->lParam = (LPARAM)(MAKELONG(pMsg->pt.x, pMsg->pt.y));
PostMessage(pGUIInfo, MSG_SETCURSOR, pMsg->wParam, pMsg->lParam);
break;
default:
pMsg->uMsg = MSG_IDLE;
pMsg->wParam = 0;
pMsg->lParam = 0L;
break;
}
PostMessage(pGUIInfo, pMsg->uMsg, pMsg->wParam, pMsg->lParam);
return TRUE;
}
/*
* Function: BOOL GUIAPI IsInClientArea( PGUIINFO pGUIInfo, POINT pt )
* This function determines weather the specified ponit pt is
* in the client area.
* Parameters:
* pGUIInfo: the pionter to the GUIINFO structure;
* pt: specified the point.
* Return:
* TRUE: the point is in the client;
* FALSE: the point is not in the client.
*
* 1995.8.9.AM.
*
*/
BOOL GUIAPI IsInClientArea( PGUIINFO pGUIInfo, POINT pt )
{
return ((pt.x >= pGUIInfo->dc.clientrect.left) &&
(pt.x < pGUIInfo->dc.clientrect.right) &&
(pt.y >= pGUIInfo->dc.clientrect.top) &&
(pt.y < pGUIInfo->dc.clientrect.bottom));
}
/*
* Function: int GUIAPI TranslateAccelerator( PGUIINFO pGUIInfo, PMSG pMsg);
* This function translate the accelerator to a MSG_COMMAND.
*
* Parameters:
* pGUIInfo: the pionter to the GUIINFO structure.
* pMsg: pinter to the message that will be translated.
*
* Return:
* if there is no message translated, return 0.
*
* 1995.8.9.AM.
*
*/
int GUIAPI TranslateAccelerator( PGUIINFO pGUIInfo, PMSG pMsg)
{
int i = 0;
BOOL fTranslated = FALSE;
if(pMsg->uMsg == MSG_CHAR || pMsg->uMsg == MSG_SYSCHAR)
{
do
{
if((pGUIInfo->pAccelTab+i)->bEvent == LOBYTE(pMsg->wParam) &&
((pGUIInfo->pAccelTab+i)->fFlags & 0x0f) == HIBYTE(pMsg->wParam))
{
PNORMALMENUITEM pNormalMenuItem;
pNormalMenuItem = GetNormalMenuItem(pGUIInfo, (pGUIInfo->pAccelTab+i)->wID);
if(pNormalMenuItem)
{
fTranslated = TRUE;
if(pNormalMenuItem->fItemFlags & MF_DISABLED)
break;
}
else
break;
pMsg->uMsg = MSG_COMMAND;
pMsg->wParam = (pGUIInfo->pAccelTab+i)->wID;
break;
}
if((pGUIInfo->pAccelTab+i)->bEvent & AF_END)
break;
i++;
}while(TRUE);
}
if(fTranslated)
return 1;
return 0;
}
/*
* Function: void GUIAPI DisptchMessage( PGUIINFO pGUIInfo, PMSG pMsg )
* This function disptch the specified message to the call back function.
* Parameters:
* pGUIInfo: the pionter to the GUIINFO structure.
* pMsg: pinter to the message that will be disptched.
* Return:
* None;
*
* 1995.8.9.AM.
*
*/
void GUIAPI DisptchMessage( PGUIINFO pGUIInfo, PMSG pMsg )
{
(*pGUIInfo->MainProc)(pGUIInfo, pMsg->uMsg, pMsg->wParam, pMsg->lParam);
}
/*
* Function: void GUIAPI SendMessage( PGUIINFO pGUIInfo, UINT uMsg, WPARAM wParam LPARAM lParam )
* This function send the specified message directly to the call back function.
* Parameters:
* pGUIInfo: the pionter to the GUIINFO structure.
* uMsg: the message that will be sent.
* wParam: the WORD parameters of the message.
* lParam: the LONG parameters of the message.
* Return:
* None;
*
* 1997.7.7.AM.
*
*/
void GUIAPI SendMessage( PGUIINFO pGUIInfo, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
(*pGUIInfo->MainProc)(pGUIInfo, uMsg, wParam, lParam);
}
#define MN_BKCOLOR 15 // The background color of normal menu item.
#define MN_FGCOLOR 0 // The foreground color of normal menu item.
#define MA_BKCOLOR 8 // The background color of actived menu item.
#define MA_FGCOLOR 15 // The foreground color of actived menu item.
#define MD_FGCOLOR 14 // The foreground color of disabled menu item.
#define MN_HEIGHT 18 // The height of normal menu item.
#define MB_HEIGHT 4 // The height of menu break.
#define MB_WIDTH 20 // The width of menu bar break.
#define MB_START_WIDTH 4
#define MP_START_WIDTH 8 // The width before start bar menu item.
#define MP_END_WIDTH 8 // The width after end bar menu item.
#define MN_START_WIDTH 16 // The width before start normal menu item.
#define MN_END_WIDTH 16 // The width after end normal menu item.
/*
* Function: void GUIAPI DrawNCArea( PGUIINFO pGUIInfo )
* This function Draw the none clietn area, and fill the client rect of
* pGUIInfo
* Parameters:
* Return:
* None;
*
* 1995.8.9.AM.
*
*/
void GUIAPI DrawNCArea( PGUIINFO pGUIInfo )
{
pGUIInfo->dc.clientrect.left = 0;
pGUIInfo->dc.clientrect.right = vc.numxpixels - 1;
pGUIInfo->dc.clientrect.top = CP_HEIGHT + MN_HEIGHT + 2;
pGUIInfo->dc.clientrect.bottom = vc.numypixels - SB_HEIGHT - 1;
PostMessage(pGUIInfo, MSG_SETFOCUS, 0, 0L);
}
/*
* Function: void GUIAPI DrawCaption( PGUIINFO pGUIInfo, BOOL fSetFocus)
* This function disptch the specified message to the call back function.
* Parameters:
* Return:
* None;
*
* 1995.8.9.AM.
*
*/
void GUIAPI DrawCaption( PGUIINFO pGUIInfo, BOOL fSetFocus)
{
int bkcolor;
int fgcolor;
int x;
bkcolor = fSetFocus?CP_BKCOLOR:CD_BKCOLOR;
fgcolor = fSetFocus?CP_FGCOLOR:CD_FGCOLOR;
// Draw caption
set_cliprgn(0, 0, vc.numxpixels - 1, vc.numypixels - 1);
SetPtrVis(HIDE);
_setcolor(bkcolor);
_rectangle(_GFILLINTERIOR, 0, 0, vc.numxpixels - 1, CP_HEIGHT - 1);
// Draw copyright information.
if( !Bitmap(szDefaultLogo, 5, 16, 16) )
{
set_color( 5 );
cc_wt16(szMiniGUI, 16, 0);
}
set_color(fgcolor);
x = (vc.numxpixels - GetOutWidth(pGUIInfo->spCaption))/2;
cc_wt16(pGUIInfo->spCaption, x, 0);
_setcolor(0);
_moveto(0, CP_HEIGHT - 1);
_lineto(vc.numxpixels - 1, CP_HEIGHT - 1);
SetPtrVis(SHOW);
set_cliprgn(pGUIInfo->dc.clientrect.left,
pGUIInfo->dc.clientrect.top,
pGUIInfo->dc.clientrect.right,
pGUIInfo->dc.clientrect.bottom);
}
/*
* Function: void GUIAPI DrawMenuBar( PPOPUPMENUITEM pPopupMenuItem )
* This function disptch the specified message to the call back function.
* Parameters:
* Return:
* None;
*
* 1995.8.9.AM.
*
*/
void GUIAPI DrawMenuBar( PPOPUPMENUITEM pPopupMenuItem )
{
int x = MB_START_WIDTH;
PPOPUPMENUITEM pBuffer = pPopupMenuItem;
SetPtrVis(HIDE);
// Fill background.
_setcolor(MN_BKCOLOR);
_rectangle( _GFILLINTERIOR, 0, CP_HEIGHT, vc.numxpixels, CP_HEIGHT + MN_HEIGHT);
_setcolor(0);
_moveto(0, CP_HEIGHT + MN_HEIGHT + 1);
_lineto(vc.numxpixels - 1, CP_HEIGHT + MN_HEIGHT + 1);
// Draw bar menu item.
do
{
if(pBuffer->fItemFlags & MF_MENUBARBREAK)
x += MB_WIDTH;
else
{
int iWidth = GetOutWidth(pBuffer->spItemText)
+ MP_START_WIDTH + MP_END_WIDTH;
DrawMenuItem(pBuffer->spItemText, FALSE, pBuffer->fItemFlags, x, CP_HEIGHT, iWidth);
x += iWidth;
}
if(pBuffer->fItemFlags & MF_END)
break;
pBuffer++;
}while(TRUE);
SetPtrVis(SHOW);
}
#define KB_LEFT 0x014b
#define KB_RIGHT 0x014d
#define KB_UP 0x0148
#define KB_DOWN 0x0150
#define KB_ENTER 0x000d
#define KB_ESC 0x001b
#define KB_ALT 0x0800
#define MAXITEM 20
#define NEXTPOPUPMENU -1
#define PREVIOUSPOPUPMENU -2
#define MOUSEDETERMINE -3
#define INVALIDCHOICE -4
#define NULLCHOICE -5
#define ENDTRACKMENU -6
/*
* Function: int GUIAPI TrackMenu( PPOPUPMENUITEM pPopupMenuItem, int iIndex, BOOL fPopup )
* This function track menu by user.
* Parameters:
*
* Return:
* >= 0: give the select menu item's identification;
* < 0: none menu item or invalid menu item was selected.
*/
int GUIAPI TrackMenu( PPOPUPMENUITEM pPopupMenuItem, int iIndex, BOOL fPopup )
{
unsigned uKey; // unsigned key code
EVENT meEvent;
BOOL fReturn = FALSE;
static BOOL fBtnDown = FALSE;
int x, y;
int iWidth;
int iID = -1;
int iPrev;
int iCur;
POINT pt;
char achHilite[MAXITEM];
char* pchT; // Temporary character pointer
CreateHiliteStringOfMenuBar(pPopupMenuItem, achHilite);
// Track menu bar.
iPrev = -1;
iCur = iIndex;
GetKey(CLEAR);
while( TRUE )
{
if(iPrev != iCur) // We must redisplay the popup menu item.
{
RedrawPopupMenuItem(pPopupMenuItem, iPrev, iCur);
iPrev = iCur;
}
if(!fPopup)
{
if( uKey = GetKey( NO_WAIT ) )
{
switch( uKey )
{
case KB_UP: // Up key
case KB_DOWN: // Down key
case KB_ENTER:
fPopup = TRUE;
break;
case KB_RIGHT: // Right key
iCur = GetNextPopupMenu(pPopupMenuItem, iCur);
break;
case KB_LEFT: // Left key
iCur = GetPreviousPopupMenu(pPopupMenuItem, iCur);
break;
case KB_ALT:
case KB_ESC:
iCur = -1;
fReturn = TRUE;
break;
default:
if( uKey > 256 ) // Ignore unknown function key
break;
pchT = strchr( achHilite, (char)tolower( uKey ) );
if( pchT != NULL ) // If in highlight string, evaluate
{
iCur = pchT - achHilite;
if(!((pPopupMenuItem+iCur)->fItemFlags & MF_DISABLED))
{
RedrawPopupMenuItem(pPopupMenuItem, iPrev, iCur);
iPrev = iCur;
fPopup = TRUE;
}
break;
}
else
break; // Ignore unkown ASCII key
}
}
else if( GetMouseEvent( &meEvent ) )
{
pt.x = meEvent.hotx;
pt.y = meEvent.hoty;
if( meEvent.fsBtn & LEFT_DOWN )
{
fBtnDown = TRUE;
iCur = CanActiveMenu(pPopupMenuItem, &pt);
if(iCur < 0)
fReturn = TRUE;
else
fPopup = TRUE;
}
else if( fBtnDown && !(meEvent.fsBtn & LEFT_DOWN) )
{
fBtnDown = FALSE;
}
}
}
if(iPrev != iCur) // We must redisplay the popup menu item.
{
RedrawPopupMenuItem(pPopupMenuItem, iPrev, iCur);
iPrev = iCur;
}
if(fPopup)
{
// Get the position of popup menu.
x = GetPositionOfPopupMenuItem(pPopupMenuItem, iCur);
iWidth = GetPopupMenuWidth(pPopupMenuItem + iCur);
if((x + iWidth + 2) > vc.numxpixels)
x = vc.numxpixels - iWidth - 2;
y = CP_HEIGHT + MN_HEIGHT;
iID = TrackPopupMenu(pPopupMenuItem, iCur, x, y, &pt);
if( iID > 0)
{
iCur = -1;
fReturn = TRUE;
}
else
{
switch( iID )
{
case NEXTPOPUPMENU:
iCur = GetNextPopupMenu(pPopupMenuItem, iCur);
fPopup = TRUE;
break;
case PREVIOUSPOPUPMENU:
iCur = GetPreviousPopupMenu(pPopupMenuItem, iCur);
fPopup = TRUE;
break;
case MOUSEDETERMINE:
iCur = CanActiveMenu(pPopupMenuItem, &pt);
if(iCur < 0)
fReturn = TRUE;
else
fPopup = TRUE;
break;
case INVALIDCHOICE: // selected a disabled menu item.
case ENDTRACKMENU: // Alt pressed
iCur = -1;
fReturn = TRUE;
break;
case NULLCHOICE: // ESC pressed
fPopup = FALSE;
break;
}
}
}
if(fReturn)
{
RedrawPopupMenuItem(pPopupMenuItem, iPrev, iCur);
return iID;
}
}
}
/*
* Function: static void RedrawPopupMenuItem(PPOPUPMENUITEM pPopupMenuItem, int iPrev, int iCur)
* Parameters:
* Return:
* None;
*/
static void RedrawPopupMenuItem(PPOPUPMENUITEM pPopupMenuItem, int iPrev, int iCur)
{
int x, iWidth;
STATUSBARDATA SBData;
SBData.fgcolor = 0;
SetPtrVis(HIDE);
if( iPrev >= 0)
{
iWidth = MP_START_WIDTH + MP_END_WIDTH;
x = GetPositionOfPopupMenuItem(pPopupMenuItem, iPrev);
iWidth += GetOutWidth((pPopupMenuItem + iPrev)->spItemText);
DrawMenuItem((pPopupMenuItem + iPrev)->spItemText,
FALSE,
(pPopupMenuItem + iPrev)->fItemFlags,
x, CP_HEIGHT,
iWidth) ;
}
if( iCur >= 0)
{
iWidth = MP_START_WIDTH + MP_END_WIDTH;
x = GetPositionOfPopupMenuItem(pPopupMenuItem, iCur);
iWidth += GetOutWidth((pPopupMenuItem + iCur)->spItemText);
DrawMenuItem((pPopupMenuItem + iCur)->spItemText,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -