📄 babygrid_demo.cpp
字号:
// BABYGRID_DEMO.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
#include "babygrid.h" // <------- You must include the babygrid.h header file
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
_BGCELL cell; // <----------- You'll need to define at least one of these
// to reference the grid cells for entering or
// retreiving data from the grid
HWND hgrid1,hgrid2; // <------------ Window handles of the grids you'll create
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
void LoadGrid1(HWND);
void LoadGrid2(HWND);
void SetCell(HWND,int,int,char*);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_BABYGRID_DEMO, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_BABYGRID_DEMO);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_BABYGRID_DEMO);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_BABYGRID_DEMO;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
case 500: //properties grid notification that something happened
{
if(HIWORD(wParam)==BGN_CELLCLICKED) //a cell was clicked in the properties grid
{
int row,col,dtype;
//get the row and column of the clicked cell
row=LOWORD(lParam);
col=HIWORD(lParam);
//set the _BGCELL structure variable (cell) to this row and column
SetCell(&cell,row,col);
//get the data type that is in the cell
//in this instance, we're looking for BOOLEAN data (types 3 [TRUE] or 4 [FALSE])
//datatype 1 is alphanumeric data
//datatype 2 is numeric data
//datatype 3 is BOOLEAN TRUE data
//datatype 4 is BOOLEAN FALSE data
dtype=SendMessage(hgrid1,BGM_GETTYPE,(UINT)&cell,0);
if(dtype == 3) //bool true
{
//if the grid cell was true (checked checkbox), toggle it false
SendMessage(hgrid1,BGM_SETCELLDATA,(UINT)&cell,(long)"FALSE");
//send appropriate control message to the grid based
//on the row of the cell that was toggled
if(row==1)
{
SendMessage(hgrid2,BGM_SETALLOWCOLRESIZE,FALSE,0);
}
if(row==2)
{
SendMessage(hgrid2,BGM_SETEDITABLE,FALSE,0);
}
if(row==3)
{
SendMessage(hgrid2,BGM_SETELLIPSIS,FALSE,0);
}
if(row==4)
{
SendMessage(hgrid2,BGM_SETCOLAUTOWIDTH,FALSE,0);
}
if(row==5)
{
SendMessage(hgrid2,BGM_EXTENDLASTCOLUMN,FALSE,0);
}
if(row==6)
{
SendMessage(hgrid2,BGM_SETCOLSNUMBERED,FALSE,0);
LoadGrid2(hgrid2);
}
if(row==7)
{
SendMessage(hgrid2,BGM_SETROWSNUMBERED,FALSE,0);
}
if(row==8)
{
SendMessage(hgrid2,BGM_SHOWHILIGHT,FALSE,0);
}
if(row==9)
{
SendMessage(hgrid2,BGM_SETCURSORCOLOR,(UINT)RGB(0,0,0),0);
}
if(row==10)
{
SendMessage(hgrid2,BGM_SETGRIDLINECOLOR,(UINT)RGB(255,255,255),0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -