// Tab 制表符 BOOL CTestScript::PreTranslateMessage(MSG* pMsg) { // TODO: 在此添加专用代码和/或调用基类 switch( pMsg->message ) { case WM_KEYDOWN: { if(pMsg->wParam ==VK_TAB) { CString str; CPoint pt; pt = GetCaretPos(); m_edScriptEdit.GetWindowText(str); m_edScriptEdit.ReplaceSel("\t"); m_edScriptEdit.SetSel(-1,0); //取消正文的选择 return TRUE; } else if (pMsg->wParam == VK_LEFT) { this->OnBnClickedButtonStartLogin(); return true; } } } return CDialog::PreTranslateMessage(pMsg); }
void CTitleTimeEdit::KeyInDel() { int nCharPos = CharFromPos(GetCaretPos()); int nSelStart = 0; int nSelEnd = 0; GetSel(nSelStart, nSelEnd); if(nSelStart == nSelEnd) { if(nCharPos < 12) { m_szTimeChar[nCharPos] = s_szDefTMChar[nCharPos]; nCharPos ++; if(s_szDefTMChar[nCharPos] != '0') nCharPos ++; } } else { DeleteRange(nSelStart, nSelEnd); } Update(); SetSel(nCharPos, nCharPos); }
/** * @author ACM2012 * @note 限制光标移动本函数在按下键盘按键时触发,主要限制光标移动; *屏蔽光标的向上向下移动,位于提示行光标向左移动时,不得超过约定的范围,该范围由输入 *的提示符显示长度决定 */ void CmdView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: 在此添加消息处理程序代码和/或调用默认值 CPoint point; int nline; switch (nChar) { /** *@brief 直接返回,屏蔽光标上下移动 */ case VK_UP: case VK_DOWN: case VK_HOME: return; /** *@brief 监听光标左移 */ case VK_LEFT: point = GetCaretPos(); //禁止光标移动到command区域: nline = myedit->CharFromPos(point); /** *@brief 如果超过光标能移动的范围,返回 */ if (point.x <= HintPLen&&HIWORD(nline)==HintLine) return; default: break; } CEditView::OnKeyDown(nChar, nRepCnt, nFlags); }
void CSelection::UpdateCaretPosition() const { RECT rcView; m_pView->GetViewRect( &rcView ); if ( GetFocus() == m_hWnd && !m_pCtrl->DelayPaint() ) { int yCaret = rcView.top + ( ( m_nEndRow - m_pView->GetTopIndex() ) * m_pView->GetLineHeight() ); int cxLeftMargin = m_pView->GetLeftMargin( TRUE, TRUE ); int xCaret = rcView.left + cxLeftMargin + ( ( m_nEndViewCol - m_pView->GetLeftIndex() ) * m_pView->GetCharWidth() ); if ( m_pCtrl->ShowHScrollBar() && ( ( ( yCaret + m_cyCaret ) > rcView.bottom ) || ( yCaret < rcView.top ) ) ) { // don't let the caret draw over the scrollbars yCaret = -m_cyCaret - 1; } if ( ( xCaret < rcView.left + cxLeftMargin ) || ( m_pCtrl->ShowVScrollBar() && ( ( ( xCaret + m_cxCaret ) > rcView.right ) || ( xCaret < rcView.left ) ) ) ) { // don't let the caret draw over the scrollbars xCaret = -m_cxCaret - 1; } POINT pt; GetCaretPos( &pt ); if ( pt.x != xCaret || pt.y != yCaret ) { VERIFY( SetCaretPos( xCaret, yCaret ) ); } } }
bool CHSNumEdit::CheckInput (UINT nChar) { // checks no digit or dots before a minus sign // and no more than m_digits after '.' int pos = CharFromPos(GetCaretPos()); CString txt; GetWindowText(txt); int len = txt.GetLength(); //////// no digits or dot before a minus sign int sign = txt.Find('-'); if ( pos <= sign ) return false; //// no dot before m_digit from end of string int dot = txt.ReverseFind('.'); if ( dot == -1 ) { // no dot - check position before accepting if ( pos >= len -m_digits ) return true; //else // return false; } /////// limit digits after '.' if ( len - pos < dot) { // no insert if // there is more than m_digits digits after zero. if ( pos -dot > m_digits ) return false; // the insert will cause the same if ( len - dot> m_digits) return false; } return true; }
void CTitleTimeEdit::KeyInNumeric(UINT nChar) { int nCharPos = CharFromPos(GetCaretPos()); int nSelStart = 0; int nSelEnd = 0; GetSel(nSelStart, nSelEnd); if(nSelStart == nSelEnd) { if(nCharPos < 12) { if((s_szDefTMChar[nCharPos] == '0') &&(nChar <= (UINT)s_szMaxTMChar[nCharPos])) { m_szTimeChar[nCharPos] = nChar; } nCharPos ++; if(s_szDefTMChar[nCharPos] != '0') nCharPos ++; } } else { if((s_szDefTMChar[nSelStart] == '0') &&(nChar <= (UINT)s_szMaxTMChar[nCharPos])) { m_szTimeChar[nSelStart] = nChar; } } Update(); SetSel(nCharPos, nCharPos); }
static void hugsprim_GetCaretPos_42(HugsStackPtr hugs_root) { HsPtr arg1; HsBool res1; arg1 = hugs->getPtr(); res1 = GetCaretPos(arg1); hugs->putBool(res1); hugs->returnIO(hugs_root,1); }
void NativeTextfieldWin::OnContextMenu(HWND window, const gfx::Point& point) { POINT p = point.ToPOINT(); if(p.x==-1 || p.y==-1) { GetCaretPos(&p); MapWindowPoints(HWND_DESKTOP, &p, 1); } BuildContextMenu(); context_menu_->RunContextMenuAt(gfx::Point(p)); }
//im --- override to over the spot composition void AwtTextComponent::SetCompositionWindow(RECT& rc) { HIMC hIMC = ImmGetContext(); // rc is not used for text component. COMPOSITIONFORM cf = { CFS_POINT, {0,0}, {0,0,0,0} }; GetCaretPos(&(cf.ptCurrentPos)); ImmSetCompositionWindow(hIMC, &cf); LOGFONT lf; GetObject(m_hFont, sizeof(LOGFONT), &lf); ImmSetCompositionFont(hIMC, &lf); }
void fastPoll( void ) { RANDOM_STATE randomState; BYTE buffer[ RANDOM_BUFSIZE ]; SYSHEAPINFO sysHeapInfo; MEMMANINFO memManInfo; TIMERINFO timerInfo; POINT point; initRandomData( randomState, buffer, RANDOM_BUFSIZE ); /* Get various basic pieces of system information: Handle of the window with mouse capture, handle of window with input focus, amount of space in global heap, whether system queue has any events, cursor position for last message, 55 ms time for last message, number of active tasks, 55 ms time since Windows started, current mouse cursor position, current caret position */ addRandomValue( randomState, GetCapture() ); addRandomValue( randomState, GetFocus() ); addRandomValue( randomState, GetFreeSpace( 0 ) ); addRandomValue( randomState, GetInputState() ); addRandomValue( randomState, GetMessagePos() ); addRandomValue( randomState, GetMessageTime() ); addRandomValue( randomState, GetNumTasks() ); addRandomValue( randomState, GetTickCount() ); GetCursorPos( &point ); addRandomData( randomState, &point, sizeof( POINT ) ); GetCaretPos( &point ); addRandomData( randomState, &point, sizeof( POINT ) ); /* Get the largest free memory block, number of lockable pages, number of unlocked pages, number of free and used pages, and number of swapped pages */ memManInfo.dwSize = sizeof( MEMMANINFO ); MemManInfo( &memManInfo ); addRandomData( randomState, &memManInfo, sizeof( MEMMANINFO ) ); /* Get the execution times of the current task and VM to approximately 1ms resolution */ timerInfo.dwSize = sizeof( TIMERINFO ); TimerCount( &timerInfo ); addRandomData( randomState, &timerInfo, sizeof( TIMERINFO ) ); /* Get the percentage free and segment of the user and GDI heap */ sysHeapInfo.dwSize = sizeof( SYSHEAPINFO ); SystemHeapInfo( &sysHeapInfo ); addRandomData( randomState, &sysHeapInfo, sizeof( SYSHEAPINFO ) ); /* Flush any remaining data through */ endRandomData( randomState, 25 ); }
void CUrlRichEditCtrl::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) { if (nChar == VK_APPS) { m_ptContextMenu = GetCaretPos(); // does this location lie on a url? m_nContextUrl = FindUrl(m_ptContextMenu); // convert point to screen coords ClientToScreen(&m_ptContextMenu); } CRichEditBaseCtrl::OnKeyUp(nChar, nRepCnt, nFlags); }
void CmdView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: 在此添加消息处理程序代码和/或调用默认值 ///<brief 处理回退键 if (VK_BACK == nChar){ ///<限制删除范围 CPoint point; int num; num = myedit->GetLineCount(); point = GetCaretPos(); if (point.x <= HintPLen&&num - 1 == HintLine) return; } ///<brief 处理回车键 if (VK_RETURN == nChar) ///<处理回车消息 DealEnter(); CEditView::OnChar(nChar, nRepCnt, nFlags); }
void CUrlRichEditCtrl::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { if (nChar == VK_F10 && GetKeyState(VK_SHIFT)) { m_ptContextMenu = GetCaretPos(); // does this location lie on a url? m_nContextUrl = FindUrl(m_ptContextMenu); // convert point to screen coords ClientToScreen(&m_ptContextMenu); // eat message else we'll get a WM_KEYUP with VK_APPS } CRichEditBaseCtrl::OnSysKeyDown(nChar, nRepCnt, nFlags); }
void WeaselIME::_UpdateInputPosition(LPINPUTCONTEXT lpIMC, POINT pt) { EZDBGONLYLOGGERPRINT("_UpdateInputPosition: (%d, %d)", pt.x, pt.y); //EZDBGONLYLOGGERPRINT("cfCompForm: ptCurrentPos = (%d, %d), rcArea = (%d, %d)", // lpIMC->cfCompForm.ptCurrentPos.x, lpIMC->cfCompForm.ptCurrentPos.y, // lpIMC->cfCompForm.rcArea.left, lpIMC->cfCompForm.rcArea.top); //EZDBGONLYLOGGERPRINT("cfCandForm[0]: ptCurrentPos = (%d, %d), rcArea = (%d, %d)", // lpIMC->cfCandForm[0].ptCurrentPos.x, lpIMC->cfCandForm[0].ptCurrentPos.y, // lpIMC->cfCandForm[0].rcArea.left, lpIMC->cfCandForm[0].rcArea.top); //EZDBGONLYLOGGERPRINT("cfCandForm[1]: ptCurrentPos = (%d, %d), rcArea = (%d, %d)", // lpIMC->cfCandForm[1].ptCurrentPos.x, lpIMC->cfCandForm[1].ptCurrentPos.y, // lpIMC->cfCandForm[1].rcArea.left, lpIMC->cfCandForm[1].rcArea.top); if (pt.x == -1 && pt.y == -1) { EZDBGONLYLOGGERPRINT("Caret pos detection required."); if(!GetCaretPos(&pt)) { EZDBGONLYLOGGERPRINT("Failed to determine caret pos."); pt.x = pt.y = 0; } } ClientToScreen(lpIMC->hWnd, &pt); if (pt.x < -4096 || pt.x >= 4096 || pt.y < -4096 || pt.y >= 4096) { EZDBGONLYLOGGERPRINT("Input position out of range, possibly invalid."); return; } int height = abs(lpIMC->lfFont.W.lfHeight); if (height == 0) { HDC hDC = GetDC(lpIMC->hWnd); SIZE sz = {0}; GetTextExtentPoint(hDC, L"A", 1, &sz); height = sz.cy; ReleaseDC(lpIMC->hWnd, hDC); } const int width = 6; RECT rc; SetRect(&rc, pt.x, pt.y, pt.x + width, pt.y + height); EZDBGONLYLOGGERPRINT("Updating input position: (%d, %d)", pt.x, pt.y); m_client.UpdateInputPosition(rc); }
//im --- override to over the spot composition void AwtTextComponent::SetCompositionWindow(RECT& rc) { HWND hwnd = ImmGetHWnd(); HIMC hIMC = ImmGetContext(hwnd); // rc is not used for text component. COMPOSITIONFORM cf = { CFS_FORCE_POSITION, {0,0}, {0,0,0,0} }; GetCaretPos(&(cf.ptCurrentPos)); // the proxy is the native focus owner and it contains the composition window // let's convert the position to a coordinate space relative to proxy ::MapWindowPoints(GetHWnd(), GetProxyFocusOwner(), (LPPOINT)&cf.ptCurrentPos, 1); ImmSetCompositionWindow(hIMC, &cf); LOGFONT lf; GetObject(m_hFont, sizeof(LOGFONT), &lf); ImmSetCompositionFont(hIMC, &lf); ImmReleaseContext(hwnd, hIMC); }
/************************************************************************ * * SetIMECompFormPos * ************************************************************************/ void SetIMECompFormPos( HWND hWnd ) { HIMC hIMC = ImmGetContext(hWnd); POINT point = {0}; COMPOSITIONFORM CompForm; GetCaretPos( &point ); CompForm.dwStyle = CFS_POINT; CompForm.ptCurrentPos.x = (long) point.x; CompForm.ptCurrentPos.y = (long) point.y; if ( hIMC ) ImmSetCompositionWindow(hIMC,&CompForm); ImmReleaseContext( hWnd , hIMC); }
// // AdjustCandWnd() // void AdjustCandWnd(HWND hCandWnd, LPUIPRIV lpUIPriv, LPINPUTCONTEXT lpIMC) { //LPUIPRIV lpUIPriv; POINT ptNew; GetWorkArea(&g_sImeUIG.rcWorkArea); if (GetCaretPos(&ptNew)){ ClientToScreen(lpIMC->hWnd, &ptNew); murmur("AdjustCandWnd() ptNew.x = %d, ptNew.y = %d, rcWorkArea.bottom = %d, nCandHi=%d\n", ptNew.x, ptNew.y, g_sImeUIG.rcWorkArea.bottom, lpUIPriv->nCandHi); if( ( g_sImeUIG.rcWorkArea.bottom - ptNew.y < 2*lpUIPriv->nCandHi ) && ( g_sImeUIG.rcWorkArea.bottom - ptNew.y >0 ) && ptNew.y < g_sImeUIG.rcWorkArea.bottom ){ ptNew.y -= lpUIPriv->nCandHi; } else ptNew.y = g_sImeUIG.rcWorkArea.bottom - lpUIPriv->nCandHi; } else ptNew.y = g_sImeUIG.rcWorkArea.bottom - lpUIPriv->nCandHi; ptNew.x = 0; murmur("AdjustCandWnd() ptNew.x = %d, ptNew.y = %d\n", ptNew.x, ptNew.y); InvalidateRect(hCandWnd, NULL, FALSE); lpUIPriv->rcCandText.right = g_sImeUIG.rcWorkArea.right -g_sImeUIG.nCandCharWi *2; if (ptNew.x != lpUIPriv->ptCand.x || ptNew.y != lpUIPriv->ptCand.y || g_sImeUIG.rcWorkArea.right != lpUIPriv->nCandWi ) { lpUIPriv->ptCand = ptNew; lpUIPriv->nCandWi = g_sImeUIG.rcWorkArea.right; SetWindowPos(hCandWnd, NULL, ptNew.x, ptNew.y, g_sImeUIG.rcWorkArea.right, g_sImeUIG.nCandLineHi, SWP_NOACTIVATE|SWP_NOZORDER); } return; }
void RichEdit::Stop() { m_stopped++; if (m_stopped != 1) return; SuspendUndo(); SendMessage(WM_SETREDRAW, FALSE, 0); SendMessage(EM_GETSCROLLPOS, 0, (LPARAM)&m_old_scroll_pos); SendMessage(EM_EXGETSEL, 0, (LPARAM)&m_old_sel); GetCaretPos(&m_caretPos); m_old_mask = SendMessage(EM_GETEVENTMASK, 0, 0); SendMessage(EM_SETEVENTMASK, 0, m_old_mask & ~ENM_CHANGE); m_inverse = (m_old_sel.cpMin >= LOWORD(SendMessage(EM_CHARFROMPOS, 0, (LPARAM)&m_caretPos))); }
static int winListGetCaretPos(HWND cbedit) { int pos = 0; POINT point; if (GetFocus() != cbedit || !GetCaretPos(&point)) { /* if does not have the focus, or could not get caret position, then use the selection start position */ SendMessage(cbedit, EM_GETSEL, (WPARAM)&pos, 0); } else { pos = SendMessage(cbedit, EM_CHARFROMPOS, 0, MAKELPARAM(point.x, point.y)); pos = LOWORD(pos); } return pos; }
void CSelection::UpdateCaretPosition() const { ASSERT( m_pView ); RECT rcView; m_pView->GetViewRect( &rcView ); if ( GetFocus() == m_hWnd && !m_pCtrl->DelayPaint() ) { int yCaret = rcView.top + ( ( m_nEndRow - m_pView->GetTopIndex() ) * m_pView->GetLineHeight() ); int cxLeftMargin = m_pView->GetLeftMargin( TRUE, TRUE ); int xCaret = rcView.left + cxLeftMargin + ( ( m_nEndViewCol - m_pView->GetLeftIndex() ) * m_pView->GetCharWidth() ); if ( m_pCtrl->ShowHScrollBar() && ( ( ( yCaret + m_cyCaret ) > rcView.bottom ) || ( yCaret < rcView.top ) ) ) { // don't let the caret draw over the scrollbars yCaret = -m_cyCaret - 1; } if ( ( xCaret < rcView.left + cxLeftMargin ) || ( m_pCtrl->ShowVScrollBar() && ( ( ( xCaret + m_cxCaret ) > rcView.right ) || ( xCaret < rcView.left ) ) ) ) { // don't let the caret draw over the scrollbars xCaret = -m_cxCaret - 1; } POINT pt; GetCaretPos( &pt ); if ( pt.x != xCaret || pt.y != yCaret ) { if (!SetCaretPos (xCaret, yCaret)) { // this seems to work around a bug in a HTML Help version that causes SetCaretPos to // fail with a 0x05 (permission denied) error, even though CreateCaret had succeeded // and the window had focus. maybe it was stealing the caret back after CreateCaret ? VERIFY (CreateCaret (m_hWnd, NULL, m_cxCaret, m_cyCaret)) ; VERIFY (SetCaretPos (xCaret, yCaret)) ; } } } }
//********************************************************************** // // void ImeUIMove() // // Handler routine of WM_MOVE message. // //********************************************************************* void ImeUIMoveCandWin( HWND hwnd ) { if ( gImeUIData.ImeState & IME_IN_CHOSECAND ) { POINT point; // Storage for caret position. int i; // loop counter. int NumCandWin; // Storage for num of cand win. RECT rect; // Storage for client rect. // // If current IME state is in chosing candidate, here we // move all candidate windows, if any, to the appropriate // position based on the parent window's position. // NumCandWin = 0; GetCaretPos( &point ); ClientToScreen( hwnd, &point ); for ( i = 0; i < MAX_LISTCAND ; i++ ) { if ( gImeUIData.hListCand[ i ] ) { GetClientRect( gImeUIData.hListCand[ i ], &rect ); MoveWindow( gImeUIData.hListCand[ i ], point.x + X_INDENT * NumCandWin, point.y + Y_INDENT * NumCandWin + cyMetrics, ( rect.right - rect.left + 1 ), ( rect.bottom - rect.top + 1 ), TRUE ); NumCandWin++; } } } }
void CConstraintEditDialog::insertFuncString() { if(!m_editExpression) { return; } CPoint caret = GetCaretPos(); int curpos = c_expredit.CharFromPos(caret); CString selfun; int cursel = m_funclist.GetCurSel(); int len = m_funclist.GetTextLen(cursel); m_funclist.GetText(cursel, selfun.GetBuffer(len+2) ); c_expredit.ReplaceSel(selfun); if(selfun!=_T("self") && selfun!=_T("children")) c_expredit.ReplaceSel(_T("()")); if(selfun==_T("children") || selfun==_T("project().Materials")) { c_expredit.ReplaceSel(_T("(\"\")")); } c_expredit.SetFocus(); }
void CTitleTimeEdit::KeyInDown() { int nCharPos = CharFromPos(GetCaretPos()); if(nCharPos < 3) { if(m_szTimeChar[1] > '0') m_szTimeChar[1] --; else if(m_szTimeChar[1] == '0') { if(m_szTimeChar[0] > '0') { m_szTimeChar[0] --; m_szTimeChar[1] = s_szMaxTMChar[1]; } } } else if(nCharPos < 6) { if(m_szTimeChar[4] > '0') m_szTimeChar[4] --; else if(m_szTimeChar[4] == '0') { if(m_szTimeChar[3] > '0') { m_szTimeChar[3] --; m_szTimeChar[4] = s_szMaxTMChar[4]; } } } else if(nCharPos < 9) { if(m_szTimeChar[7] > '0') m_szTimeChar[7] --; else if(m_szTimeChar[7] == '0') { if(m_szTimeChar[6] > '0') { m_szTimeChar[6] --; m_szTimeChar[7] = s_szMaxTMChar[7]; } } } else { if(m_szTimeChar[11] > '0') m_szTimeChar[11] --; else if(m_szTimeChar[11] == '0') { if(m_szTimeChar[10] > '0') { m_szTimeChar[10] --; m_szTimeChar[11] = s_szMaxTMChar[11]; } else if(m_szTimeChar[10] == '0') { if(m_szTimeChar[9] > '0') { m_szTimeChar[9] --; m_szTimeChar[10] = s_szMaxTMChar[10]; m_szTimeChar[11] = s_szMaxTMChar[11]; } } } } Update(); SetSel(nCharPos, nCharPos); }
// IMN_OPENCANDIDATE: BOOL CImeView::OpenCandidate(LONG lParam) { LPCANDIDATELIST lpCandList = NULL; // Storage for LP to candidate list. DWORD dwBufLen; // Storage for candidate strings. LPSTR lpStr; // Storage for LP to a string. int max_width = 0; // Storage for width of listCand int CurNumCandList = 0; // Storage for number of cand. lists. DWORD dwPreferNumPerPage; // Storage for PreferNumPerPage // POINT point; // Storage for caret position. if (!Enter()) return FALSE; // SetWindowText(hwnd, (LPSTR)TITLE_CAND); for (int i = 0; i < MAX_LISTCAND; i++ ) { if (m_hwndCand[i]) CurNumCandList++; } for (int index = 0; index < MAX_LISTCAND; index++ ) { if (lParam & (1 << index)) { if (!(dwBufLen = ImmGetCandidateList(m_hIMC, index, lpCandList, 0))) goto exit_opencand; if( !(m_CandList[index] = (LPCANDIDATELIST)new char[dwBufLen])) goto exit_opencand; lpCandList = m_CandList[index]; ImmGetCandidateList(m_hIMC, index, lpCandList, dwBufLen); POINT pt ; GetCaretPos(&pt); ClientToScreen(m_hWnd,&pt); dwPreferNumPerPage = ( !lpCandList->dwPageSize ) ? DEFAULT_CAND_NUM_PER_PAGE : lpCandList->dwPageSize; // get the longest string length for (int i = 0; i < (int)lpCandList->dwCount; i++ ) { lpStr = (LPSTR)lpCandList + lpCandList->dwOffset[i]; max_width = (max_width < lstrlen(lpStr)) ? lstrlen(lpStr) : max_width; } m_hwndCand[index] = CreateWindow( "HanjaCandidate", "CandWindow", WS_BORDER | WS_POPUP | WS_DISABLED, CurNumCandList * m_charWidth + pt.x, pt.y + m_charHeight + 2, (max_width + 3) * m_charWidth + 4, (int)dwPreferNumPerPage * m_charHeight + 5, m_hWnd, (HMENU)NULL, (HINSTANCE)GetWindowLong(m_hWnd, GWL_HINSTANCE ), (LPVOID)NULL ); if (m_hwndCand[index] == NULL) { delete m_CandList[index]; m_CandList[index] = NULL; goto exit_opencand; } SetWindowLong(m_hwndCand[index], 0, (LONG)this); ::ShowWindow(m_hwndCand[index], SW_SHOWNOACTIVATE); DisplayCandStrings(m_hwndCand[index], lpCandList); CurNumCandList++; } } m_nState |= IME_IN_CHOSECAND; exit_opencand: Leave(); return TRUE; }
wxRect FixedLine::GetFoldIndicatorRect() const { const unsigned int lastpos = textend - textstart; wxPoint point = GetCaretPos(lastpos); return wxRect(point.x, point.y, m_foldWidth, charheight); }
//********************************************************************** // // void ImeUIOpenCandidate() // // This handles WM_IME_NOTIFY message with wParam = IMN_OPENCANDIDATE. // //********************************************************************** void ImeUIOpenCandidate( HWND hwnd, LPARAM CandList ) { HIMC hIMC; // Input context handle. LPCANDIDATELIST lpCandList; // Storage for LP to candidate list. CANDIDATELIST tempCandList; // Storage for LP to candidate list. DWORD bufLen; // Storage for candidate strings. LPSTR lpStr; // Storage for LP to a string. DWORD dwIndex; // Storage for index of ListCand array DWORD i; // Loop count. int width = 0; // Storage for width of listCand int CurNumCandList = 0; // Storage for number of cand. lists. DWORD dwPreferNumPerPage; // Storage for PreferNumPerPage POINT point; // Storage for caret position. // // If fail to get input context handle, do nothing. // if ( ! (hIMC = ImmGetContext( hwnd ) ) ) return; // // Change caption title to DBCS candidate mode. // SetWindowText( hwnd, szSteCandTitle ); // // Find out how many candidate windows have already been opened. // for( i = 0; i < MAX_LISTCAND; i++ ) { if ( gImeUIData.hListCand[ i ] ) { CurNumCandList++; } } // // Check which candidate lists should be displayed by loopping // through all possible candidate lists. // for( dwIndex = 0; dwIndex < MAX_LISTCAND ; dwIndex ++ ) { if ( CandList & ( 1 << dwIndex ) ) { // // The dwIndex-th candidate list contains candidate strings. // So here we want to display them. // // // Determines how musch memory space should be allocated to // read in the corresponding candidate list . // if ( ! ( bufLen = ImmGetCandidateList( hIMC, dwIndex, &tempCandList, 0 ) ) ) goto exit2; // // Allocate memory space. // if( !( gImeUIData.hListCandMem[ dwIndex ] = GlobalAlloc( LPTR, (int)bufLen ) ) ) goto exit2; if( !( lpStr = (LPSTR)GlobalLock( gImeUIData.hListCandMem[ dwIndex ] ) ) ) { GlobalFree( gImeUIData.hListCandMem[ dwIndex ] ); gImeUIData.hListCandMem[ dwIndex ] = NULL; goto exit2; } lpCandList = (LPCANDIDATELIST) lpStr; // // Reads in the corresponding candidate list. // ImmGetCandidateList( hIMC, dwIndex, lpCandList, bufLen ); // // Get current caret position. // GetCaretPos( (POINT *)&point ); ClientToScreen( hwnd, &point ); // // Determines how many candidate strings per page. // dwPreferNumPerPage = ( !lpCandList->dwPageSize ) ? DEFAULT_CAND_NUM_PER_PAGE : lpCandList->dwPageSize; // // Determining maximum character length the list box // will display by loopping through all candidate strings. // for( i = 0; i < lpCandList->dwCount; i++ ) { // // Get the pointer to i-th candidate string. // lpStr = (LPSTR)lpCandList + lpCandList->dwOffset[ i ]; width = ( width < lstrlen( lpStr ) ) ? lstrlen( lpStr ) : width; } // // Create a candidate window for the candidate list. // gImeUIData.hListCand[ dwIndex ] = CreateWindow( szCandClass, NULL, WS_BORDER | WS_POPUP | WS_DISABLED, CurNumCandList * X_INDENT + point.x, CurNumCandList * Y_INDENT + point.y + cyMetrics, ( width ) * cxMetrics + 10, (int)(dwPreferNumPerPage) * cyMetrics + 5, hwnd, NULL, (HINSTANCE)GetWindowLongPtr( hwnd, GWLP_HINSTANCE ), NULL ); // // If fail to create the candidate window then do nothing. // if ( gImeUIData.hListCand[ dwIndex ] < 0 ) { GlobalUnlock( gImeUIData.hListCandMem[ dwIndex ] ); GlobalFree( gImeUIData.hListCandMem[ dwIndex ] ); goto exit2; } // // Show candidate window. // ShowWindow( gImeUIData.hListCand[ dwIndex ], SW_SHOWNOACTIVATE ); // // Display candidate strings. // DisplayCandStrings( gImeUIData.hListCand[ dwIndex ], lpCandList ); GlobalUnlock( gImeUIData.hListCandMem[ dwIndex ] ); CurNumCandList++; } } // // Reset IME state. // gImeUIData.ImeState |= IME_IN_CHOSECAND; exit2: ImmReleaseContext( hwnd, hIMC ); }
void CTitleTimeEdit::KeyInUp() { int nCharPos = CharFromPos(GetCaretPos()); if(nCharPos < 3) { if(m_szTimeChar[1] < s_szMaxTMChar[1]) m_szTimeChar[1] ++; else if(m_szTimeChar[1] == s_szMaxTMChar[1]) { if(m_szTimeChar[0] < s_szMaxTMChar[0]) { m_szTimeChar[0] ++; m_szTimeChar[1] = '0'; } } } else if(nCharPos < 6) { if(m_szTimeChar[4] < s_szMaxTMChar[4]) m_szTimeChar[4] ++; else if(m_szTimeChar[4] == s_szMaxTMChar[4]) { if(m_szTimeChar[3] < s_szMaxTMChar[3]) { m_szTimeChar[3] ++; m_szTimeChar[4] = '0'; } } } else if(nCharPos < 9) { if(m_szTimeChar[7] < s_szMaxTMChar[7]) m_szTimeChar[7] ++; else if(m_szTimeChar[7] == s_szMaxTMChar[7]) { if(m_szTimeChar[6] < s_szMaxTMChar[6]) { m_szTimeChar[6] ++; m_szTimeChar[7] = '0'; } } } else { if(m_szTimeChar[11] < s_szMaxTMChar[11]) m_szTimeChar[11] ++; else if(m_szTimeChar[11] == s_szMaxTMChar[11]) { if(m_szTimeChar[10] < s_szMaxTMChar[10]) { m_szTimeChar[10] ++; m_szTimeChar[11] = '0'; } else if(m_szTimeChar[10] == s_szMaxTMChar[10]) { if(m_szTimeChar[9] < s_szMaxTMChar[9]) { m_szTimeChar[9] ++; m_szTimeChar[10] = '0'; m_szTimeChar[11] = '0'; } } } } Update(); SetSel(nCharPos, nCharPos); }
/** * Win32 poll using stats functions including Tooltip32 */ void Win32_EntropySource::poll(Entropy_Accumulator& accum) { /* First query a bunch of basic statistical stuff, though don't count it for much in terms of contributed entropy. */ accum.add(GetTickCount(), 0); accum.add(GetMessagePos(), 0); accum.add(GetMessageTime(), 0); accum.add(GetInputState(), 0); accum.add(GetCurrentProcessId(), 0); accum.add(GetCurrentThreadId(), 0); SYSTEM_INFO sys_info; GetSystemInfo(&sys_info); accum.add(sys_info, 1); MEMORYSTATUS mem_info; GlobalMemoryStatus(&mem_info); accum.add(mem_info, 1); POINT point; GetCursorPos(&point); accum.add(point, 1); GetCaretPos(&point); accum.add(point, 1); LARGE_INTEGER perf_counter; QueryPerformanceCounter(&perf_counter); accum.add(perf_counter, 0); /* Now use the Tooltip library to iterate throug various objects on the system, including processes, threads, and heap objects. */ HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); #define TOOLHELP32_ITER(DATA_TYPE, FUNC_FIRST, FUNC_NEXT) \ if(!accum.polling_finished()) \ { \ DATA_TYPE info; \ info.dwSize = sizeof(DATA_TYPE); \ if(FUNC_FIRST(snapshot, &info)) \ { \ do \ { \ accum.add(info, 1); \ } while(FUNC_NEXT(snapshot, &info)); \ } \ } TOOLHELP32_ITER(MODULEENTRY32, Module32First, Module32Next); TOOLHELP32_ITER(PROCESSENTRY32, Process32First, Process32Next); TOOLHELP32_ITER(THREADENTRY32, Thread32First, Thread32Next); #undef TOOLHELP32_ITER if(!accum.polling_finished()) { size_t heap_lists_found = 0; HEAPLIST32 heap_list; heap_list.dwSize = sizeof(HEAPLIST32); const size_t HEAP_LISTS_MAX = 32; const size_t HEAP_OBJS_PER_LIST = 128; if(Heap32ListFirst(snapshot, &heap_list)) { do { accum.add(heap_list, 1); if(++heap_lists_found > HEAP_LISTS_MAX) break; size_t heap_objs_found = 0; HEAPENTRY32 heap_entry; heap_entry.dwSize = sizeof(HEAPENTRY32); if(Heap32First(&heap_entry, heap_list.th32ProcessID, heap_list.th32HeapID)) { do { if(heap_objs_found++ > HEAP_OBJS_PER_LIST) break; accum.add(heap_entry, 1); } while(Heap32Next(&heap_entry)); } if(accum.polling_finished()) break; } while(Heap32ListNext(snapshot, &heap_list)); } } CloseHandle(snapshot); }
/* This is the fastpoll function which gathers up info by calling various api's */ BOOL FastPoll (void) { int nOriginalRandIndex = nRandIndex; static BOOL addedFixedItems = FALSE; FILETIME creationTime, exitTime, kernelTime, userTime; SIZE_T minimumWorkingSetSize, maximumWorkingSetSize; LARGE_INTEGER performanceCount; MEMORYSTATUS memoryStatus; HANDLE handle; POINT point; /* Get various basic pieces of system information */ RandaddIntPtr (GetActiveWindow ()); /* Handle of active window */ RandaddIntPtr (GetCapture ()); /* Handle of window with mouse capture */ RandaddIntPtr (GetClipboardOwner ()); /* Handle of clipboard owner */ RandaddIntPtr (GetClipboardViewer ()); /* Handle of start of clpbd.viewer list */ RandaddIntPtr (GetCurrentProcess ()); /* Pseudohandle of current process */ RandaddInt32 (GetCurrentProcessId ()); /* Current process ID */ RandaddIntPtr (GetCurrentThread ()); /* Pseudohandle of current thread */ RandaddInt32 (GetCurrentThreadId ()); /* Current thread ID */ RandaddInt32 (GetCurrentTime ()); /* Milliseconds since Windows started */ RandaddIntPtr (GetDesktopWindow ()); /* Handle of desktop window */ RandaddIntPtr (GetFocus ()); /* Handle of window with kb.focus */ RandaddInt32 (GetInputState ()); /* Whether sys.queue has any events */ RandaddInt32 (GetMessagePos ()); /* Cursor pos.for last message */ RandaddInt32 (GetMessageTime ()); /* 1 ms time for last message */ RandaddIntPtr (GetOpenClipboardWindow ()); /* Handle of window with clpbd.open */ RandaddIntPtr (GetProcessHeap ()); /* Handle of process heap */ RandaddIntPtr (GetProcessWindowStation ()); /* Handle of procs window station */ RandaddInt32 (GetQueueStatus (QS_ALLEVENTS)); /* Types of events in input queue */ /* Get multiword system information */ GetCaretPos (&point); /* Current caret position */ RandaddBuf ((unsigned char *) &point, sizeof (POINT)); GetCursorPos (&point); /* Current mouse cursor position */ RandaddBuf ((unsigned char *) &point, sizeof (POINT)); /* Get percent of memory in use, bytes of physical memory, bytes of free physical memory, bytes in paging file, free bytes in paging file, user bytes of address space, and free user bytes */ memoryStatus.dwLength = sizeof (MEMORYSTATUS); GlobalMemoryStatus (&memoryStatus); RandaddBuf ((unsigned char *) &memoryStatus, sizeof (MEMORYSTATUS)); /* Get thread and process creation time, exit time, time in kernel mode, and time in user mode in 100ns intervals */ handle = GetCurrentThread (); GetThreadTimes (handle, &creationTime, &exitTime, &kernelTime, &userTime); RandaddBuf ((unsigned char *) &creationTime, sizeof (FILETIME)); RandaddBuf ((unsigned char *) &exitTime, sizeof (FILETIME)); RandaddBuf ((unsigned char *) &kernelTime, sizeof (FILETIME)); RandaddBuf ((unsigned char *) &userTime, sizeof (FILETIME)); handle = GetCurrentProcess (); GetProcessTimes (handle, &creationTime, &exitTime, &kernelTime, &userTime); RandaddBuf ((unsigned char *) &creationTime, sizeof (FILETIME)); RandaddBuf ((unsigned char *) &exitTime, sizeof (FILETIME)); RandaddBuf ((unsigned char *) &kernelTime, sizeof (FILETIME)); RandaddBuf ((unsigned char *) &userTime, sizeof (FILETIME)); /* Get the minimum and maximum working set size for the current process */ GetProcessWorkingSetSize (handle, &minimumWorkingSetSize, &maximumWorkingSetSize); RandaddIntPtr (minimumWorkingSetSize); RandaddIntPtr (maximumWorkingSetSize); /* The following are fixed for the lifetime of the process so we only add them once */ if (addedFixedItems == 0) { STARTUPINFO startupInfo; /* Get name of desktop, console window title, new window position and size, window flags, and handles for stdin, stdout, and stderr */ startupInfo.cb = sizeof (STARTUPINFO); GetStartupInfo (&startupInfo); RandaddBuf ((unsigned char *) &startupInfo, sizeof (STARTUPINFO)); addedFixedItems = TRUE; } /* The docs say QPC can fail if appropriate hardware is not available. It works on 486 & Pentium boxes, but hasn't been tested for 386 or RISC boxes */ if (QueryPerformanceCounter (&performanceCount)) RandaddBuf ((unsigned char *) &performanceCount, sizeof (LARGE_INTEGER)); else { /* Millisecond accuracy at best... */ DWORD dwTicks = GetTickCount (); RandaddBuf ((unsigned char *) &dwTicks, sizeof (dwTicks)); } // CryptoAPI: We always have a valid CryptoAPI context when we arrive here but // we keep the check for clarity purpose if ( !CryptoAPIAvailable ) return FALSE; if (CryptGenRandom (hCryptProv, sizeof (buffer), buffer)) { RandaddBuf (buffer, sizeof (buffer)); burn (buffer, sizeof(buffer)); } else { /* return error in case CryptGenRandom fails */ CryptoAPILastError = GetLastError (); return FALSE; } /* Apply the pool mixing function */ Randmix(); /* Restore the original pool cursor position. If this wasn't done, mouse coordinates could be written to a limited area of the pool, especially when moving the mouse uninterruptedly. The severity of the problem would depend on the length of data written by FastPoll (if it was equal to the size of the pool, mouse coordinates would be written only to a particular 4-byte area, whenever moving the mouse uninterruptedly). */ nRandIndex = nOriginalRandIndex; return TRUE; }
int _gcry_rndw32_gather_random_fast (void (*add)(const void*, size_t, int), int requester ) { static int addedFixedItems = 0; if ( debug_me ) log_debug ("rndw32#gather_random_fast: req=%d\n", requester ); /* Get various basic pieces of system information: Handle of active * window, handle of window with mouse capture, handle of clipboard owner * handle of start of clpboard viewer list, pseudohandle of current * process, current process ID, pseudohandle of current thread, current * thread ID, handle of desktop window, handle of window with keyboard * focus, whether system queue has any events, cursor position for last * message, 1 ms time for last message, handle of window with clipboard * open, handle of process heap, handle of procs window station, types of * events in input queue, and milliseconds since Windows was started */ { byte buffer[20*sizeof(ulong)], *bufptr; bufptr = buffer; #define ADD(f) do { ulong along = (ulong)(f); \ memcpy (bufptr, &along, sizeof (along) ); \ bufptr += sizeof (along); } while (0) ADD ( GetActiveWindow ()); ADD ( GetCapture ()); ADD ( GetClipboardOwner ()); ADD ( GetClipboardViewer ()); ADD ( GetCurrentProcess ()); ADD ( GetCurrentProcessId ()); ADD ( GetCurrentThread ()); ADD ( GetCurrentThreadId ()); ADD ( GetDesktopWindow ()); ADD ( GetFocus ()); ADD ( GetInputState ()); ADD ( GetMessagePos ()); ADD ( GetMessageTime ()); ADD ( GetOpenClipboardWindow ()); ADD ( GetProcessHeap ()); ADD ( GetProcessWindowStation ()); ADD ( GetQueueStatus (QS_ALLEVENTS)); ADD ( GetTickCount ()); assert ( bufptr-buffer < sizeof (buffer) ); (*add) ( buffer, bufptr-buffer, requester ); #undef ADD } /* Get multiword system information: Current caret position, current * mouse cursor position */ { POINT point; GetCaretPos (&point); (*add) ( &point, sizeof (point), requester ); GetCursorPos (&point); (*add) ( &point, sizeof (point), requester ); } /* Get percent of memory in use, bytes of physical memory, bytes of free * physical memory, bytes in paging file, free bytes in paging file, user * bytes of address space, and free user bytes */ { MEMORYSTATUS memoryStatus; memoryStatus.dwLength = sizeof (MEMORYSTATUS); GlobalMemoryStatus (&memoryStatus); (*add) ( &memoryStatus, sizeof (memoryStatus), requester ); } /* Get thread and process creation time, exit time, time in kernel mode, and time in user mode in 100ns intervals */ { HANDLE handle; FILETIME creationTime, exitTime, kernelTime, userTime; DWORD minimumWorkingSetSize, maximumWorkingSetSize; handle = GetCurrentThread (); GetThreadTimes (handle, &creationTime, &exitTime, &kernelTime, &userTime); (*add) ( &creationTime, sizeof (creationTime), requester ); (*add) ( &exitTime, sizeof (exitTime), requester ); (*add) ( &kernelTime, sizeof (kernelTime), requester ); (*add) ( &userTime, sizeof (userTime), requester ); handle = GetCurrentProcess (); GetProcessTimes (handle, &creationTime, &exitTime, &kernelTime, &userTime); (*add) ( &creationTime, sizeof (creationTime), requester ); (*add) ( &exitTime, sizeof (exitTime), requester ); (*add) ( &kernelTime, sizeof (kernelTime), requester ); (*add) ( &userTime, sizeof (userTime), requester ); /* Get the minimum and maximum working set size for the current process */ GetProcessWorkingSetSize (handle, &minimumWorkingSetSize, &maximumWorkingSetSize); (*add) ( &minimumWorkingSetSize, sizeof (minimumWorkingSetSize), requester ); (*add) ( &maximumWorkingSetSize, sizeof (maximumWorkingSetSize), requester ); } /* The following are fixed for the lifetime of the process so we only * add them once */ if (!addedFixedItems) { STARTUPINFO startupInfo; /* Get name of desktop, console window title, new window position and * size, window flags, and handles for stdin, stdout, and stderr */ startupInfo.cb = sizeof (STARTUPINFO); GetStartupInfo (&startupInfo); (*add) ( &startupInfo, sizeof (STARTUPINFO), requester ); addedFixedItems = 1; } /* The performance of QPC varies depending on the architecture it's * running on and on the OS. Under NT it reads the CPU's 64-bit timestamp * counter (at least on a Pentium and newer '486's, it hasn't been tested * on anything without a TSC), under Win95 it reads the 1.193180 MHz PIC * timer. There are vague mumblings in the docs that it may fail if the * appropriate hardware isn't available (possibly '386's or MIPS machines * running NT), but who's going to run NT on a '386? */ { LARGE_INTEGER performanceCount; if (QueryPerformanceCounter (&performanceCount)) { if ( debug_me ) log_debug ("rndw32#gather_random_fast: perf data\n"); (*add) (&performanceCount, sizeof (performanceCount), requester); } else { /* Millisecond accuracy at best... */ DWORD aword = GetTickCount (); (*add) (&aword, sizeof (aword), requester ); } } return 0; }