unsigned long RegisterTimer(int milisecond, P2PTimerProc callback, void* pParam, int nRepeatTime) { struct time_node* pTimerNode; struct time_node* pTemp; Position it, itPrev; pTimerNode = (struct time_node*)malloc(sizeof(struct time_node)); pTimerNode->pPtr = pParam; pTimerNode->OnTimer = callback; pTimerNode->ulNextTime = get_tick_count() + milisecond; pTimerNode->nRemainCount = nRepeatTime; pTimerNode->ulID = g_ulTimerSeq++; pTimerNode->nInterval = milisecond; lstLock(g_timer); it = lstFirst(g_timer); itPrev = lstHeader(g_timer); while(it != NULL) { pTemp = (struct time_node*)lstRetrieve(it); if(pTemp->ulNextTime > pTimerNode->ulNextTime) break; itPrev = it; it = lstAdvance(it); } lstInsert(g_timer, pTimerNode, itPrev); lstUnLock(g_timer); NotifyHandler(); return pTimerNode->ulID; }
/* * This method calls NotifyHandler for sending the XMPP stanza to the Handler * and puts the parser in a new state for parsing the next stanza or for * expecting a prolog/root element when it encounters the proceed or success * stanza. */ bool XMPPXMLParser::HandleXMPPStanza() { bool continueParsing = true; const unsigned proceedLiteral[] = { L'p', L'r', L'o', L'c', L'e', L'e', L'd', 0 }; const unsigned successLiteral[] = { L's', L'u', L'c', L'c', L'e', L's', 0 }; const unsigned compressedLiteral[] = { L'c', L'o', L'm', L'p', L'r', L'e', L's', L's', L'e', L'd', 0 }; continueParsing = NotifyHandler(m_ElementName); if(m_ElementName.find(proceedLiteral) != UTF32String::npos || m_ElementName.find(successLiteral) != UTF32String::npos || m_ElementName.find(compressedLiteral) != UTF32String::npos) { RestartParser(); } else { m_ParsingState = ParsingXMPPStanzaBegin; m_ParsedData.clear(); } return continueParsing; }
/* * Method: OnExit() * Purpose: called when the thread is terminating * Comments: none */ void CSeeker::OnExit() { NotifyHandler(kEvnSeekerFinished,iFound); }
/* * Method: OnEntry() * Purpose: called when the thread is starting * Comments: none */ void CSeeker::OnEntry() { NotifyHandler(kEvnSeekerStarted); }
LONG APIENTRY MainWndProc( HWND hWnd, /* window handle */ UINT message, /* type of message */ UINT wParam, /* additional information */ LONG lParam) /* additional information */ { static HWND hWndListView; DWORD dwStyle; switch (message) { case WM_CREATE: hWndListView = CreateListView( hWnd ); if (hWndListView == NULL) MessageBox (NULL, "Listview not created!", NULL, MB_OK ); break; case WM_NOTIFY: return( NotifyHandler(hWnd, message, wParam, lParam)); break; case WM_COMMAND: switch( LOWORD( wParam )) { case IDM_LARGEICON: dwStyle = GetWindowLong(hWndListView, GWL_STYLE); if ((dwStyle & LVS_TYPEMASK) != LVS_ICON) SetWindowLong(hWndListView, GWL_STYLE, (dwStyle & ~LVS_TYPEMASK) | LVS_ICON); break; case IDM_SMALLICON: dwStyle = GetWindowLong(hWndListView, GWL_STYLE); if ((dwStyle & LVS_TYPEMASK) != LVS_SMALLICON) SetWindowLong(hWndListView, GWL_STYLE, (dwStyle & ~LVS_TYPEMASK) | LVS_SMALLICON); break; case IDM_LISTVIEW: dwStyle = GetWindowLong(hWndListView, GWL_STYLE); if ((dwStyle & LVS_TYPEMASK) != LVS_LIST) SetWindowLong(hWndListView, GWL_STYLE, (dwStyle & ~LVS_TYPEMASK) | LVS_LIST); break; case IDM_REPORTVIEW: dwStyle = GetWindowLong(hWndListView, GWL_STYLE); if ((dwStyle & LVS_TYPEMASK) != LVS_REPORT) SetWindowLong(hWndListView, GWL_STYLE, (dwStyle & ~LVS_TYPEMASK) | LVS_REPORT); break; case IDM_EXIT: PostQuitMessage(0); break; case IDM_ABOUT: DialogBox(hInst, "AboutBox", hWnd, (DLGPROC)About); break; default: return (DefWindowProc(hWnd, message, wParam, lParam)); } break; case WM_SIZE: MoveWindow(hWndListView, 0, 0, LOWORD(lParam),HIWORD(lParam),TRUE); break; case WM_DESTROY: /* message: window being destroyed */ PostQuitMessage(0); break; default: return (DefWindowProc(hWnd, message, wParam, lParam)); } return (0); }
// // Main window procedure // LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { int width, height, heightsb; HIMAGELIST hImgList; RECT rect; HDWP hdwp; NMHDR *nmhdr; TCHAR msgstr[MAX_PATH+200]; switch(msg) { case WM_CREATE: g_hwndTextView = CreateTextView(hwnd); g_hwndStatusbar = CreateStatusBar(hwnd); TextView_SetContextMenu(g_hwndTextView, GetSubMenu(LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(IDR_MENU2)), 0)); // load the image list hImgList = ImageList_LoadImage( GetModuleHandle(0), MAKEINTRESOURCE(IDB_BITMAP1), 16, 0, RGB(255,0,255), IMAGE_BITMAP, LR_LOADTRANSPARENT|LR_CREATEDIBSECTION ); TextView_SetImageList(g_hwndTextView, hImgList); // highlight specific lines with image-index "1" //TextView_SetLineImage(g_hwndTextView, 16, 1); //TextView_SetLineImage(g_hwndTextView, 5, 1); //TextView_SetLineImage(g_hwndTextView, 36, 1); //TextView_SetLineImage(g_hwndTextView, 11, 1); // tell windows that we can handle drag+drop'd files DragAcceptFiles(hwnd, TRUE); return 0; case WM_DROPFILES: HandleDropFiles(hwnd, (HDROP)wParam); return 0; case WM_DESTROY: SaveFileData(g_szFileName, hwnd); PostQuitMessage(0); DeleteObject(g_hFont); return 0; //case WM_NCCALCSIZE: // return NcCalcSize(hwnd, wParam, lParam); case WM_INITMENU: CheckMenuCommand((HMENU)wParam, IDM_VIEW_LINENUMBERS, g_fLineNumbers); CheckMenuCommand((HMENU)wParam, IDM_VIEW_LONGLINES, g_fLongLines); CheckMenuCommand((HMENU)wParam, IDM_VIEW_SAVEEXIT, g_fSaveOnExit); CheckMenuCommand((HMENU)wParam, IDM_VIEW_STATUSBAR, g_fShowStatusbar); //CheckMenuCommand((HMENU)wParam, IDM_VIEW_SEARCHBAR, g_hwndSearchBar ? TRUE : FALSE); EnableMenuCommand((HMENU)wParam, IDM_EDIT_UNDO, TextView_CanUndo(g_hwndTextView)); EnableMenuCommand((HMENU)wParam, IDM_EDIT_REDO, TextView_CanRedo(g_hwndTextView)); EnableMenuCommand((HMENU)wParam, IDM_EDIT_PASTE, IsClipboardFormatAvailable(CF_TEXT)); EnableMenuCommand((HMENU)wParam, IDM_EDIT_COPY, TextView_GetSelSize(g_hwndTextView)); EnableMenuCommand((HMENU)wParam, IDM_EDIT_CUT, TextView_GetSelSize(g_hwndTextView)); EnableMenuCommand((HMENU)wParam, IDM_EDIT_DELETE, TextView_GetSelSize(g_hwndTextView)); return 0; //case WM_USER: // wsprintf(msgstr, _T("%s\n\nThis file has been modified outside of Neatpad.") // _T("Do you wish to reload it?"), g_szFileName); // MessageBox(hwnd, msgstr, _T("Neatpad"), MB_ICONQUESTION|MB_YESNO); // // return 0; case WM_ENABLE: // keep the modeless find/replace dialog in the same enabled state as the main window EnableWindow(g_hwndSearchDlg, (BOOL)wParam); return 0; case WM_MENUSELECT: StatusBarMenuSelect(hwnd, g_hwndStatusbar, wParam, lParam); return 0; case WM_NOTIFY: nmhdr = (NMHDR *)lParam; if(nmhdr->hwndFrom == g_hwndTextView) return TextViewNotifyHandler(hwnd, nmhdr); else return NotifyHandler(hwnd, nmhdr); case WM_COMMAND: return CommandHandler(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); case WM_SETFOCUS: SetFocus(g_hwndTextView); return 0; case WM_CLOSE: // does the file need saving? if(TextView_CanUndo(g_hwndTextView)) { UINT r; wsprintf(msgstr, _T("Do you want to save changes to\r\n%s?"), g_szFileName); r = MessageBox(hwnd, msgstr, APP_TITLE, MB_YESNOCANCEL | MB_ICONQUESTION); if(r == IDCANCEL) return 0; } DestroyWindow(hwnd); return 0; case WM_SIZE: // resize the TextView and StatusBar to fit within the main window's client area width = (short)LOWORD(lParam); height = (short)HIWORD(lParam); GetWindowRect(g_hwndStatusbar, &rect); heightsb = rect.bottom-rect.top; hdwp = BeginDeferWindowPos(3); if(g_fShowStatusbar) { DeferWindowPos(hdwp, g_hwndStatusbar, 0, 0, height - heightsb, width, heightsb, SWP_SHOWWINDOW); // MoveWindow(g_hwndStatusbar, 0, height - heightsb, width, heightsb, TRUE); height -= heightsb; } DeferWindowPos(hdwp, g_hwndTextView, 0, 0, 0, width, height, SWP_SHOWWINDOW); //MoveWindow(g_hwndTextView, 0, 0, width, height, TRUE); EndDeferWindowPos(hdwp); SetStatusBarParts(g_hwndStatusbar); return 0; } return DefWindowProc(hwnd, msg, wParam, lParam); }