IEButtonDlg.cpp
上传用户:qzzxgm
上传日期:2009-12-14
资源大小:1882k
文件大小:5k
源码类别:

书籍源码

开发平台:

Visual C++

  1. // IEButtonDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "IEButton.h"
  5. #include "IEButtonDlg.h"
  6. #include "atlbase.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CAboutDlg dialog used for App About
  14. class CAboutDlg : public CDialog
  15. {
  16. public:
  17. CAboutDlg();
  18. // Dialog Data
  19. //{{AFX_DATA(CAboutDlg)
  20. enum { IDD = IDD_ABOUTBOX };
  21. //}}AFX_DATA
  22. // ClassWizard generated virtual function overrides
  23. //{{AFX_VIRTUAL(CAboutDlg)
  24. protected:
  25. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  26. //}}AFX_VIRTUAL
  27. // Implementation
  28. protected:
  29. //{{AFX_MSG(CAboutDlg)
  30. //}}AFX_MSG
  31. DECLARE_MESSAGE_MAP()
  32. };
  33. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  34. {
  35. //{{AFX_DATA_INIT(CAboutDlg)
  36. //}}AFX_DATA_INIT
  37. }
  38. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CAboutDlg)
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  45. //{{AFX_MSG_MAP(CAboutDlg)
  46. // No message handlers
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CIEButtonDlg dialog
  51. CIEButtonDlg::CIEButtonDlg(CWnd* pParent /*=NULL*/)
  52. : CDialog(CIEButtonDlg::IDD, pParent)
  53. {
  54. //{{AFX_DATA_INIT(CIEButtonDlg)
  55. // NOTE: the ClassWizard will add member initialization here
  56. //}}AFX_DATA_INIT
  57. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  58. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  59. }
  60. void CIEButtonDlg::DoDataExchange(CDataExchange* pDX)
  61. {
  62. CDialog::DoDataExchange(pDX);
  63. //{{AFX_DATA_MAP(CIEButtonDlg)
  64. // NOTE: the ClassWizard will add DDX and DDV calls here
  65. //}}AFX_DATA_MAP
  66. }
  67. BEGIN_MESSAGE_MAP(CIEButtonDlg, CDialog)
  68. //{{AFX_MSG_MAP(CIEButtonDlg)
  69. ON_WM_SYSCOMMAND()
  70. ON_WM_PAINT()
  71. ON_WM_QUERYDRAGICON()
  72. ON_BN_CLICKED(IDC_ADD, OnAdd)
  73. //}}AFX_MSG_MAP
  74. END_MESSAGE_MAP()
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CIEButtonDlg message handlers
  77. BOOL CIEButtonDlg::OnInitDialog()
  78. {
  79. CDialog::OnInitDialog();
  80. // Add "About..." menu item to system menu.
  81. // IDM_ABOUTBOX must be in the system command range.
  82. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  83. ASSERT(IDM_ABOUTBOX < 0xF000);
  84. CMenu* pSysMenu = GetSystemMenu(FALSE);
  85. if (pSysMenu != NULL)
  86. {
  87. CString strAboutMenu;
  88. strAboutMenu.LoadString(IDS_ABOUTBOX);
  89. if (!strAboutMenu.IsEmpty())
  90. {
  91. pSysMenu->AppendMenu(MF_SEPARATOR);
  92. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  93. }
  94. }
  95. // Set the icon for this dialog.  The framework does this automatically
  96. //  when the application's main window is not a dialog
  97. SetIcon(m_hIcon, TRUE); // Set big icon
  98. SetIcon(m_hIcon, FALSE); // Set small icon
  99. // TODO: Add extra initialization here
  100. return TRUE;  // return TRUE  unless you set the focus to a control
  101. }
  102. void CIEButtonDlg::OnSysCommand(UINT nID, LPARAM lParam)
  103. {
  104. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  105. {
  106. CAboutDlg dlgAbout;
  107. dlgAbout.DoModal();
  108. }
  109. else
  110. {
  111. CDialog::OnSysCommand(nID, lParam);
  112. }
  113. }
  114. // If you add a minimize button to your dialog, you will need the code below
  115. //  to draw the icon.  For MFC applications using the document/view model,
  116. //  this is automatically done for you by the framework.
  117. void CIEButtonDlg::OnPaint() 
  118. {
  119. if (IsIconic())
  120. {
  121. CPaintDC dc(this); // device context for painting
  122. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  123. // Center icon in client rectangle
  124. int cxIcon = GetSystemMetrics(SM_CXICON);
  125. int cyIcon = GetSystemMetrics(SM_CYICON);
  126. CRect rect;
  127. GetClientRect(&rect);
  128. int x = (rect.Width() - cxIcon + 1) / 2;
  129. int y = (rect.Height() - cyIcon + 1) / 2;
  130. // Draw the icon
  131. dc.DrawIcon(x, y, m_hIcon);
  132. }
  133. else
  134. {
  135. CDialog::OnPaint();
  136. }
  137. }
  138. // The system calls this to obtain the cursor to display while the user drags
  139. //  the minimized window.
  140. HCURSOR CIEButtonDlg::OnQueryDragIcon()
  141. {
  142. return (HCURSOR) m_hIcon;
  143. }
  144. void CIEButtonDlg::OnAdd() 
  145. {
  146. CRegKey rk;
  147. char strKey[]="Software\Microsoft\Internet Explorer\Extensions\{D5C1CCC2-811B-4bf2-BF22-0D3B89600F5B}";
  148. char strPath[MAX_PATH];
  149. char strIconNormalPath[MAX_PATH]; //正常时的图标全路径
  150. char strHotIconPath[MAX_PATH]; //鼠标覆盖时的图标全路径
  151. GetModuleFileName(0,strPath,MAX_PATH); //得到本可执行文件的路径
  152. strcpy(strIconNormalPath,strPath);
  153. strcpy(strHotIconPath,strPath);
  154. strcat(strHotIconPath,",128"); //131是图标的ID,你可以以资源方式打开EXE文件就可以看到所有资源及其ID
  155. strcat(strIconNormalPath,",128");
  156. rk.Create(HKEY_LOCAL_MACHINE,strKey);
  157. rk.SetValue("{1FBA04EE-3024-11D2-8F1F-0000F87ABD16}","CLSID");  //创建IE的ClassID键
  158. rk.SetValue("Yes","Default Visible");     //缺省可见
  159. rk.SetValue("记事本","ButtonText");
  160. rk.SetValue(strIconNormalPath,"Icon");
  161. rk.SetValue(strHotIconPath,"HotIcon");
  162. //如果是执行脚本,可以是rk.SetValue("c:\demo.html","Script"); 
  163. //在demo.html 存放你的脚本代码
  164. rk.SetValue("notepad.exe","Exec");  //打开记事本
  165. }