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

📄 wndproc.c

📁 EVC4 编程CEDB数据库操作
💻 C
📖 第 1 页 / 共 2 页
字号:
  wNotifyCode = HIWORD(wParam); // notification code
  wID = LOWORD(wParam);         // item, control, or accelerator identifier
  hwndCtl = (HWND) lParam;      // handle of control

  switch(message)
  {
	case WM_INITDIALOG:
	{
		//On Pocket PC devices you normally create all Dialog's as fullscreen dialog's
		// with an OK button in the upper corner. You should get/set any program settings
		// during each modal dialog creation and destruction
		SHINITDLGINFO shidi;
		// Create a Done button and size it.
		shidi.dwMask = SHIDIM_FLAGS;
		shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
		shidi.hDlg = hWnd;
		//initialzes the dialog based on the dwFlags parameter
		SHInitDialog(&shidi);

	    // Should return nonzero to set focus to the first control in the
	    // dialog, or zero if this routine sets the focus manually.
		pInsert = (INSERTSTRUCT *) lParam;
	    return (TRUE);
	}
	  case WM_COMMAND:
	  {
			switch(wID)
			{
				case IDCANCEL:
						EndDialog(hWnd, IDCANCEL);
						break;
				case IDC_SAVE:
				{
					BOOL bTranslS, bTranslUS;
					DWORD  cbLong, cbULong, cbString, cbBlob;
					TCHAR * pszLong, *pszULong, * pString;
					BYTE  * pBlob;
					UINT	unChars;
                    BOOL bStatus = TRUE;

                    // Initialize Properties structure
					pInsert->shNumber = 0;
                    pInsert->ushNumber = 0;
                    pInsert->lNumber = 0;
                    pInsert->ulNumber = 0;
                    pInsert->pString = NULL;
					pInsert->pBlob = NULL;
					pInsert->cbBlob = 0;

					
					// Short
                    pInsert->shNumber = (short) GetDlgItemInt(hWnd,IDC_SHORT,&bTranslS,TRUE );	

                    // Unsigned Short
					pInsert->ushNumber = GetDlgItemInt(hWnd,IDC_USHORT,&bTranslUS,FALSE );	

                    // Long
                    cbLong = SendDlgItemMessage(hWnd, IDC_LONG, WM_GETTEXTLENGTH, 0, 0);
					pszLong = (TCHAR *)LocalAlloc( LPTR , max(cbLong, (cbLong * sizeof(TCHAR) + sizeof(TCHAR))));
					if ( pszLong && bStatus)
					{
						if ( unChars = GetDlgItemText(hWnd,IDC_LONG,pszLong, cbLong) )
							pInsert->lNumber = _ttol(pszLong);
                        LocalFree(pszLong);
					}
                    else
                    {
						TCHAR szError[50];
						wsprintf(szError, TEXT("ERROR: could not allocate memory for field 'Long'."), GetLastError());
						OutputDebugString(szError);
						MessageBox(hWnd, szError, TEXT("Error"), MB_OK);                                            
                        bStatus = FALSE;
                    }

                    // Unsigned Long
                    cbULong = SendDlgItemMessage(hWnd, IDC_ULONG, WM_GETTEXTLENGTH, 0, 0);
					pszULong = (TCHAR *)LocalAlloc( LPTR , max(cbULong, (cbLong * sizeof(TCHAR) + sizeof(TCHAR))));
					if ( pszULong)
					{
						if ( unChars = GetDlgItemText(hWnd,IDC_ULONG,pszULong,cbULong) )
							pInsert->ulNumber = (unsigned long) _ttol(pszULong);
                        LocalFree(pszULong);
					}

					// String
                    cbString = SendDlgItemMessage(hWnd, IDC_STRING, WM_GETTEXTLENGTH, 0, 0);
					pString = (TCHAR *) LocalAlloc( LPTR , (cbString * sizeof(TCHAR) + sizeof(TCHAR)));
					if ( pString)
					{
						if ( unChars = GetDlgItemText(hWnd,IDC_STRING, pString, (INT) cbString))
							pInsert->pString = pString;
					    LocalFree(pString);
                    }

                    // Blob
                    cbBlob = SendDlgItemMessage(hWnd, IDC_BLOB, WM_GETTEXTLENGTH, 0, 0);
					pBlob = (BYTE *) LocalAlloc( LPTR , (cbBlob * sizeof(TCHAR) + sizeof(TCHAR)));
					if ( pBlob)
					{
						if ( unChars = GetDlgItemText(hWnd,IDC_BLOB,(TCHAR *)pBlob, cbBlob) )
						{
							pInsert->pBlob = pBlob;
							pInsert->cbBlob = cbBlob * sizeof(TCHAR);
						}
                        LocalFree(pBlob);
					}
					
					EndDialog(hWnd, IDOK);
					break;
				}
				default:
					return(FALSE);
			}
			break;
	  }
	  default:
		  return(FALSE);
  }
  return (TRUE);
}



//
//  FUNCTION:   Main_OnNotify(HWND, int, LPNMHDR)
//
//  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 WINAPI Main_OnNotify(HWND hwnd, int idCtl, LPNMHDR pnmh)
{
	HTREEITEM hti, htiNext;

	switch (pnmh->code)
	{
		// A directory node has been collapsed.  Now we can remove the child items
		// from the node.

		case TVN_SELCHANGED:
		{

			HTREEITEM hti;
			TV_ITEM	  ParentItem;
			TCHAR szEntryName[CEDB_MAXDBASENAMELEN];
			LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW) pnmh;

			if ( bRemovingProps )
				break;

			OutputDebugString(TEXT("Item selected\r\n"));


			// Check to see if this is a database or property
			// if item has no parent then database
			if ( !(hti=TreeView_GetParent(pnmh->hwndFrom, pnmtv->itemNew.hItem )) )
			{
				
				OutputDebugString(TEXT("Display Database Information\r\n"));

				// Get the text parent
				pnmtv->itemNew.mask |= TVIF_TEXT;
				pnmtv->itemNew.pszText = szEntryName;
				pnmtv->itemNew.cchTextMax =  CEDB_MAXDBASENAMELEN;

				if (!TreeView_GetItem(pnmtv->hdr.hwndFrom, &pnmtv->itemNew))
					return (FALSE);
				else
				{
					// Show DB Properties
					ShowDBInformation(szEntryName);

				}

			}
			else                                                             // database property
			{
				DWORD dwOpenHandle = (DWORD) INVALID_HANDLE_VALUE;
				ParentItem.hItem = hti;
				ParentItem.mask = TVIF_PARAM;

				if ( TreeView_GetItem(pnmh->hwndFrom, &ParentItem) )
					dwOpenHandle = ParentItem.lParam;

				OutputDebugString(TEXT("Display Database Property Information\r\n"));

				// Get the text child property
				pnmtv->itemNew.mask |= (TVIF_TEXT | TVIF_PARAM);
				pnmtv->itemNew.pszText = szEntryName;
				pnmtv->itemNew.cchTextMax = CEDB_MAXDBASENAMELEN;

				if (!TreeView_GetItem(pnmtv->hdr.hwndFrom, &pnmtv->itemNew))
					return (FALSE);
				else
				{
				   ShowPropDesc(pnmtv->itemNew.lParam, dwOpenHandle, -1);

				}


			}
			break;
		}



		case TVN_ITEMEXPANDED:
		{
			LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW) pnmh;

			if (pnmtv->action == TVE_COLLAPSE)
			{
				OutputDebugString(TEXT("Item collapsed\r\n"));

				// Now actually remove the child items within this directory
				hti = TreeView_GetChild(pnmh->hwndFrom, pnmtv->itemNew.hItem);
				while (hti)
				{
					htiNext = TreeView_GetNextSibling(pnmh->hwndFrom, hti);
					TreeView_DeleteItem(pnmh->hwndFrom, hti);
					hti = htiNext;
				}
			}

			return (FALSE);
		}
			
	// 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:
		{
			// cast the NMHDR into a treeview notify structure
			LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW) pnmh;

			if (pnmtv->action == TVE_COLLAPSE)
			{
				OutputDebugString(TEXT("Item collapsing\r\n"));

				// 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 = IMAGE_CLOSED;
				pnmtv->itemNew.iSelectedImage = IMAGE_CLOSED;
		
				TreeView_SetItem(pnmh->hwndFrom, &(pnmtv->itemNew));
			}
			else
			{
				TCHAR szDBName[CEDB_MAXDBASENAMELEN];
				OutputDebugString(TEXT("Item expanding\r\n"));

				// 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 = IMAGE_OPEN;
				pnmtv->itemNew.iSelectedImage = IMAGE_OPEN;
				TreeView_SetItem(pnmh->hwndFrom, &(pnmtv->itemNew));

				// Get the text for the first item
				pnmtv->itemNew.mask |= (TVIF_TEXT|TVIF_PARAM);
				pnmtv->itemNew.pszText = szDBName;
				pnmtv->itemNew.cchTextMax =  CEDB_MAXDBASENAMELEN;
				if (!TreeView_GetItem(pnmtv->hdr.hwndFrom, &pnmtv->itemNew))
					return (FALSE);
				else
					EnumDbaseProps(pnmtv->hdr.hwndFrom, (HTREEITEM)pnmtv->itemNew.hItem, pnmtv->itemNew.lParam);

			}

			return (FALSE); // return value is ignored
		}

	// The mouse has been clicked within the control.  We need to determine
	// if the click is over the state image and if so toggle the check box.
		case NM_CLICK:
		{
			UINT                    state;
			DWORD                   dwPos;
			TV_HITTESTINFO			tvhti;
			HTREEITEM               htiItemClicked;
			POINT                   point;
			HWND                    hwndTV = GetDlgItem(hwnd, IDC_TREEVIEW);
			TV_ITEM					tvi;
	
            // Find out where the cursor was
			dwPos = GetMessagePos();
			point.x = LOWORD(dwPos);
			point.y = HIWORD(dwPos);

			ScreenToClient(hwndTV, &point);

			tvhti.pt = point;
			htiItemClicked = TreeView_HitTest(hwndTV, &tvhti);

			// Now get the state information from the item and toggle it
			if (tvhti.flags & TVHT_ONITEMSTATEICON)
			{
				// Fill out the TV_ITEM struct to get the state image mask and
				// get the item from the control
				tvi.hItem = htiItemClicked;
				tvi.mask = TVIF_STATE;
				tvi.stateMask = TVIS_STATEIMAGEMASK;
				TreeView_GetItem(hwndTV, &tvi);

				// Now toggle the state
				state = tvi.state;
				tvi.state = (state & INDEXTOSTATEIMAGEMASK(TVIS_GCNOCHECK)) ?
						INDEXTOSTATEIMAGEMASK(TVIS_GCCHECK) :
							INDEXTOSTATEIMAGEMASK(TVIS_GCNOCHECK);

				// And finally set the new state of the item back into the
				// control
				TreeView_SetItem(hwndTV, &tvi);
			}

	    return (0L);    // Return value is ignored
		}
	}
	return (0L);
}

⌨️ 快捷键说明

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