Click here to Skip to main content
15,894,896 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionAbout the question of "CreateProcess" ! Pin
zxw284424-Feb-09 18:44
zxw284424-Feb-09 18:44 
QuestionRe: About the question of "CreateProcess" ! Pin
«_Superman_»24-Feb-09 19:27
professional«_Superman_»24-Feb-09 19:27 
QuestionRe: About the question of "CreateProcess" ! Pin
zxw284424-Feb-09 21:15
zxw284424-Feb-09 21:15 
AnswerRe: About the question of "CreateProcess" ! Pin
CPallini24-Feb-09 23:01
mveCPallini24-Feb-09 23:01 
GeneralRe: About the question of "CreateProcess" ! Pin
zxw284425-Feb-09 2:17
zxw284425-Feb-09 2:17 
QuestionRe: About the question of "CreateProcess" ! Pin
CPallini25-Feb-09 2:33
mveCPallini25-Feb-09 2:33 
AnswerRe: About the question of "CreateProcess" ! Pin
zxw28441-Mar-09 15:00
zxw28441-Mar-09 15:00 
Questionproblem in adding node in registry Pin
sonali996024-Feb-09 18:42
sonali996024-Feb-09 18:42 
i have created the registry editor in wince when i am going to add new registry it gets added in registry and show in treeview but problem is that when i am going to add child on unexpanded registry or lower most child ie which is not having any child the registry key added by twice means it show tow key with same name but when restart exe it shows only one key Kindly help me


Following is the code
/**********************************************************************************
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, 
     //                                                   TEXT ("Software\\n2"), 0,
     //                                                   KEY_SET_VALUE, &hKeyN2);
     //               if(rc != ERROR_SUCCESS)
     //               {
     //                   MessageBox (NULL, TEXT("RegOpenKeyEx Failed"), 
     //                                           TEXT("Key n2 not opened"), MB_OK);
     //                   return FALSE; 
     //                }
     //               //set a name and value under the open key 
     //               rc = RegSetValueEx (hKeyN2, TEXT("OneDWORD"), 0, 
     //                                                  REG_DWORD , (LPBYTE)&dwRegVal,  
     //                                                  sizeof(dwRegVal));
     //               if (rc != ERROR_SUCCESS)
     //                {
     //                   MessageBox (NULL, TEXT("RegSetValueEx Failed"), 
     //                                          TEXT("Couldn't delete value"), MB_OK);
     //                }
     //               else
     //               {
     //                   MessageBox (NULL, TEXT("Value OneDWORD Set"), 
     //                                          TEXT("Single DWORD Registered"), MB_OK);
     //               }
     //               //always clean up after ourselves
     //               RegCloseKey( hKeyN2 );
		}
		break;
	case IDD_REFRESH:
		

		break;
	
	
	
  }
}

//********************************************************************************
//  FUNCTION:   Main_OnNotify(HWND, int, LPNMHDR)  WM_NOTIFY
//
//  PURPOSE:    Handles any notifications the treeview control spits out.
//
//  PARAMETERS:
//      hwnd    - handle of the window receiving the notification
//      idCtl   - identifies the control sending the notification
//      pnmh    - points to a NMHDR struct with more inforamation regarding the
//                notification
//  RETURN VALUE:
//      (LRESULT) Dependant on the specific notification.  See Below.
//  COMMENTS:
LRESULT Main_OnNotify(HWND h_wnd, int idCtl, LPNMHDR pnmh)
{
  static  char  bIs_TVN_ITEMEXPANDING = FALSE;
  static  char  bIs_TVN_SELCHANGED = FALSE;



	switch (pnmh->code)
	{	
    // A node is expanding or collapsing.  We need to update the folder
    // images to reflect either a closed or open folder depending on it's
    // new state.
		case TVN_ITEMEXPANDING:
		{
		 LPNM_TREEVIEW pnmtv;

      if (bIs_TVN_ITEMEXPANDING == TRUE)
        return 0;
      
			// cast the NMHDR into a treeview notify structure
			pnmtv = (LPNM_TREEVIEW) pnmh;

      if (pnmtv->itemNew.hItem == nTreeRootItem) 
        return 0;
      //-------------------------------------------------

      bIs_TVN_ITEMEXPANDING = TRUE;
    
			if (pnmtv->action == TVE_COLLAPSE)
			{
				// Retrieve the image from the current item
				pnmtv->itemNew.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
				TreeView_GetItem (pnmh->hwndFrom, &(pnmtv->itemNew));

				// Set the item's image to the closed folder
				pnmtv->itemNew.iImage = nIMAGE_CLOSED;
				pnmtv->itemNew.iSelectedImage = nIMAGE_CLOSED;
           	
				TreeView_SetItem (pnmh->hwndFrom, &(pnmtv->itemNew));
			}
			else
			{
				// Retrieve the image from the current item
				pnmtv->itemNew.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
				TreeView_GetItem (pnmh->hwndFrom, &(pnmtv->itemNew));

				// Set the item's image to the closed folder
				pnmtv->itemNew.iImage = nIMAGE_OPEN;
				pnmtv->itemNew.iSelectedImage = nIMAGE_OPEN;
				TreeView_SetItem (pnmh->hwndFrom, &(pnmtv->itemNew));

        if ( ! (pnmtv->itemNew.state & TVIS_EXPANDEDONCE) )
        {
          // We need to fill in the subdirectory just expanded
          SetCursor (LoadCursor(NULL, IDC_WAIT));
			RegTree_BuildKey (pnmtv->hdr.hwndFrom, pnmtv->itemNew, &h_rootKey, sz_subKey);
			RegTree_LoadKey  (pnmtv->hdr.hwndFrom, (HTREEITEM)pnmtv->itemNew.hItem, h_rootKey, sz_subKey);
          SetCursor (NULL);
        }
			}
      bIs_TVN_ITEMEXPANDING = FALSE;
			return 0;	// return value is ignored
		}
    break;

    case TVN_SELCHANGED:
    {
			// cast the NMHDR into a treeview notify structure
			LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW) pnmh;

      if (pnmtv->itemNew.hItem == pnmtv->itemOld.hItem)
        return 0;

      if (bIs_TVN_SELCHANGED == TRUE)
        return 0;
      
      bIs_TVN_SELCHANGED = TRUE;

		SetCursor (LoadCursor(NULL, IDC_WAIT));
		RegTree_BuildKey (pnmtv->hdr.hwndFrom, pnmtv->itemNew, &h_rootKey, sz_subKey);
		RegList_LoadKey (hListWnd, h_rootKey, sz_subKey);
		lstrcpy (szCurrSubKey, sz_subKey);
		hCurrRootKey = h_rootKey;
		SetCursor (NULL);

      RegTree_GetRootPath (h_rootKey, sz_subKey);
      if (h_rootKey)
        lstrcat (sz_subKey, szCurrSubKey);

      SetDlgItemText (h_wnd, IDC_PATH, sz_subKey);

      bIs_TVN_SELCHANGED = FALSE;
    }
    break;

    case TVN_KEYDOWN:
    {
      TV_KEYDOWN * pnkd = (TV_KEYDOWN FAR *) pnmh;
      if (pnkd->wVKey == VK_DELETE)
      {
        HTREEITEM h_item = TreeView_GetSelection (pnmh->hwndFrom);

        if (h_item == NULL)
          break;
        
        if (MessageBox (h_wnd, TEXT("Are you SURE you want to delete this KEY?"), 
                               TEXT("Deleting"), MB_YESNO|MB_ICONQUESTION)==IDYES)
        {
          if (RegDeleteKey (hCurrRootKey, szCurrSubKey) != ERROR_SUCCESS)
          {
            MessageBox (h_wnd, TEXT("Can't delete the KEY."), 
                               TEXT("Error"), MB_OK|MB_ICONEXCLAMATION);
            break;
          }
          TreeView_DeleteItem (pnmh->hwndFrom, h_item);
        }
      }
    }
    break;

    case LVN_KEYDOWN:
    {  
      LV_KEYDOWN * pnkd = (LV_KEYDOWN FAR *) pnmh;

      #if 0 //DEBUG
        TCHAR ppp [80];
        wsprintf (ppp, TEXT("0x%X"), pnkd->wVKey);
        MessageBox (h_wnd, ppp, TEXT("Virtual Key"), MB_OK);
      #endif

      if (pnkd->wVKey == VK_DELETE)
      {
        UINT is_selected = ListView_GetSelectedCount (pnmh->hwndFrom);
        if (is_selected)
        {
          int n_item = ListView_GetNextItem (pnmh->hwndFrom, -1, LVNI_ALL|LVNI_SELECTED);
          if (n_item >= 0)
          {
            if (MessageBox (h_wnd, TEXT("Are you sure you want to delete this value?"), 
                                   TEXT("Deleting"), MB_YESNO|MB_ICONQUESTION)==IDYES)
            {
              HKEY h_key;
              LV_ITEM  listItem;

              memset (&listItem, 0, sizeof (listItem));
              listItem.pszText = sz_subKey;
              listItem.cchTextMax = MAX_PATH*7;
              listItem.iItem = n_item;
              listItem.mask = LVIF_TEXT;
              if (ListView_GetItem (pnmh->hwndFrom, &listItem) == FALSE)
                break;

              if (RegOpenKeyEx (hCurrRootKey, szCurrSubKey, 0, KEY_WRITE, &h_key) != ERROR_SUCCESS)
                break;
              if (RegDeleteValue (h_key, listItem.pszText) == ERROR_SUCCESS)
                ListView_DeleteItem (pnmh->hwndFrom, n_item);
              RegCloseKey (h_key);
            }
          }
        }
      }
      else if (pnkd->wVKey == VK_RETURN)
        RegList_EditSelectedValue (pnmh->hwndFrom, hCurrRootKey, szCurrSubKey);
    }
    break;

    case NM_DBLCLK:
      if (pnmh->hwndFrom == hListWnd)
        RegList_EditSelectedValue (hListWnd, hCurrRootKey, szCurrSubKey);
    break;
	}

	return 0;
}

//********************************************************************************************
//static BOOL WINAPI _aboutDialogHook (HWND h_wndDlg, UINT u_msg, WPARAM w_param, LPARAM l_param)
//{
//  switch (u_msg)
//  {
//    case WM_COMMAND:
//      switch (GET_WM_COMMAND_ID(w_param,l_param))
//      {
//        case IDCANCEL:
//          EndDialog (h_wndDlg, 0);
//        break;
//      }
//    break;
//  }
//  return 0;
//}

//********************************************************************************************
			int len;
			TCHAR *szbuf;
			HWND hEditbox;
			DWORD dwDisp;
			HKEY hKey;
			LPRECT rectl;

			HKEY     h_key;
			BOOLEAN  bool_isSubKeys = 0;
			TCHAR    psz_nextKey [MAX_PATH+1];
			DWORD    n_keyNameSize; 
			DWORD    dw_index;
			DWORD    retCode;
			TCHAR	 pRevCurrSubKey [MAX_PATH*8]; 
INT_PTR CALLBACK _addkey (HWND h_wndAdd, UINT u_msg, WPARAM w_param, LPARAM l_param)
{

	
  switch (u_msg)
  {
    case WM_COMMAND:
      switch (GET_WM_COMMAND_ID(w_param,l_param))
      {
	  case IDOK:
		 
		 
		 pRevCurrSubKey[2080]=szCurrSubKey[2080];
		  hEditbox = GetDlgItem(h_wndAdd, IDC_EDIT1);
		  len=GetWindowTextLength(hEditbox);
		  szbuf =(TCHAR*)GlobalAlloc(GPTR, len + 1);
		  GetWindowText(hEditbox, szbuf,len+1);
		  GetDlgItemText(hEditbox,IDC_EDIT1,(LPWSTR)szbuf, len + 1);
		  wcscat(szCurrSubKey,_T("\\"));
		  wcscat(szCurrSubKey, szbuf);

		 rc=  RegCreateKeyEx(hCurrRootKey,szCurrSubKey,0,TEXT(""),REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_ALL_ACCESS,NULL,&hKey,&dwDisp);
           	   if (rc == ERROR_SUCCESS)
				   {
					 MessageBox(NULL,TEXT("KEY REGISTERED"),TEXT("NOTICE"),MB_OK);
				   }
			   else 
				   {
						MessageBox(NULL,TEXT("Failed"),TEXT("ERROR"),MB_OK);
				  
	 			   }
				//RegCloseKey(hKey);
				//	   RegOpenKeyEx(hCurrRootKey,pRevCurrSubKey,0,KEY_EXECUTE,&h_key);

				h_item=TreeView_GetSelection(hTreeWnd);
				//	 retCode = RegOpenKeyEx (hCurrRootKey, hCurrRootKey, 0, KEY_EXECUTE, &h_key);
				/*if (retCode != ERROR_SUCCESS)
				return;*/


				//for (dw_index = 0 ; ; dw_index ++) //--- Read all sub keys 
				//{
				//n_keyNameSize = MAX_PATH;
				//if (RegEnumKeyEx (hKey, dw_index, psz_nextKey, &n_keyNameSize, 0, NULL, NULL, NULL) != ERROR_SUCCESS)
				//break;
				//RegOpenKeyEx()
				//   RegOpenKeyEx(hCurrRootKey,pRevCurrSubKey,0,KEY_EXECUTE,&h_key);

				//bool_isSubKeys = isParent (h_key, pRevCurrSubKey);

				//				DebugBreak();
				Tree_AddItem (hTreeWnd, szbuf, h_item,FALSE);

				RegCloseKey(hKey);
				RegCloseKey(h_key);
				RegCloseKey(szCurrSubKey);
				RegCloseKey(pRevCurrSubKey);
				RegCloseKey(hCurrRootKey);


				     
			    
        case IDCANCEL:
          EndDialog (h_wndAdd, 0);
        break;
      }
    break;
  }
  return 0;
} 
int len1;
TCHAR *szbuf1;
HWND hEditbox1;
DWORD dwDisp;
HKEY hKeyN2;
LPRECT rectl;
INT_PTR CALLBACK _string(HWND h_String, UINT u_msg, WPARAM w_param, LPARAM l_param)
{
  switch (u_msg)
  {
    case WM_COMMAND:
      switch (GET_WM_COMMAND_ID(w_param,l_param))
      {
	  case IDOK:
		
           //   DebugBreak();
			hEditbox1 = GetDlgItem(h_String, IDC_EDIT2);
			len1=GetWindowTextLength(hEditbox1);
			szbuf1 =(TCHAR*)GlobalAlloc(GPTR, len1 + 1);

			GetWindowText(hEditbox1, szbuf1,len1+1);
			GetDlgItemText(hEditbox1,IDC_EDIT2,(LPWSTR)szbuf1, len1 + 1);

			   rc = RegOpenKeyEx (hCurrRootKey,szCurrSubKey 
															, 0,
															KEY_SET_VALUE, &hKeyN2);
						if(rc != ERROR_SUCCESS)
						{
							MessageBox (NULL, TEXT("RegOpenKeyEx Failed"), 
													TEXT("Key not opened"), MB_OK);
							return FALSE; 
						 }
						//set a name and value under the open key 
						rc = RegSetValueEx (hKeyN2,szbuf1, 0, 
														   REG_DWORD , (LPBYTE)&dwRegVal,  
														   sizeof(dwRegVal));
						if (rc != ERROR_SUCCESS)
						 {
							MessageBox (NULL, TEXT("RegSetValueEx Failed"), 
												   TEXT("Couldn't delete value"), MB_OK);
						 }
						else
						{
							MessageBox (NULL, TEXT("String Name Added "), 
												   TEXT("NOTICE"), MB_OK);
						}
						//always clean up after ourselves
	 				RegCloseKey( hKeyN2 );
     
			    

		case IDCANCEL:
          EndDialog (h_String, 0);
        break;
      }
    break;
  }
  return 0;
} 
INT_PTR CALLBACK _about(HWND h_Modify, UINT u_msg, WPARAM w_param, LPARAM l_param)
{
  switch (u_msg)
  {
    case WM_COMMAND:
      switch (GET_WM_COMMAND_ID(w_param,l_param))
      {
	  case IDOK:
	  case IDCANCEL:
	  
          EndDialog (h_Modify, 0);
		  
        break;
      }
    break;
  }
  return 0;
}
 
	static BOOLEAN isParent (HKEY h_parent, TCHAR * psz_key)
	{
	  DWORD  n_numSubKeys; // address of buffer for number of subkeys 
	  DWORD  n_maxSubKeyLen;// address of buffer for longest subkey name length  
	  DWORD  n_maxClassLen; // address of buffer for longest class string length 
	  DWORD  n_numValues; // address of buffer for number of value entries 
	  DWORD  n_maxValueNameLen;     // address of buffer for longest value name length 

	  HKEY  h_key; // handle of key to query 
	  DWORD retCode = RegOpenKeyEx (h_parent, psz_key, 0, KEY_EXECUTE, &h_key);
	  if (retCode != ERROR_SUCCESS)
		return FALSE;

	  n_numSubKeys = 0;
	  retCode = RegQueryInfoKey (h_key, NULL, NULL, NULL, 
								  &n_numSubKeys, &n_maxSubKeyLen, 
								  &n_maxClassLen,
								  &n_numValues, &n_maxValueNameLen, NULL, 
								  NULL, NULL);
	  RegCloseKey (h_key);
	  return (n_numSubKeys != 0);
	}

AnswerRe: problem in adding node in registry Pin
Cedric Moonen24-Feb-09 20:52
Cedric Moonen24-Feb-09 20:52 
GeneralRe: problem in adding node in registry Pin
sonali996026-Feb-09 19:44
sonali996026-Feb-09 19:44 
QuestionHow do you refresh/update a parent dialog when Modal child dialog is active Pin
JJeffrey24-Feb-09 16:34
JJeffrey24-Feb-09 16:34 
AnswerRe: How do you refresh/update a parent dialog when Modal child dialog is active Pin
ashtwin24-Feb-09 16:57
ashtwin24-Feb-09 16:57 
GeneralRe: How do you refresh/update a parent dialog when Modal child dialog is active Pin
JJeffrey24-Feb-09 21:41
JJeffrey24-Feb-09 21:41 
AnswerRe: How do you refresh/update a parent dialog when Modal child dialog is active Pin
«_Superman_»24-Feb-09 17:41
professional«_Superman_»24-Feb-09 17:41 
QuestionProblem in displaying tooltip Pin
ashtwin24-Feb-09 16:04
ashtwin24-Feb-09 16:04 
AnswerRe: Problem in displaying tooltip Pin
Code-o-mat24-Feb-09 21:40
Code-o-mat24-Feb-09 21:40 
QuestionRe: Problem in displaying tooltip Pin
ashtwin25-Feb-09 1:02
ashtwin25-Feb-09 1:02 
AnswerRe: Problem in displaying tooltip [modified] Pin
Code-o-mat25-Feb-09 1:20
Code-o-mat25-Feb-09 1:20 
GeneralRe: Problem in displaying tooltip Pin
ashtwin25-Feb-09 21:23
ashtwin25-Feb-09 21:23 
QuestionBest Location for DB Files Pin
Bram van Kampen24-Feb-09 14:38
Bram van Kampen24-Feb-09 14:38 
QuestionHow to get the fullpath from argument of my application (VS C++ 2005)? Pin
nhatvhm24-Feb-09 14:05
nhatvhm24-Feb-09 14:05 
AnswerRe: How to get the fullpath from argument of my application (VS C++ 2005)? Pin
W. Kleinschmit24-Feb-09 14:45
W. Kleinschmit24-Feb-09 14:45 
AnswerRe: How to get the fullpath from argument of my application (VS C++ 2005)? Pin
ky_rerun24-Feb-09 14:47
ky_rerun24-Feb-09 14:47 
AnswerRe: How to get the fullpath from argument of my application (VS C++ 2005)? Pin
«_Superman_»24-Feb-09 17:51
professional«_Superman_»24-Feb-09 17:51 
QuestionAll pipes intances are busy Pin
Arif Liminto24-Feb-09 14:04
professionalArif Liminto24-Feb-09 14:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.