⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 Registry editor For WINCE which can be use to edit registry
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************************
Module Name:
    main.c

 Start module, main dialog hook and about dialog hook
  WinMain
  Main_DialogHook
    Main_OnInitDialog 
    Main_OnCommand 
    Main_OnSize 
    Main_OnNotify

  aboutDialogHook 


**********************************************************************************/
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <string.h>
#include <stdlib.h>
#include <tchar.h>

#include "global.h"
#include "regtree.h"
#include "reglist.h"
#include "find.h"
#include "resource.h"
#include "winuser.h"
#include "tree.h"
//#define IDR_ACCELERATOR  14
//#define IDD_DIALOG_MAIN  15
//#define  IDC_TREE   16 
//#define   IDB_TREE_SYMBOLS 17
//#define  IDC_LIST 18
//#define  IDB_LIST_SYMBOLS 19
//#define IDI_ICON_MAIN 20
//#define  ID_MENUITEM_EXIT 21
//#define ID_MENUITEM_DEL 22
//#define ID_MENUITEM_MODIFY 23
//#define ID_MENUITEM_FIND 24
//#define ID_MENUITEM_FINDNEXT 25
//#define ID_MENUITEM_ABOUT 26
//#define IDD_DIALOG_ABOUT  27
//#define IDC_PATH 28
//#define IDR_MENU_MAIN 987
#define WXUSINGDLL
//-----------------------------------------------------------------
		HANDLE   hInst;
		HANDLE      hAccel;
		HWND		h_wnd;
		HWND        hDlg;
		HWND h_wndDlg;
		HWND        hWndCB;   // Command Bar window
		HWND        hListWnd; // List Window
		HWND        hTreeWnd; // Tree Window
		HIMAGELIST  hTreeImages;
		HIMAGELIST  hListImages;
		TCHAR	  sz_subKey [MAX_PATH*8];
		HKEY    h_rootKey; 
		RECT rect;
		LPTV_INSERTSTRUCT lpis;
		HTREEITEM   nTreeRootItem; //CRegRootItems rootItems;

		TCHAR	  szCurrSubKey [MAX_PATH*8]; 
		HKEY    hCurrRootKey;   
		HKEY hKeyN2; 
		DWORD dwDisp;
		int  rc;
		PBYTE pBuff;
		DWORD dwValType, dwDSize;
		PBYTE  pbData;
		DWORD dwRegVal = 0x1234;
		
		
		HTREEITEM h_item ;
//---Messages handles
BOOL        Main_OnInitDialog (HWND hwnd, HWND h_wndFocus, LPARAM l_param);
//void WINAPI Main_OnDestroy    (HWND hwnd);
void        Main_OnCommand    (HWND h_wnd, int n_id, HWND h_wndCtl, UINT n_codeNotify);
int         Main_OnSize       (HWND h_wnd, WPARAM fw_sizeType, int n_width, int n_height);
LRESULT     Main_OnNotify     (HWND hwnd, int idCtl, LPNMHDR pnmh);
INT_PTR CALLBACK _addkey (HWND h_wndAdd, UINT u_msg, WPARAM w_param, LPARAM l_param);
INT_PTR CALLBACK _string(HWND h_String, UINT u_msg, WPARAM w_param, LPARAM l_param);
INT_PTR CALLBACK _about(HWND h_Modify, UINT u_msg, WPARAM w_param, LPARAM l_param);

static BOOL WINAPI _mainDialogHook  (HWND h_wndDlg, UINT u_msg, WPARAM w_param, LPARAM l_param);
static BOOL WINAPI _aboutDialogHook (HWND h_wndDlg, UINT u_msg, WPARAM w_param, LPARAM l_param);
static BOOLEAN isParent (HKEY h_parent, TCHAR * psz_key);

//*****************************************************************

int WINAPI WinMain (HINSTANCE h_instance, HINSTANCE h_prevInstance,
                    #ifdef _WIN32_WCE
                      LPWSTR lp_cmdLine, 
                    #else
                      LPSTR lp_cmdLine, 
                    #endif
                    int n_cmdShow)
{
  HWND  h_wnd;
  MSG   msg;

  UNREFERENCED_PARAMETER (n_cmdShow);
  UNREFERENCED_PARAMETER (lp_cmdLine);
  UNREFERENCED_PARAMETER (h_prevInstance);

  hInst = h_instance;
  
  InitCommonControls ();
  hAccel = LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_ACCELERATOR));

  h_wnd = CreateDialog ((HANDLE)h_instance, MAKEINTRESOURCE(IDD_DIALOG_MAIN), NULL, (DLGPROC)_mainDialogHook);
  if (h_wnd == NULL)
    MessageBox (NULL, TEXT("Can't create main window"), TEXT("Error"), MB_OK|MB_ICONSTOP);

  while (GetMessage(&msg, NULL, 0, 0))
  {
    if (!TranslateAccelerator(h_wnd, hAccel, &msg))
    {
      TranslateMessage((LPMSG)&msg);
      DispatchMessage((LPMSG)&msg);
    }
  }
  return 0;
}

//*****************************************************************
static BOOL WINAPI _mainDialogHook ( HWND h_wndDlg, UINT u_msg, WPARAM w_param, LPARAM l_param)
{
  switch (u_msg)
  {
		HANDLE_MESS (h_wndDlg, WM_INITDIALOG, w_param, l_param, Main_OnInitDialog); 
		break;

		//    HANDLE_MESS (h_wndDlg, WM_DESTROY   , w_param, l_param, Main_OnDestroy);
		break;
		HANDLE_MESS (h_wndDlg, WM_NOTIFY    , w_param, l_param, Main_OnNotify); 
		break;
		HANDLE_MESS (h_wndDlg, WM_COMMAND   , w_param, l_param, Main_OnCommand); 
		break;

		#ifdef _WIN32_WCE
		  HANDLE_MESS (h_wndDlg, WM_SIZE    , w_param, l_param, Main_OnSize);
		#endif
 
  case WM_QUIT:
	  {
			DefWindowProc(h_wndDlg,u_msg,w_param, l_param);
	  }
	  //DestroyWindow(h_wndDlg);
  }
  return 0;
}

//********************************************************************************
//  PARAMETERS:
//      hwnd        - handle of the window receiving the notification
//      h_wndFocus  - handle of control to receive focus
//      l_param     - initialization parameter 
BOOL Main_OnInitDialog (HWND h_wndDlg, HWND h_wndFocus, LPARAM l_param)
{
  LV_COLUMN col;
  HICON     h_icon;
  int       idx;
  #ifdef _WIN32_WCE
    TBBUTTON buttons[] = 
    {
      {0,                         0, TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0, 0, -1},
      {STD_FIND  , ID_MENUITEM_FIND, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
      {0,                         0, TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0, 0, -1},
      {STD_DELETE, ID_MENUITEM_DEL , TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1}
    };
    //TCHAR * psz_toolTips[] = {TEXT("Find key or value"),
    //                          TEXT("Delete key or value")};
  #endif

  SendMessage (h_wndDlg, WM_SETTEXT, 0, (LPARAM)(TEXT("Registry Editor")));

  #ifdef _WIN32_WCE
	  /////////////////////////////////////////////////////////////////////////
    // Create Menu and command bar
    hWndCB = CommandBar_Create (hInst, h_wndDlg, 1);
    if (hWndCB == NULL) 
      MessageBox (h_wndDlg, TEXT("Can't create menu: step 1"), TEXT("Error"), MB_OK|MB_ICONSTOP);

    if (CommandBar_AddBitmap (hWndCB, HINST_COMMCTRL, IDB_STD_SMALL_COLOR, 15, 16, 16)==-1)
      MessageBox (h_wndDlg, TEXT("Can't create menu: step 2"), TEXT("Error"), MB_OK|MB_ICONSTOP);

    //CommandBar_AddToolTips (hWndCB, 2, psz_toolTips);

    if (CommandBar_AddButtons (hWndCB, sizeof(buttons)/sizeof(TBBUTTON),buttons) == FALSE)
      MessageBox (h_wndDlg, TEXT("Can't create menu: step 3"), TEXT("Error"), MB_OK|MB_ICONSTOP);

    if (CommandBar_InsertMenubar (hWndCB, hInst, IDR_MENU_MAIN, 0)==FALSE)
      MessageBox (h_wndDlg, TEXT("Can't create menu: step 4"), TEXT("Error"), MB_OK|MB_ICONSTOP);
  #endif
      
  //////////////////////////////////////////////////////////////////////
  hTreeWnd = GetDlgItem(h_wndDlg, IDC_TREE);

  //////////////////////////////////////////////////////////////////////
  // Create the image list for the item pictures
	if ((hTreeImages = ImageList_Create(16, 16, ILC_COLOR4/*ILC_MASK*/, 3, 0)) != NULL)
  {
    HBITMAP h_bmpTree = LoadBitmap (hInst, MAKEINTRESOURCE(IDB_TREE_SYMBOLS));
    //idx = ImageList_AddMasked (hTreeImages, h_bmpTree, RGB(0,255,0));
    idx = ImageList_Add (hTreeImages, h_bmpTree, NULL);

    // Clean up the GDI objects
    DeleteObject (h_bmpTree);

    #ifdef __DEBUG__
      idx = ImageList_GetImageCount(hTreeImages);
    #endif

    //--- Associate the image list with the treeview control
	  TreeView_SetImageList (hTreeWnd, hTreeImages, TVSIL_NORMAL);
  }

  //--- Load registry to the tree
  nTreeRootItem = RegTree_LoadRoot (hTreeWnd);
  TreeView_Expand (hTreeWnd, nTreeRootItem, TVE_EXPAND);

  //////////////////////////////////////////////////////////////////////
  //         Init list view
	  hListWnd = GetDlgItem (h_wndDlg, IDC_LIST);

	  col.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM; 
	  col.cx = 100; 
	  col.pszText = TEXT ("Name"); 
	  col.iSubItem = 0;
	  ListView_InsertColumn (hListWnd, 0, &col);

	  col.pszText = TEXT ("Data"); 
	  col.cx = 250; 
	  col.iSubItem = 1;
	  ListView_InsertColumn (hListWnd, 1, &col);

  // Create the image list for the item pictures
	if ((hListImages = ImageList_Create(16, 16, ILC_COLOR4/*ILC_MASK*/, 4, 0)) != NULL)
		  {

			HBITMAP h_bmpList = LoadBitmap (hInst, MAKEINTRESOURCE(IDB_LIST_SYMBOLS));
			idx = ImageList_Add (hListImages, h_bmpList, NULL);

			// Clean up the GDI objects
			DeleteObject (h_bmpList);

			ListView_SetImageList (hListWnd, hListImages, LVSIL_SMALL);
		  }

  //----Set Icon to the Window -----------------------------------------
		  h_icon = (HICON)LoadImage (hInst, MAKEINTRESOURCE(IDI_ICON_MAIN),
									 IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
		  PostMessage  (h_wndDlg, WM_SETICON, (WPARAM)FALSE, (LPARAM)h_icon);
		  DeleteObject ((HGDIOBJ)h_icon);

  //--- Adjust window size and position --------------------------------
  {
    #ifndef _WIN32_WCE
      ShowWindow (h_wndDlg, SW_MAXIMIZE);
    #else
      int n_width = GetSystemMetrics (SM_CXSCREEN);
      int n_height = GetSystemMetrics (SM_CYSCREEN);
      POINT point = {n_width - 1, n_height - 1};
      HWND h_taskBar = WindowFromPoint (point);

      
      GetWindowRect (h_taskBar, &rect);

	    SetWindowPos (h_wndDlg, HWND_TOP, 0, 0, n_width, n_height-(rect.bottom-rect.top)+1, SWP_SHOWWINDOW);
    #endif
  }
	return 0;
}

//****************************************************************************
//  FUNCTION:   Main_OnDestroy(HWND)
//
//  PURPOSE:    Handle any clean up and post the quit message to exit the
//              message loop.
//  PARAMETERS:
//      hwnd    - handle of the window receiving this message
//  RETURN VALUE:
//      none
//void WINAPI Main_OnDestroy (HWND hwnd)
//{
//// Indicate that the message loop should exit since the main window
//  // is being destroyed.
//	if (hListImages)
//    ImageList_Destroy (hListImages);
//  if (hTreeImages)
//    ImageList_Destroy (hTreeImages);
//  #ifdef _WIN32_WCE
//    CommandBar_Destroy (hWndCB);
//  #endif
//
//  
//  PostQuitMessage(0);
//
//}

//********************************************************************************
//  PARAMETERS:
//    fwSizeType = wParam;          - resizing flag 
//    nWidth     = LOWORD(lParam);  - width of client area 
//    nHeight    = HIWORD(lParam);  - height of client area 
int Main_OnSize (HWND h_wndDlg, WPARAM fw_sizeType, int n_width, int n_height)
{
  #ifdef _WIN32_WCE
    HWND h_wndItem;
    RECT rect;
    int  n_topOffset = 0;
    int  n_bottomOffset = 0;
  
    GetWindowRect (hWndCB, &rect);
    n_topOffset = rect.bottom-rect.top;
    SetWindowPos (hWndCB, h_wndDlg, 0, 0, n_width, n_topOffset, SWP_NOZORDER|SWP_NOMOVE);
    CommandBar_AddAdornments (hWndCB, 0, 0);

    h_wndItem = GetDlgItem(h_wndDlg, IDC_PATH);
    GetWindowRect (h_wndItem, &rect);
    n_bottomOffset = rect.bottom-rect.top;

    SetWindowPos (h_wndItem, h_wndDlg, 0, n_height-n_bottomOffset, 
                                      n_width, n_bottomOffset, SWP_NOZORDER);

    GetWindowRect (hTreeWnd, &rect);
    SetWindowPos (hTreeWnd, h_wndDlg, 
                            0, n_topOffset+1, 
                            rect.right-rect.left, 
                            n_height - n_bottomOffset - n_topOffset, SWP_NOZORDER);//|SWP_NOMOVE);

    SetWindowPos (hListWnd, h_wndDlg, 
                            rect.right-rect.left+3, n_topOffset+1, 
                            n_width-(rect.right-rect.left)-5, 
                            n_height - n_bottomOffset - n_topOffset, SWP_NOZORDER);//|SWP_NOMOVE);
  #endif

  return 0;
}

//********************************************************************************
//  FUNCTION:   Main_OnCommand(HWND, int, HWND, UINT)
//
//  PURPOSE:    Handles the WM_COMMAND messages for the Win32Generic window
//              class
//  PARAMETERS:
//      hwnd        - handle of the window receiving the message
//      id          - identifier of the command
//      hwndCtl     - handle of the control sending the message)
//      codeNotify  - specifies the notification code if the message is from
//                    a control
//  RETURN VALUE:
//      none
//  COMMENTS:
//      codeNotify is 1 if from an accelerator, 0 if from a menu.
//      If the message is not from a control hwndCtl is NULL.
void Main_OnCommand (HWND h_wnd, int n_id, HWND h_wndCtl, UINT n_codeNotify)
{
	
  switch (n_id) //process pressing of buttons and combobox
  {
   case IDCANCEL: 
	case ID_MENUITEM_EXIT:
	//  EndDialog(hwnd ,0);
     	EndDialog (h_wnd, 0);
	//  EndDialog(h_wndCtl);
	//  ImageList_Destroy (hListImages);
	//  ImageList_Destroy (hTreeImages);
		DestroyMenu(NULL);
		DestroyIcon(NULL);
		DestroyAcceleratorTable(NULL);
		CommandBar_Destroy (hWndCB);
		DestroyWindow (h_wnd);
	    DestroyWindow(NULL);
    break;

    case ID_MENUITEM_DEL: case ID_EDIT_MODIFY:
    {
      HWND h_foc = GetFocus();
      if (h_foc == hListWnd || h_foc == hTreeWnd)
      {
        if (n_id == ID_MENUITEM_DEL)
          SendMessage (h_foc, WM_KEYDOWN, VK_DELETE, 0);
        else if (h_foc == hListWnd)
          RegList_EditSelectedValue (hListWnd, hCurrRootKey, szCurrSubKey);
      }
    }
    break;

    case ID_MENUITEM_FIND:
  /*  case ID_MENUITEM_FINDNEXT:
			{
			  HWND h_foc = GetFocus();
			  Find_Run (h_foc, (n_id == ID_MENUITEM_FINDNEXT)?TRUE:FALSE);
			}
    break;*/

    case ID_HELP_REFRESH:
		
     DialogBox (hInst, MAKEINTRESOURCEW(IDD_DIALOG_ABOUT),
                   h_wnd, _about);
    break;
	case ID_MENUITEM_CREATE_KEY:
		{
			/*TV_INSERTSTRUCT  tvins;	
				*/
            
		DialogBox(hInst, MAKEINTRESOURCEW(IDD_ADD_KEY), h_wnd,_addkey);
		

					//(HTREEITEM) SendMessage (hwndFrom, TVM_INSERTITEM, 0, (LPARAM)(LPTV_INSERTSTRUCT) &tvins);			*/
					/*UpdateWindow(hTreeImages);
					UpdateWindow(h_wnd);
					UpdateWindow(hTreeWnd);
					UpdateWindow(h_wndDlg);
					UpdateWindow(h_wndCtl);
					UpdateWindow(hAccel);*/


					//SendMessage(hTreeWnd,TVM_INSERTITEM, 0,&lpis);

		}
		
		break;
	case ID_MENUITEM_CREATE_STRING:
		{
		
				DialogBox(hInst, MAKEINTRESOURCEW(IDD_STRING_NEW), h_wnd,_string);
							  //rc = RegOpenKeyEx (HKEY_LOCAL_MACHINE, 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -