remnet.c
来自「wince下的源代码集合打包」· C语言 代码 · 共 1,669 行 · 第 1/4 页
C
1,669 行
return TRUE;}// InitListViewItems - adds items and subitems to a list view.// Returns TRUE if successful or FALSE otherwise.// hwndLV - handle of the list view control// pfData - text file containing list view items with columns// separated by semicolonsBOOL WINAPIInitListViewItems(HWND hwndLV){ int iItem; // Item we're working on LV_ITEM lvi; // Current Item structure DWORD cb; // Number of bytes in RasEntryName list. LPRASENTRYNAME lpRasEntries; // Pointer to the RasEntries. DWORD cEntries; // Number of Entries found DWORD Index; PITEMINFO pItemInfo; ListView_DeleteAllItems (hwndLV); // Initialize LV_ITEM members that are common to all items. lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE; lvi.state = LVIS_SELECTED | LVIS_FOCUSED; lvi.stateMask = 0; lvi.pszText = LPSTR_TEXTCALLBACK; // app. maintains text lvi.iImage = 0; // image list index lvi.iItem = 0; lvi.iSubItem = 0; lvi.lParam = (LPARAM) 0; // item data // Add the item. ListView_InsertItem(hwndLV, &lvi); lvi.state = 0; // The rest of the items are not selected. // Now get the current RasEntryNames RasEnumEntries (NULL, NULL, NULL, &cb, NULL); if (cb) { // Now we have to do something with the list. lpRasEntries = (LPRASENTRYNAME)LocalAlloc (LPTR, cb); if (!RasEnumEntries (NULL, NULL, lpRasEntries, &cb, &cEntries)) { // Walk the list iItem = 1; for ( Index = 0; Index < cEntries; Index++) { if (lpRasEntries[Index].szEntryName[0] == TEXT('`')) { DEBUGMSG (1, (TEXT("Skipping entry \"%s\"\r\n"), lpRasEntries[Index].szEntryName)); continue; } pItemInfo = (PITEMINFO)LocalAlloc (LPTR, sizeof(ITEMINFO)); memset ((char *)pItemInfo, 0, sizeof(ITEMINFO)); _tcscpy (pItemInfo->EntryName, lpRasEntries[Index].szEntryName); // Get the Entry properties. cb = sizeof(pItemInfo->Entry); pItemInfo->Entry.dwSize = sizeof(RASENTRY); if (RasGetEntryProperties (NULL, pItemInfo->EntryName, &(pItemInfo->Entry), &cb, NULL, NULL)) { LocalFree (pItemInfo); continue; } // This should use lineTranslateAddress to get a pretty version // But should handle VPN and Direct entries nicely. _tcsncpy (pItemInfo->szPhone, pItemInfo->Entry.szLocalPhoneNumber, sizeof(pItemInfo->szPhone)/sizeof(TCHAR)); // Initialize item-specific LV_ITEM members. lvi.iItem = iItem++; lvi.iSubItem = 0; lvi.lParam = (LPARAM) pItemInfo; // save item data lvi.iImage = _tcscmp (pItemInfo->Entry.szDeviceType, RASDT_Direct) ? 1 : 2; // Add the item. ListView_InsertItem(hwndLV, &lvi); lvi.state = 0; // The rest of the items are not selected. } } // Free the RasEntry info LocalFree ((HLOCAL)lpRasEntries); } return TRUE;} BOOLInitInstance(HINSTANCE hInstance, int nCmdShow){ RECT rc; HICON hIcon; HMENU hMenu = NULL; int rv, nWidth, nHeight, x, y; v_hInst = hInstance; // OK, create the window, taking the position of the SIP into account nWidth = CW_USEDEFAULT; nHeight = CW_USEDEFAULT; x = y = CW_USEDEFAULT;#ifdef USE_SIP if (g_pSipGetInfo) { SIPINFO si; memset(&si, 0, sizeof(SIPINFO)); si.cbSize = sizeof(si); if((*g_pSipGetInfo)(&si) ) { nWidth = si.rcVisibleDesktop.right - si.rcVisibleDesktop.left; nHeight = si.rcVisibleDesktop.bottom - si.rcVisibleDesktop.top; x = si.rcVisibleDesktop.left; y = si.rcVisibleDesktop.top; } }#endif v_hMainWnd = CreateWindowEx(0, szAppName, szTitle, WS_CLIPCHILDREN, x, y, nWidth, nHeight, NULL, hMenu, hInstance, NULL); if ( v_hMainWnd == 0 ) { return (FALSE); } // Set remnets icon for the task bar hIcon = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REMOTENW), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); SendMessage(v_hMainWnd, WM_SETICON, FALSE, (WPARAM)hIcon); DEBUGMSG (ZONE_MISC, (TEXT("After CreateWindowEx\r\n"))); GetClientRect (v_hMainWnd, &rc); v_hCmdBar = CallCommCtrlFunc(CommandBar_Create) (hInstance, v_hMainWnd, 1); if (v_fPortrait) { CallCommCtrlFunc(CommandBar_InsertMenubar)(v_hCmdBar, hInstance, IDR_PORTRAIT_MENU, 0); } else { CallCommCtrlFunc(CommandBar_InsertMenubar)(v_hCmdBar, hInstance, IDR_MAIN_MENU, 0); } // NOTE: Add the command buttons CallCommCtrlFunc(CommandBar_AddBitmap)(v_hCmdBar, HINST_COMMCTRL, IDB_VIEW_SMALL_COLOR, 12, 16, 16); CallCommCtrlFunc(CommandBar_AddBitmap)(v_hCmdBar, HINST_COMMCTRL, IDB_STD_SMALL_COLOR, 15, 16, 16); if (!v_fPortrait) { CommandBar_AddButtons(v_hCmdBar, sizeof(tbButton)/sizeof(TBBUTTON), tbButton); LoadString(v_hInst, IDS_TLTP_NON, nonStr, sizeof(nonStr)); LoadString(v_hInst, IDS_TLTP_DELETE, deleteStr, sizeof(deleteStr)); LoadString(v_hInst, IDS_TLTP_PRPTY, propertiesStr, sizeof(propertiesStr)); LoadString(v_hInst, IDS_TLTP_LARGE, largeIconStr, sizeof(largeIconStr)); LoadString(v_hInst, IDS_TLTP_SMOLL, smallIconStr, sizeof(smallIconStr)); LoadString(v_hInst, IDS_TLTP_DETAILS, detailsStr, sizeof(detailsStr)); CommandBar_AddToolTips(v_hCmdBar, 6, (LPARAM)ToolTipsTbl); CallCommCtrlFunc(CommandBar_AddAdornments)(v_hCmdBar, STD_HELP, ID_FILE_EXIT); SendMessage (v_hCmdBar, TB_CHECKBUTTON, ID_VIEW_LARGEICON, MAKELONG(TRUE, 0)); // Set the default view checkbox hMenu = CallCommCtrlFunc(CommandBar_GetMenu)(v_hCmdBar, 0); CheckMenuRadioItem(hMenu, ID_VIEW_LARGEICON, ID_VIEW_DETAILS, ID_VIEW_LARGEICON, MF_BYCOMMAND); } else { rv = CallCommCtrlFunc(CommandBar_AddBitmap)(v_hCmdBar, v_hInst, IDB_TOOLBAR, 2, 16, 16); tbButtonPortrait[1].iBitmap = rv+1;// tbButtonPortrait[3].iBitmap = rv; CommandBar_AddButtons(v_hCmdBar, sizeof(tbButtonPortrait)/sizeof(TBBUTTON), tbButtonPortrait); LoadString(v_hInst, IDS_TLTP_NON, nonStr, sizeof(nonStr)); LoadString(v_hInst, IDS_TLTP_CONNECT, largeIconStr, sizeof(largeIconStr)); LoadString(v_hInst, IDS_TLTP_EDIT, smallIconStr, sizeof(smallIconStr)); LoadString(v_hInst, IDS_TLTP_DELETEP, propertiesStr, sizeof(propertiesStr)); CommandBar_AddToolTips(v_hCmdBar, 4, (LPARAM)ToolTipsTblPortrait); CallCommCtrlFunc(CommandBar_AddAdornments)(v_hCmdBar, STD_HELP, ID_CONN_EXIT); } rc.top += CallCommCtrlFunc(CommandBar_Height)(v_hCmdBar); v_hListWnd = CreateWindow (WC_LISTVIEW, TEXT(""), WS_VISIBLE|WS_CHILD|WS_VSCROLL| LVS_SHOWSELALWAYS|LVS_AUTOARRANGE| 0x0040|LVS_EDITLABELS| LVS_ICON, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, v_hMainWnd, (HMENU)IDD_LISTVIEW, v_hInst, NULL); if ( v_hListWnd == 0 ) { return (FALSE); } if (!InitListViewImageLists(v_hListWnd) || !InitListViewColumns(v_hListWnd) || !InitListViewItems(v_hListWnd)) { DestroyWindow(v_hListWnd); return FALSE; } ShowWindow(v_hMainWnd, SW_SHOW); UpdateWindow(v_hMainWnd); // Focus in on the list view. SetFocus (v_hListWnd); return TRUE;}void LoadSIP(void){#ifdef USE_SIP if( (g_hSipLib = LoadLibrary( TEXT("coredll.dll") )) && (g_pSipStatus = (LPFNSIPSTATUS)GetProcAddress( g_hSipLib, TEXT("SipStatus"))) && (g_pSipGetInfo = (LPFNSIP)GetProcAddress( g_hSipLib, TEXT("SipGetInfo"))) && (g_pSipSetInfo = (LPFNSIP)GetProcAddress( g_hSipLib, TEXT("SipSetInfo"))) && (SIP_STATUS_AVAILABLE == g_pSipStatus()) ) { DEBUGMSG(1, (L"REMNET: Using SIP!\r\n")); } else { g_pSipStatus = NULL; g_pSipGetInfo = NULL; g_pSipSetInfo = NULL; if(g_hSipLib) FreeLibrary(g_hSipLib); }#endif}int WINAPIWinMain(HINSTANCE hInstance, HINSTANCE hInstPrev, LPWSTR pszCmdLine, int nCmdShow){ MSG msg; HWND hPrevWind; HANDLE hAccelTable; DEBUGREGISTER(0); if (GetSystemMetrics(SM_CXSCREEN) < 480) { v_fPortrait = TRUE; } // Check if SIP is present LoadSIP();#ifdef DEBUG // Scan command line { while (*pszCmdLine) { // Skip leading blanks while (' ' == *pszCmdLine) { pszCmdLine++; } if ('\0' == *pszCmdLine) { break; } if ((TEXT('-') == *pszCmdLine) || (TEXT('/') == *pszCmdLine)) { pszCmdLine++; while ((TEXT(' ') != *pszCmdLine) && (TEXT('\0') != *pszCmdLine)) { switch (*pszCmdLine) { case 'p' : case 'P' : v_fPortrait = TRUE; break; case 'l' : case 'L' : v_fPortrait = FALSE; break; case 'd' : case 'D' : // Get debug flag dpCurSettings.ulZoneMask = 0; pszCmdLine++; while ((TEXT('0') <= *pszCmdLine) && (TEXT('9') >= *pszCmdLine)) { dpCurSettings.ulZoneMask *= 10; dpCurSettings.ulZoneMask += *pszCmdLine - TEXT('0'); pszCmdLine++; } pszCmdLine--; DEBUGMSG (1, (TEXT("New ulZoneMask=%d\r\n"), dpCurSettings.ulZoneMask)); break; default : DEBUGMSG (1, (TEXT("Unknown switch '%s'\r\n"), pszCmdLine)); break; } pszCmdLine++; } } else { DEBUGMSG (1, (TEXT("Bad commandline parm '%s'\r\n"), pszCmdLine)); break; } } }#endif LoadString(hInstance, (v_fPortrait) ? IDS_CONNECTIONS : IDS_TITLE, szTitle, sizeof(szTitle) / sizeof(TCHAR)); if (hPrevWind = FindWindow (szAppName, szTitle)) { SetForegroundWindow((HWND) ((ULONG) hPrevWind | 0x00000001)); return FALSE; } if (!InitCommCtrlTable()) { DEBUGMSG (ZONE_ERROR, (TEXT("Unable to load commctrl.dll\r\n"))); return FALSE; } CallCommCtrlFunc(InitCommonControls)(); { INITCOMMONCONTROLSEX icce; icce.dwSize = sizeof(INITCOMMONCONTROLSEX); icce.dwICC = ICC_TOOLTIP_CLASSES|ICC_CAPEDIT_CLASS; CallCommCtrlFunc(InitCommonControlsEx)(&icce); } if ( hInstPrev != 0 ) { return FALSE; } DEBUGMSG (ZONE_MISC, (TEXT("About to InitApplication\r\n"))); if ( InitApplication(hInstance) == FALSE ) { return(FALSE); } DEBUGMSG (ZONE_MISC, (TEXT("About to InitInstance\r\n"))); if ( InitInstance(hInstance, nCmdShow) == FALSE ) { // Unregister IP class window UnregisterIPClass(hInstance); return(FALSE); } if (v_fPortrait) { // Update dialogs ID table with small version. v_DialogPages[DLG_PG_1] = IDD_RAS_WIZ_1P; v_DialogPages[DLG_PG_2] = IDD_RAS_WIZ_2P; v_DialogPages[DLG_PG_3] = IDD_RAS_WIZ_3P; v_DialogPages[DLG_PG_4] = IDD_RAS_WIZ_4P; v_DialogPages[DLG_PG_5] = IDD_RAS_WIZ_5P; v_DialogPages[DLG_TCP_GEN] = IDD_RAS_TCPIP_GENP; v_DialogPages[DLG_TCP_NS] = IDD_RAS_TCPIP_NAME_SERVP; } hAccelTable = LoadAccelerators (hInstance,TEXT("REMNET_ACCEL")); SetMenu(); DEBUGMSG (ZONE_MISC, (TEXT("About to enter GetMessage Loop\r\n"))); while ( GetMessage(&msg, NULL, 0, 0) != FALSE ) { if (v_hDialogWnd && IsDialogMessage (v_hDialogWnd, &msg)) { continue; } if (v_fInRename || !TranslateAccelerator (v_hMainWnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } // Unregister IP class window UnregisterIPClass(hInstance); DEBUGMSG (ZONE_MISC, (TEXT("Exiting WinMain\r\n"))); return(msg.wParam);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?