⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nthell.wmc

📁 WIN32高级程序设计书附源码
💻 WMC
📖 第 1 页 / 共 2 页
字号:
    ON_COMMAND(IDM_Exit, wmIDM_ExitCM)

    ON_COMMAND(IDM_All, wmIDM_AllCM)

    ON_COMMAND(IDM_Dhrystone, wmIDM_DhrystoneCM)

    ON_COMMAND(IDM_Whetstone, wmIDM_WhetstoneCM)

    ON_COMMAND(IDM_Disk, wmIDM_DiskCM)

    ON_COMMAND(IDM_Videoalltests, wmIDM_VideoalltestsCM)

    ON_COMMAND(IDM_TextScrolling, wmIDM_TextScrollingCM)

    ON_COMMAND(IDM_LineDrawing, wmIDM_LineDrawingCM)

    ON_COMMAND(IDM_FilledObjects, wmIDM_FilledObjectsCM)

    ON_COMMAND(IDM_ColorDisplay, wmIDM_ColorDisplayCM)

    ON_COMMAND(IDM_Details, wmIDM_DetailsCM)

    ON_COMMAND(IDM_About, wmIDM_AboutCM)

END_MESSAGE_MAP()
 
 
 
//*************************************************************
//                 CLASS: CWinMakerClientDlg
//*************************************************************
 
 
// Message Map for class CWinMakerClientDlg, decending from class CDialog.
 
BEGIN_MESSAGE_MAP(CWinMakerClientDlg, CDialog)

    
// Message Map for special message map entries
    ON_COMMAND(IDOK,OnOK)
    ON_COMMAND(IDCANCEL,OnCancel)
END_MESSAGE_MAP()
 
 
 
 
void CWinMakerClientDlg::PostNcDestroy()
{
    // Make sure destructors are called
    delete this;
}
 
 
 
//*************************************************************
//
//                 WindowsMAKER Pro service functions
//
//*************************************************************
 
 
// **********************************************************
// ERROR MESSAGE HANDLING (Definitions can be overruled.)
// **********************************************************
 
// the title of the dialog box when system modal errors occur
// (ie. cannot load strings form stringtable)
#ifndef ERRORCAPTION
#define ERRORCAPTION "WINMAG NT Benchmarks"
#endif
 
#ifndef LOADERROR
#define LOADERROR "Cannot load string."
#endif
 
// Display an error message.  Usually called when a resource
// can't be loaded by WindowsMAKER.
 
int BLDDisplayMessage (HWND hWnd, unsigned uMsg, 
    char *pContext, int iType)
{ 
    int i, j; 
    char Message[200+1]; 
 
 
    if( uMsg )
    {
        if( !LoadString (AfxGetInstanceHandle (), uMsg, Message, sizeof(Message)) )
            {
            MessageBox (hWnd, LOADERROR, ERRORCAPTION,
                MB_OK | MB_SYSTEMMODAL | MB_ICONHAND);
            return FALSE; 
        }
    }
    else
        Message[0] = 0;
 
    if( pContext )
    {
        i = lstrlen (Message);
        j = lstrlen (pContext);
        if( i + j + 1 <= 200 )
        {
            lstrcat (Message, " ");
            lstrcat (Message, pContext);
        }
    }
 
    return MessageBox (hWnd, Message, ERRORCAPTION, iType);
}
 
 
// ***************************************************************
//         FUNCTIONS FOR DRAWING GRAPHIC BUTTONS
// ***************************************************************
 
// Draws an icon at the specified place on the hDC.
BOOL BLDDrawIcon (LPDRAWITEMSTRUCT lpDrawItem, char *pIconName)
{
    HICON hIcon;
 
 
    if( !(hIcon = LoadIcon (AfxGetInstanceHandle (), pIconName)) )
    {
        BLDDisplayMessage (::GetActiveWindow (), BLD_CannotLoadIcon, pIconName,
            MB_OK | MB_ICONASTERISK);
        return FALSE;
    }
 
    SetMapMode (lpDrawItem->hDC, MM_TEXT);
    return DrawIcon (lpDrawItem->hDC, 0, 0, hIcon);
}
 
// Draw a bitmap at the specified place on the hDC, stretching if
// required.  This routine is often called when processing bitmaps
// in dialog boxes (WM_DRAWITEM messages).
BOOL BLDDrawBitmap (LPDRAWITEMSTRUCT lpDrawItem, 
    char *pBitmapName, BOOL bStretch)
{
    HBITMAP hbm;
    HDC     hMemDC;
    BITMAP  bm;
 
 
    int iRaster = GetDeviceCaps (lpDrawItem->hDC, RASTERCAPS);
    if( (iRaster & RC_BITBLT) != RC_BITBLT )
        return FALSE; // Device cannot display bitmaps
 
    if( !(hbm = LoadBitmap (AfxGetInstanceHandle (), pBitmapName)) )
    {
        BLDDisplayMessage (::GetActiveWindow (), BLD_CannotLoadBitmap, pBitmapName,
            MB_OK | MB_ICONASTERISK);
        return FALSE;
    }
 
    if( !GetObject (hbm, sizeof(BITMAP), (LPSTR)&bm) )
    {
        DeleteObject (hbm);
        return FALSE;
    }
    if( !(hMemDC = CreateCompatibleDC (lpDrawItem->hDC)) )
    {
        DeleteObject (hbm);
        return FALSE;
    }
    if( !SelectObject (hMemDC, hbm) )
    {
        DeleteDC (hMemDC);
        DeleteObject (hbm);
        return FALSE;
    }
 
    int    dx = lpDrawItem->rcItem.right - lpDrawItem->rcItem.left;
    int    dy = lpDrawItem->rcItem.bottom - lpDrawItem->rcItem.top;
 
    if( bStretch )
    {
        StretchBlt (lpDrawItem->hDC,
            lpDrawItem->rcItem.left, lpDrawItem->rcItem.top,
            dx, dy,
            hMemDC,
            0, 0,
            bm.bmWidth, bm.bmHeight,
            SRCCOPY);
    }
    else
    {
        BitBlt (lpDrawItem->hDC,
            lpDrawItem->rcItem.left, lpDrawItem->rcItem.top,
            dx, dy,
            hMemDC,
            0, 0,
            SRCCOPY);
    }
    DeleteDC (hMemDC);
    DeleteObject (hbm);
    return TRUE;
}
 
 
 
// ***************************************************************
//       FUNCTION FOR CREATING CONTROLS IN MAIN WINDOW
// ***************************************************************
 
// Startup procedure for controls in the client area
// This routine loads the dialog from the resources, and then changes
// the style bits to make it displayable in the main window.
 
BOOL BLDCreateClientControls (char *pTemplateName, CWinMakerClientDlg* pDlg)
{
    RECT  rClient, rMain, rDialog;
    int   dxDialog, dyDialog, dyExtra;
    HRSRC hRes;
    HANDLE hMem;
    LPBLD_DLGTEMPLATE lpDlg;
    unsigned long styleold,style;
 
 
    if( !IsWindow (TheApp.m_pMainWnd->GetSafeHwnd ()) )
        return 0;
    if( TheApp.m_pMainWnd->IsZoomed () )
        TheApp.m_pMainWnd->ShowWindow (SW_RESTORE);
 
    if( IsWindow (TheApp.pWndClient->GetSafeHwnd ()) )
        TheApp.pWndClient->DestroyWindow (); // Destroy Previous window in client area
 
    // Get access to data structure of dialog box containing layout of controls
    if( !(hRes = FindResource (AfxGetInstanceHandle (), (LPSTR)pTemplateName, RT_DIALOG)) )
        return 0;
    if( !(hMem = LoadResource (AfxGetInstanceHandle (), hRes)) )
        return 0;
    if( !(lpDlg = (LPBLD_DLGTEMPLATE)LockResource (hMem)) )
        return 0;
 
    // Change dialog box data structure so it can be used as a window in client area
    styleold       = lpDlg->dtStyle;
    style          = lpDlg->dtStyle&(CLIENTSTRIP);
    lpDlg->dtStyle = lpDlg->dtStyle^style;
    lpDlg->dtStyle = lpDlg->dtStyle | WS_CHILD | WS_CLIPSIBLINGS;
 
    if( !(pDlg->doCreateIndirect ((const BYTE FAR *)lpDlg)) )
        return 0;
    HWND  hNew = pDlg->GetSafeHwnd ();
 
    // Restore dialog box data structure.
    lpDlg->dtStyle = styleold;
 
    UnlockResource (hMem);
    FreeResource (hMem);
 
    // Move and size window in client area and main window
    TheApp.m_pMainWnd->GetClientRect (&rClient);
    TheApp.m_pMainWnd->GetWindowRect (&rMain);
    GetWindowRect (hNew, &rDialog);
    dxDialog = (rDialog.right - rDialog.left) - (rClient.right - rClient.left);
    dyDialog = (rDialog.bottom - rDialog.top) - (rClient.bottom - rClient.top);
    BLDMoveWindow (TheApp.m_pMainWnd->GetSafeHwnd (), rMain.left, rMain.top,
        (rMain.right - rMain.left) + dxDialog,
        (rMain.bottom - rMain.top) + dyDialog,
        TRUE);
    pDlg->MoveWindow (0, 0,
        (rDialog.right - rDialog.left),
        (rDialog.bottom - rDialog.top),
        TRUE);
    TheApp.m_pMainWnd->GetClientRect (&rClient);
 
    // Compensate size if menu bar is more than one line.
    if( (rDialog.bottom - rDialog.top) > (rClient.bottom - rClient.top) )
    {
        dyExtra = (rDialog.bottom - rDialog.top) - (rClient.bottom - rClient.top);
        BLDMoveWindow (TheApp.m_pMainWnd->GetSafeHwnd (), rMain.left, rMain.top,
            (rMain.right - rMain.left) + dxDialog,
            (rMain.bottom - rMain.top) + dyDialog + dyExtra,
            TRUE);
    }
 
    pDlg->InvalidateRect (NULL, TRUE);
    TheApp.pWndClient = (CWinMakerClientDlg*)pDlg;
    pDlg->ShowWindow (SW_SHOW);
    return TRUE;
}
 
    
// Ensure that window is within screen. 
void BLDMoveWindow(HWND hWnd, int x, int y,
	int nWidth, int nHeight, BOOL bRepaint)
    {
    int xMax,yMax,xNew,yNew;
    
    xMax = GetSystemMetrics(SM_CXSCREEN);
    yMax = GetSystemMetrics(SM_CYSCREEN);
    
    if ((nWidth<=xMax)&&(x+nWidth>xMax))
        xNew=xMax-nWidth;
    else
        xNew=x;
    
    if ((nHeight<=yMax)&&(y+nHeight>yMax))
        yNew=yMax-nHeight;
    else
        yNew=y;
    
    MoveWindow(hWnd,xNew,yNew,nWidth,nHeight,bRepaint);
    return;
    }
    
    
    
 
 
// ***************************************************************
//       FUNCTION FOR SWITCHING MENU SET
// ***************************************************************
 
// This routine switches the menu bar to a new one, and sets up the
// Accel table and all the bitmaps for the new menu.
 
BOOL BLDSwitchMenu (CWnd* pWnd, char *pTemplateName)
{
    DWORD style;
 
 
 
    style = GetWindowLong (pWnd->GetSafeHwnd (), GWL_STYLE);
    // Called from control in main window?
    if( (style & WS_CHILD) == WS_CHILD )
    {
        if( !(pWnd = (pWnd->GetParent ())) )
            return FALSE;
        style = GetWindowLong (pWnd->GetSafeHwnd (), GWL_STYLE);
        if( (style & WS_CHILD) == WS_CHILD ) // No menu in a WS_CHILD window.
            return FALSE;
    }
    if( (style & WS_CAPTION) != WS_CAPTION ) // No menu if no caption.
        return FALSE;
 
    CMenu *pMenuOld = pWnd->GetMenu ();
    CMenu *pMenu = new CMenu;
    if( !(pMenu->LoadMenu (pTemplateName)) )
    {
        BLDDisplayMessage (pWnd->GetSafeHwnd (), BLD_CannotLoadMenu, pTemplateName,
            MB_OK | MB_ICONASTERISK);
        return FALSE;
    }
 
    if( !pWnd->SetMenu (pMenu) )
        return FALSE;
    if( pMenuOld )
    {
        pMenuOld->DestroyMenu ();
    }
 
    pWnd->DrawMenuBar ();
    return TRUE;
}
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -