📄 wndproc.c
字号:
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (C) 1993-1997 Microsoft Corporation. All Rights Reserved.
//
// MODULE: wndproc.c
//
// PURPOSE: Contains window procedures for the main application windows.
//
// PLATFORMS: Windows CE
//
// FUNCTIONS:
// MainWndProc() - Message handler for the main application window
// Main_OnCommand() - Processes WM_COMMAND messages
// Main_OnDestroy() - Handles the WM_DESTROY message
// AboutDlgProc() - Message handler for the application's about
// dialog.
//
// COMMENTS:
//
//
#include <windows.h>
#include <windowsx.h>
#include <aygshell.h>
#if !defined(_WIN_CE_EMULATION)
#include <memory.h>
#endif
#include <commctrl.h>
#include <tchar.h>
#include "resource.h"
#include "globals.h"
#include "WINDBASE.H"
//----------------------------------------------------------------------------
// Local prototypes
static TBBUTTON tbVIEWButton[] = {
{DB_NEXT_REC, DB_NEXT_REC, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{DB_PREV_REC, DB_PREV_REC, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 1},
{DB_ADD_REC, DB_ADD_REC, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 2}
};
LRESULT OnSetFocus(HWND hwndLostFocus, HWND dummy)
{
SetFocus(g_hwndTreeView);
return 0;
}
//----------------------------------------------------------------------------
//
// FUNCTION: MainWndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main application window.
//
// PARAMETERS:
// hwnd - handle the the window receiving the message
// uMsg - identifier of the message
// wParam - additional info associated with the message
// lParam - additional info associated with the message
//
// RETURN VALUE:
// (LRESULT) Returns 0 by default if the message is handled by this
// procedure.
//
// COMMENTS:
//
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
switch(uMsg)
{
HANDLE_MSG(hwnd, WM_COMMAND, Main_OnCommand);
HANDLE_MSG(hwnd, WM_DESTROY, Main_OnDestroy);
HANDLE_MSG(hwnd, WM_CREATE, Main_OnCreate );
HANDLE_MSG(hwnd, WM_NOTIFY, Main_OnNotify );
HANDLE_MSG(hwnd, WM_SETFOCUS, OnSetFocus); // set focus to treeview
default: // Pass message on for default proccessing
return DefWindowProc( hwnd, uMsg, wParam, lParam );
}
// If we performed non-default processing on the message, return FALSE
return FALSE;
}
//
// 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.
//
LRESULT WINAPI Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch (id)
{
case IDM_FILE_EXIT:
// The user wants to exit, so send our window a close message
SendMessage(hwnd, WM_CLOSE, 0, 0L);
break;
case IDM_HELP_ABOUT:
// Display the "About" dialog
DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, (DLGPROC)AboutDlgProc);
break;
case ID_OBJECTSTORE_STORAGESPACE:
DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_PEGMEMORY), hwnd, (DLGPROC)MemoryDlgProc);
break;
case IDM_CREATEDB:
DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_NEWDBNAME), hwnd, (DLGPROC)NewDBDlgProc);
break;
case IDM_DELETEDB:
DeleteCurrentDB(hwnd);
break;
case DB_NEXT_REC:
SeekNextRecord(hwnd, 1);
break;
case DB_PREV_REC:
SeekNextRecord(hwnd, (DWORD) -1);
break;
case DB_ADD_REC:
AddRecToCurrentDB(hwnd);
break;
case IDM_INDEXDB:
ModifyIndex(hwnd);
break;
case IDM_USEINDEXES:
OpenIndex(hwnd);
break;
default:
return 1L;
}
return 0L;
}
//
// 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.
CommandBar_Destroy(hwndCB);
if ( himl )
ImageList_Destroy(himl);
PostQuitMessage(0);
}
//
// FUNCTION: Main_OnCreate(HWND, LPCREATESTRUCT)
//
// PURPOSE: Create the treeview control and initialize the data
//
// PARAMETERS:
// hwnd - handle of the window receiving this message
// lpCreateStruct - points to a CREATESTRUCT containing information
// about the window creation
//
// RETURN VALUE:
// returns TRUE if the window should be created, FALSE otherwise
//
// COMMENTS:
//
BOOL WINAPI Main_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
{
HWND hwndTV;
RECT rcClient;
BOOL bButton;
SHMENUBARINFO mbi;
// Start by initializing the common control libraries
InitCommonControls();
// Get the client area rect to put the treeview in
GetClientRect(hwnd, &rcClient);
//Create a MenuBar
memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hwnd;
mbi.nToolBarId = IDM_MAIN_MENU;
mbi.hInstRes = g_hInstance;
mbi.nBmpId = 0;
mbi.cBmpImages = 0;
if (!SHCreateMenuBar(&mbi))
MessageBox(hwnd, L"SHCreateMenuBar Failed", L"Error", MB_OK);
else
{
hwndCB = mbi.hwndMB;
CommandBar_AddBitmap(hwndCB, g_hInstance, IDB_BUTTONS, 3, 16, 16);
bButton = CommandBar_AddButtons(hwndCB, 3, tbVIEWButton);
}
// We need to create the treeview control
hwndTV = CreateWindowEx(0, WC_TREEVIEW, TEXT("DB View Control"),
WS_VISIBLE | WS_CHILD | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | WS_BORDER,
0, 0, rcClient.right, rcClient.bottom/2,
hwnd, (HMENU) IDC_TREEVIEW, g_hInstance, NULL);
hwndEdit = CreateWindow(TEXT("EDIT"), TEXT("Property Information"),
WS_VISIBLE | WS_CHILD | ES_MULTILINE | ES_READONLY | WS_VSCROLL | WS_BORDER ,
0, rcClient.bottom/2, rcClient.right, rcClient.bottom/2,
hwnd, (HMENU) IDC_EDITCONTROL, g_hInstance, NULL);
// Make sure the treeview was actually created
if (!hwndTV)
{
ErrorHandler();
return FALSE;
}
// Initialize the image list, and add items to the control.
// InitTreeViewImageLists() and InitTreeViewItems() are defined in treeview.c.
if (!InitDBViewImageLists(hwndTV) || !InitDBViewItems(hwndTV))
{
DestroyWindow(hwndTV);
return FALSE;
}
// Everything is set up correctly, now set the global handle to the treeview
// and finish window creation.
g_hwndTreeView = hwndTV;
return TRUE;
}
//
// FUNCTION: AboutDlgProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the About dialog box
//
// PARAMETERS:
// hwnd - window handle of the dialog box
// uMsg - identifier of the message being handled
// wParam - additional info associated with the message
// lParam - additional info associated with the message
//
// RETURN VALUE:
// Except in response to the WM_INITDIALOG message, the dialog box
// procedure should return nonzero if it processes the message, and zero
// if it does not.
//
// COMMENTS:
//
LRESULT CALLBACK AboutDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
switch(uMsg)
{
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.
return (TRUE);
}
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
EndDialog(hwnd, 0);
break;
case IDCANCEL:
EndDialog(hwnd, 0);
break;
}
return (TRUE);
}
return (FALSE);
}
BOOL CALLBACK AddRecDlgProc( HWND hWnd,UINT message, WPARAM wParam, LPARAM lParam )
{
WORD wNotifyCode, wID;
HWND hwndCtl;
static INSERTSTRUCT * pInsert;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -