Baca dalam bahasa Inggris

Bagikan melalui


CMainWindow

Sistem operasi Microsoft Windows menerjemahkan tindakan pengguna berikut ke dalam pesan jendela standar dan mengirimkannya ke prosedur utama dalam aplikasi StoClien :

  • Pengguna mengklik tombol mouse kiri, atau tombol ujung pena di perangkat tablet, untuk memulai urutan gambar garis.
  • Pengguna mengklik dan menahan tombol dan menggerakkan mouse untuk menggambar garis.
  • Urutan berakhir ketika tombol mouse kiri dilepaskan.

Contoh kode berikut mengilustrasikan prosedur ini.

CMainWindow::WindowProc (STOCLIEN. CPP)

LRESULT CMainWindow::WindowProc(
            UINT uMsg,
            WPARAM wParam,
            LPARAM lParam)
  {
    LRESULT lResult = FALSE;

    switch (uMsg)
    {
      case WM_CREATE:
        break;

      case WM_ACTIVATE:
        // A mouse click reactivates the paint procedure.
        // This is used to paint a new window when a user
        // selects a portion of the STOCLIEN window that is 
        // visible beneath another window. This message is  
        // sent in the WindowProc handle.
        if (WA_CLICKACTIVE == LOWORD(wParam))
          m_pGuiPaper->PaintWin();
        lResult = ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);
        break;

      case WM_SIZE:
        // Handle a resize of this window.
        m_wWidth = LOWORD(lParam);
        m_wHeight = HIWORD(lParam);
        // Inform CGuiPaper of the change.
        m_pGuiPaper->Resize(m_wWidth, m_wHeight);
        break;

      case WM_PAINT:
        // This is a message to repaint the window.
        {
          PAINTSTRUCT ps;

          if(BeginPaint(m_hWnd, &ps))
            EndPaint(m_hWnd, &ps);

          m_pGuiPaper->PaintWin();
        }
        break;

      case WM_LBUTTONDOWN:
        // Start sequence of ink drawing to the paper.
        m_pGuiPaper->InkStart(LOWORD(lParam), HIWORD(lParam));
        break;

      case WM_MOUSEMOVE:
        // Draw inking sequence data.
        m_pGuiPaper->InkDraw(LOWORD(lParam), HIWORD(lParam));
        break;

      case WM_LBUTTONUP:
        // Stop an ink drawing sequence.
        m_pGuiPaper->InkStop(LOWORD(lParam), HIWORD(lParam));
        break;

      case WM_COMMAND:
        // Dispatch and handle any Menu command messages received.
        lResult = DoMenu(wParam, lParam);
        break;

      case WM_CHAR:
        if (wParam == 0x1b)
        {
          // Exit this application if user presses the ESC key.
          ::PostMessage(m_hWnd, WM_CLOSE, 0, 0);
        }
        break;

      case WM_CLOSE:
        // The user selected Close on the main window System menu
        // or Exit on the File menu.
        // If there is unsaved ink data, then prompt
        // the user. If the user cancels, do not close the window.
        if (IDCANCEL == m_pGuiPaper->AskSave())
          break;
      case WM_QUIT:
        // When exiting the application, close any associated help
        // windows.
        // ::WinHelp(m_hWnd, m_szHelpFile, HELP_QUIT, 0);
      default:
        // If there are any messages that have not been handled,
        // send them to the default window procedure.
        lResult = ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);
        break;
    }

    return(lResult);
  }

Urutan gambar garis dimulai saat pesan WM_LBUTTONDOWN mengirimkan data posisi mouse.

CMainWindow memiliki penunjuk ke objek CGuiPaper dan memanggil metode CGuiPaper::InkStart untuk memulai urutan gambar garis.

Saat mouse dipindahkan untuk menggambar, urutan pesan WM_MOUSEMOVE terpisah yang berisi data posisi mouse disediakan ke metode CGuiPaper::InkDraw .

Ketika tombol mouse kiri dilepaskan, pesan WM_LBUTTONUP diterima. Metode CGuiPaper::InkStop menghentikan urutan gambar garis.