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

📄 memory.c

📁 <Win2k系统编程>源码.次数为国人自编,内容丰富,还是不错的.
💻 C
📖 第 1 页 / 共 3 页
字号:
                 }
                 else
                 {
                    MessageBox(ghwndMain,
                               GetStringRes (IDS_ERR_ACCESS_READ_FAILED),
                               NULL, MB_OK);
                    SetWindowText(hTextWnd,
                                  GetStringRes (IDS_ERR_ACCESS_READ_FAILED));
                 }

             return 0L;
             }

            case MM_OPT_8:
            { // refresh now
               HANDLE hActive;

               hActive = (HANDLE) SendMessage(GetParent(hwnd), WM_MDIGETACTIVE, 0L, 0L);
               SendMessage(hEdit, WM_SETTEXT, 0L, (LONG)pShrMem1);
               return 0L;
            }
        }
    }

    case WM_TIMER:
    {
        HANDLE hActive;

        if (IsWindow (hEdit) && pShrMem1)
        {
           hActive = (HANDLE) SendMessage(GetParent(hwnd), WM_MDIGETACTIVE, 0L, 0L);
           SendMessage(hEdit, WM_SETTEXT, 0L, (LONG)pShrMem1);
        }
        return 0L;
    }

    case WM_MDIACTIVATE:
        if ((HWND) lParam == hwnd)
        {
           SendMessage(GetParent(hwnd), WM_MDISETMENU,
                       (DWORD)  hClientMenu,
                       (LONG)   hClientMenuWindow);
           DrawMenuBar(GetParent(GetParent(hwnd))) ;
        }
        return 0;

    case WM_SIZE:
        if (hEdit)
           MoveWindow(hEdit, 0, 0,
                      LOWORD(lParam),
                      HIWORD(lParam)-GetWindowLong(hTextWnd, GWL_USERDATA),
                      TRUE);

        MoveWindow(hTextWnd, 0,
                   HIWORD(lParam) - GetWindowLong(hTextWnd, GWL_USERDATA),
                   LOWORD(lParam),
                   HIWORD(lParam), TRUE);

        return DefMDIChildProc(hwnd, message, wParam, lParam);

    case WM_CREATE:
    {
        PPERWNDINFO      pWndInfo;
        PNODE            pHead;
        HANDLE           hHead, hTmp;
        RECT             rect;

        GetClientRect(hwnd, &rect);
        hTextWnd = CreateWindow("Text", NULL,
                                WS_BORDER | SS_LEFT | WS_CHILD | WS_VISIBLE,
                                0, 0, 0, 0,
                                hwnd,
                                (HMENU) 2,
                                ghModule,
                                NULL);

        EnableMenuItem(hClientMenu, MM_OPT_5, MF_ENABLED);

        SetWindowText(hTextWnd, GetStringRes (IDS_SEL_OPEN_FILE));

        // now find match
        hHead = (HANDLE) GetWindowLong(ghwndMain, 0);
        if (hHead && (pHead = (PNODE)LocalLock(hHead)))
        {

           while ((pHead->ChildWnd.hThisWnd != hwnd) && (pHead->hNext))
           {
              hTmp = hHead;
              hHead = pHead->hNext;
              LocalUnlock(hTmp);
              pHead = (PNODE) LocalLock(hHead);
           }

           if (pHead->ChildWnd.hThisWnd == hwnd)
           {
              pWndInfo = &pHead->ChildWnd;
              GetClientRect(pWndInfo->hThisWnd, &pWndInfo->rcClient);
           }

           LocalUnlock(hHead);
           return DefMDIChildProc(hwnd, message, wParam, lParam);
        }
        return DefMDIChildProc(hwnd, message, wParam, lParam);
    }

    case WM_CLOSE:
    {
        PPERWNDINFO      pWndInfo;
        PNODE            pHead, pTrail;
        HANDLE           hHead, hTmp;


        EnableMenuItem(hClientMenu, MM_OPT_6, MF_GRAYED);
        EnableMenuItem(hClientMenu, MM_OPT_7, MF_GRAYED);
        EnableMenuItem(hClientMenu, MM_OPT_8, MF_GRAYED);

        SendMessage(GetParent(hwnd), WM_MDISETMENU,
                    (DWORD) hMenu,
                    (LONG)   hMenuWindow) ;
        DrawMenuBar(GetParent(GetParent(hwnd))) ;

        // Don't need to read from the edit control anymore
        KillTimer(hwnd, 2);


        // Unmap view, close mapping!
        if (pShrMem1)
        {
           UnmapViewOfFile (pShrMem1);
           pShrMem1 = NULL;
        }

        if (hMem1)
        {
           CloseHandle (hMem1);
           hMem1 = NULL;
        }


        // now find match
        hHead = (HANDLE) GetWindowLong(ghwndMain, 0);
        if (hHead && (pHead = (PNODE)LocalLock(hHead)))
        {
            pTrail = pHead;
            while ((pHead->ChildWnd.hThisWnd != hwnd) && (pHead->hNext))
            {
               hTmp = hHead;
               pTrail = pHead;
               hHead = pHead->hNext;
               LocalUnlock(hTmp);

               pHead = (PNODE) LocalLock(hHead);
            }

            if (pHead->ChildWnd.hThisWnd == hwnd)
            {
                pWndInfo = &pHead->ChildWnd;

                if (pTrail == pHead)
                    SetWindowLong(ghwndMain, 0, (LONG) pHead->hNext);
                else
                    pTrail->hNext = pHead->hNext;

                LocalUnlock(hHead);
                LocalFree(hHead);
            }
            else
            {
                LocalUnlock(hHead);
            }
        }
        return DefMDIChildProc(hwnd, message, wParam, lParam);

    }

    case WM_DESTROY:
        return 0l;

    default:
         return DefMDIChildProc(hwnd, message, wParam, lParam);
    }

}




/***************************************************************************\
* About
*
* About dialog proc.
*
\***************************************************************************/

BOOL CALLBACK APIENTRY About( HWND hDlg,
                              UINT message,
                              DWORD wParam,
                              LONG lParam)
{
    switch (message)
    {
        case WM_INITDIALOG:
            return TRUE;

        case WM_COMMAND:
            if (wParam == IDOK)
                EndDialog(hDlg, wParam);
            break;
    }
    return FALSE;

    UNREFERENCED_PARAMETER(lParam);
    UNREFERENCED_PARAMETER(hDlg);
}

/***************************************************************************\
* MapFileName
*
* MapFileName dialog proc.
*
\***************************************************************************/

BOOL CALLBACK MapFileName( HWND hDlg,
                           UINT message,
                           DWORD wParam,
                           LONG lParam)
{

    switch (message)
    {
    case WM_INITDIALOG:
        return TRUE;

    case WM_COMMAND:
        switch (wParam)
        {
            case IDBTN_OK:
            {
                if (!GetDlgItemText(hDlg, IDEDIT_MAPNAME, gszMapName, 20))
                {
                   strncpy(gszMapName, "MapName1", 10);        // default name
                }
                EndDialog(hDlg, IDBTN_OK);
                break;
            }
        }
    }
    return FALSE;

    UNREFERENCED_PARAMETER(lParam);
    UNREFERENCED_PARAMETER(hDlg);
}

/***************************************************************************\
* FileType
*
* FileType dialog proc.
*
\***************************************************************************/

BOOL CALLBACK FileType( HWND hDlg,
                        UINT message,
                        DWORD wParam,
                        LONG lParam)
{

    switch (message)
    {
       case WM_INITDIALOG:
           return TRUE;

       case WM_COMMAND:
           switch (wParam)
           {
              case IDBTN_PAGE:
              {
                 EndDialog(hDlg, IDBTN_PAGE);
                 break;
              }

              case IDBTN_MAP:
              {
                  if ((GetDlgItemText(hDlg, IDEDIT_MAPFILE, gszFile, 20)) == 0)
                      EndDialog(hDlg, IDBTN_PAGE);  // default to use PAGE file
                  else
                      EndDialog(hDlg, IDBTN_MAP);

                  break;
              }
           }
    }
    return FALSE;

    UNREFERENCED_PARAMETER(lParam);
    UNREFERENCED_PARAMETER(hDlg);
}


/*************************************************************************
*
* TextWndProc
*
* Text Window proc.
*
\***************************************************************************/

LONG APIENTRY TextWndProc (HWND hwnd, UINT message, DWORD wParam, LONG lParam)
{
    static HFONT hFont = (HFONT) NULL;

    switch (message)
    {
       case WM_CREATE:
       {
          LOGFONT    lf;
          HDC        hDC;
          HFONT      hOldFont;
          TEXTMETRIC tm;
          RECT       rect;
          LONG       lHeight;

          SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, FALSE);

          hDC = GetDC(hwnd);
          // this is the height for 8 point size font in pixels
          lf.lfHeight = 8 * GetDeviceCaps(hDC, LOGPIXELSY) / 72;

          hFont = CreateFontIndirect(&lf);
          hOldFont = SelectObject(hDC, hFont);
          GetTextMetrics(hDC, &tm);
          GetClientRect(GetParent(hwnd), &rect);

          // base the height of the window on size of text
          lHeight = tm.tmHeight+6*GetSystemMetrics(SM_CYBORDER)+2;
          // saved the height for later reference
          SetWindowLong(hwnd, GWL_USERDATA, lHeight);
          SetWindowPos(hwnd, NULL, 0, rect.bottom-lHeight,
                       rect.right-rect.left, lHeight,
                       SWP_NOZORDER | SWP_NOMOVE);

          ReleaseDC(hwnd, hDC);
          break;
       }

    case WM_DESTROY:
       if (hFont)
          DeleteObject(hFont);
       break;

    case WM_SETTEXT:
       DefWindowProc(hwnd, message, wParam, lParam);
       InvalidateRect(hwnd,NULL,FALSE);
       UpdateWindow(hwnd);
       return 0L;

    case WM_PAINT:
    {
       PAINTSTRUCT ps;
       RECT   rc;
       char   ach[128];
       int    len, nxBorder, nyBorder;
       HFONT  hOldFont = NULL;

       BeginPaint(hwnd, &ps);

       GetClientRect(hwnd,&rc);

       nxBorder = GetSystemMetrics(SM_CXBORDER);
       rc.left  += 9*nxBorder;
       rc.right -= 9*nxBorder;

       nyBorder = GetSystemMetrics(SM_CYBORDER);
       rc.top    += 3*nyBorder;
       rc.bottom -= 3*nyBorder;

       // 3D Text
       len = GetWindowText(hwnd, ach, sizeof(ach));
       SetBkColor(ps.hdc, GetSysColor(COLOR_BTNFACE));

       SetBkMode(ps.hdc, TRANSPARENT);
       SetTextColor(ps.hdc, RGB(64,96,96));
       if (hFont)
           hOldFont = SelectObject(ps.hdc, hFont);
       ExtTextOut(ps.hdc, rc.left+2*nxBorder+2, rc.top+2,
                  ETO_OPAQUE | ETO_CLIPPED, &rc, ach, len, NULL);

       SetTextColor(ps.hdc, RGB(128,128,128));
       if (hFont)
           hOldFont = SelectObject(ps.hdc, hFont);
       ExtTextOut(ps.hdc, rc.left+2*nxBorder+1, rc.top+1, ETO_CLIPPED,
                   &rc, ach, len, NULL);

       SetTextColor(ps.hdc, RGB(255,255,255));
       if (hFont)
           hOldFont = SelectObject(ps.hdc, hFont);
       ExtTextOut(ps.hdc, rc.left+2*nxBorder, rc.top, ETO_CLIPPED,
                   &rc, ach, len, NULL);

       SetBkMode(ps.hdc, OPAQUE);

       if (hOldFont)
           SelectObject(ps.hdc, hOldFont);

       EndPaint(hwnd, &ps);
       return 0L;
       }
    }
    return DefWindowProc(hwnd, message, wParam, lParam);
}


//---------------------------------------------------------------------------
//
// FUNCTION:    GetStringRes (int id INPUT ONLY)
//
// COMMENTS:    Load the resource string with the ID given, and return a
//              pointer to it.  Notice that the buffer is common memory so
//              the string must be used before this call is made a second time.
//
//---------------------------------------------------------------------------

LPTSTR GetStringRes (int id)
{
  static TCHAR buffer[MAX_PATH];

  buffer[0]=0;
  LoadString (GetModuleHandle (NULL), id, buffer, MAX_PATH);
  return buffer;
}

⌨️ 快捷键说明

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