CMainWindow
Microsoft Windows 作業系統會將下列使用者動作轉譯為標準視窗訊息,並將其傳送至 StoClien 應用程式中的主要程式:
- 使用者按一下滑鼠左鍵或平板電腦裝置中的手寫筆提示切換,以起始線條繪製順序。
- 使用者按一下並按住按鈕,並移動滑鼠以繪製線條。
- 當放開滑鼠左鍵時,序列就會結束。
下列範例程式碼說明此程式。
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);
}
當WM_LBUTTONDOWN訊息傳遞滑鼠位置資料時,線條繪製順序就會開始。
CMainWindow 具有 CGuiPaper 物件的指標,並呼叫 CGuiPaper::InkStart 方法來啟動線條繪製順序。
當滑鼠移動以繪製時,會將包含滑鼠位置資料的個別 WM_MOUSEMOVE 訊息序列提供給 CGuiPaper::InkDraw 方法。
放開滑鼠左鍵時,會收到 WM_LBUTTONUP 訊息。 CGuiPaper::InkStop方法會停止線條繪製順序。