dùng lớp CHtmlView
Hi everyone !
Mình đã cố gắng tìm kiếm trên mạng rồi, nhưng ra toàn kết quả linh tinh thôi. Mong các bạn giúp chút.
Tớ muốn muốn mở một trang web từ ứng dụng của mình. Ví dụ trong app có 1 cái button mà nhấn vào đó là nó bật ngay trình duyệt ( nếu là trình duyệt mặc định thì càng tốt ) để xem trang chủ của mình.
Thankz !
dùng lớp CHtmlView
Đã được chỉnh sửa lần cuối bởi vinhie47 : 10-02-2007 lúc 12:27 AM.
Here are some predefined error ids:Code:#include <windows.h> #include <shellapi.h> #include <tchar.h> #define NOT ! #define EXIT_SUCCESS 0 #define EXIT_FAILURE 1 int WINAPI _tWinMain (HINSTANCE hInstance, HINSTANCE hNotUse, LPTSTR lpszCmdLine, int nCmdShow) { TCHAR szDefaultBrowserFolder[] = TEXT("C:\\Program Files\\Internet Explorer"); TCHAR szDefaultBrowserName[] = TEXT("iexplore.exe"); TCHAR szDefaultWebsite[] = TEXT("congdongcviet.com"); TCHAR szOperation[] = TEXT("open"); HINSTANCE hBrowserInstance = ShellExecute (NULL, szOperation, szDefaultBrowserName, szDefaultWebsite, szDefaultBrowserFolder, SW_SHOWDEFAULT); int nResult = int (hBrowserInstance); BOOL bSuccess = (nResult > 32); if (NOT bSuccess) { //Check nResutl's value for error id MessageBox (NULL, TEXT("Cannot run the requested program!"), TEXT("Error"), MB_OK | MB_ICONERROR); return EXIT_FAILURE; } return EXIT_SUCCESS; }
Code:0 The operating system is out of memory or resources. ERROR_FILE_NOT_FOUND The specified file was not found. 2 ERROR_PATH_NOT_FOUND The specified path was not found. 3 ERROR_BAD_FORMAT The .exe file is invalid (non-Microsoft Win32 .exe or error in .exe image). 11 SE_ERR_FNF 2 SE_ERR_PNF 3 SE_ERR_ACCESSDENIED 5 SE_ERR_OOM 8 SE_ERR_DLLNOTFOUND 32 SE_ERR_SHARE 26 SE_ERR_ASSOCINCOMPLETE 27 SE_ERR_DDETIMEOUT 28 SE_ERR_DDEFAIL 29 SE_ERR_DDEBUSY 30 SE_ERR_NOASSOC 31
Our dreams are young and we both know they take us where we want to go...
Cảm ơn ilovecplusplus nhiều lắm. Mặc dù nó chỉ chạy IE, nếu mày người ta set Firefox mặc định thì nó vẫn chạy IE. Dù sao tế cũng tốt lắm rồi. => very good.
Nếu ai mà cao tay hơn, thì cho xin code mà nó bật trình duyệt mặc định lên thì excellent.
Code:#include <windows.h> #include <tchar.h> #include <cstdlib> #include <iostream> #include <string> #define SIZE_LIMIT 16300 //in bytes #ifdef UNICODE #define tstring wstring #define tcout wcout #else #define tcout cout #define tstring string #endif using namespace std; int _tmain(void) { TCHAR szSubKey[] = TEXT("HTTP\\shell\\open\\command"); //or HTTPS... TCHAR szBuffer[SIZE_LIMIT]; LONG cbBufferSize = SIZE_LIMIT * sizeof(TCHAR); //this because the buffer size specified in bytes LONG nResult = RegQueryValue (HKEY_CLASSES_ROOT, szSubKey, szBuffer, &cbBufferSize); BOOL bSuccess = (nResult == ERROR_SUCCESS); if (bSuccess) { tstring szKeyValue = szBuffer; DWORD posDOT_EXE = szKeyValue.find_last_of (TEXT(".EXE")); DWORD posLAST_BACKSLASH = szKeyValue.find_last_of (TEXT("\\")); DWORD nBrowserNameLength = posDOT_EXE - posLAST_BACKSLASH; DWORD nBrowserFolderPathLength = posLAST_BACKSLASH; TCHAR szBrowserName [nBrowserNameLength + 1]; TCHAR szBrowserFolder [nBrowserFolderPathLength + 1]; szKeyValue.copy (szBrowserName, nBrowserNameLength, posLAST_BACKSLASH + 1); szKeyValue.copy (szBrowserFolder, nBrowserFolderPathLength, 0); szBrowserName [nBrowserNameLength] = TEXT('\0'); szBrowserFolder [nBrowserFolderPathLength] = TEXT('\0'); tcout << TEXT("Key Value (HKEY_CLASSES_ROOT\\HTTP\\shell\\open\\command)") << endl; tcout << szKeyValue.c_str() << endl; tcout << TEXT("Extracting from key value...") << endl; tcout << TEXT("----------------------------") << endl; tcout << TEXT("Default Browser Name:") << szBrowserName << endl; tcout << TEXT("Default Browser Folder:") << szBrowserFolder << endl; //Using szBrowserName & szBrowserFolder for ShellExecute } system("PAUSE"); return EXIT_SUCCESS; } /* Size limit of Value (ref: MSDN) Available memory (latest format) 1MB (standard format) Windows Me/98/95: 16,300 bytes. Windows 95: There is a 64K limit for the total size of all values of a key. Because MS modifies the size limit for each OS, you should use GetVersionEx to determine your platform version. */
Đã được chỉnh sửa lần cuối bởi ilovecplusplus : 11-02-2007 lúc 02:38 AM.
Our dreams are young and we both know they take us where we want to go...
Lỗi tùm lum rồi bạn ơi !
Code:Compiling... Temp.cpp E:\My Documents\My Projects\Temp\Temp.cpp(39) : error C2057: expected constant expression E:\My Documents\My Projects\Temp\Temp.cpp(39) : error C2466: cannot allocate an array of constant size 0 E:\My Documents\My Projects\Temp\Temp.cpp(39) : error C2133: 'szBrowserName' : unknown size E:\My Documents\My Projects\Temp\Temp.cpp(40) : error C2057: expected constant expression E:\My Documents\My Projects\Temp\Temp.cpp(40) : error C2466: cannot allocate an array of constant size 0 E:\My Documents\My Projects\Temp\Temp.cpp(40) : error C2133: 'szBrowserFolder' : unknown size Error executing cl.exe. Temp.exe - 6 error(s), 0 warning(s)
Try again!Code:#define _STLP_THREADS //comment if you not use STLport #define _STLP_WCHAR_T //comment if you not use STLport #define SIZE_LIMIT 16300 #include <windows.h> #include <tchar.h> #include <cstdlib> #include <iostream> using namespace std; #ifdef UNICODE #define tcout wcout typedef wstring tstring; #else #define tcout cout typedef string tstring; #endif int _tmain(void) { tstring szCmdValue = ""; TCHAR szCmdSubKey[] = TEXT("HTTP\\shell\\open\\command"); //or HTTPS... TCHAR szBuffer[SIZE_LIMIT]; LONG cbBufferSize = SIZE_LIMIT * sizeof(TCHAR); //this because the buffer size specified in bytes LONG nResult = RegQueryValue (HKEY_CLASSES_ROOT, szCmdSubKey, szBuffer, &cbBufferSize); BOOL bCmdSuccess = (nResult == ERROR_SUCCESS); if (bCmdSuccess) { szCmdValue = _tcslwr (szBuffer); DWORD posLAST_BACKSLASH = szCmdValue.rfind (TEXT("\\")); DWORD posROOT = szCmdValue.find (TEXT(":\\")); DWORD posDOT_EXE = szCmdValue.rfind (TEXT(".exe")); DWORD nBrowserNameLength = posDOT_EXE - posLAST_BACKSLASH + lstrlen (TEXT(".exe")) - 1; DWORD nBrowserFolderPathLength = posLAST_BACKSLASH - posROOT + 1; tstring szBrowserName = szCmdValue.substr (posLAST_BACKSLASH + 1, nBrowserNameLength); tstring szBrowserFolder = szCmdValue.substr (posROOT - 1, nBrowserFolderPathLength); tcout << TEXT("Command Value (HKEY_CLASSES_ROOT\\HTTP\\shell\\open\\command)") << endl; tcout << szCmdValue.c_str() << endl; tcout << TEXT("Extracting from key value...") << endl; tcout << TEXT("----------------------------") << endl; tcout << TEXT("Default Browser Name:") << szBrowserName.data() << endl; tcout << TEXT("Default Browser Folder:") << szBrowserFolder.data() << endl; } system("PAUSE"); return EXIT_SUCCESS; }
Our dreams are young and we both know they take us where we want to go...
Xem code của IloveCplusplus cho thấy: Để mở trình duyệt mặc định thì cần Query cái KEY "HKEY_CLASSES_ROOT\HTTP\shell\open\command" để quyết định open cái file exe của trình duyệt nào.
Vậy cứ theo cái nguyên tắc này để mà tiến hành tùy biến. Phải không IloveCplusplus?
Một người nào đó coi thường ý thức kỷ luật cũng có nghĩa là người đó đã coi thường tương lai số phận của chính bản thân người đó.Email: kevin[@]congdongcviet.com | CC to: info[@]congdongcviet.com
Phone: 0972 89 7667
Những người coi thường ý thức kỷ luật sẽ không bao giờ có được sự thành công trong sự nghiệp hoặc bị sự thiếu kỷ luật làm tiêu tan sự nghiệp.
Hic hic ! Cái ông ilovecplusplus ko chịu bảo gì cả, mình cứ tưởng Project kiểu Win32 Application mà xài. Ai dè báo lỗi tùm lum, hóa ra là cái kiểu Win32 Console Application.
Cảm ơn ông lắm nha.