?? babygrid.cpp
字號:
for(j=0;j<(int)lstrlen(text);j++)
{
if(text[j]=='\n')
{
lines++;
}
}
lstrcpy(temptext,text);
p = generic_strtok(temptext, TEXT("\n"));
while(p)
{
GetTextExtentPoint32(hdc,p,lstrlen(p),size);
if(size->cx > longest)
{
longest=size->cx;
}
p = generic_strtok('\0', TEXT("\n"));
}
return longest;
}
LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR buffer[1000];
int SelfIndex;
int ReturnValue;
UINT SelfMenu;
HINSTANCE hInst;
int iDataType;
static int ASCII;
SelfIndex=FindGrid((UINT)GetMenu(hWnd));
SelfMenu=BGHS[SelfIndex].gridmenu;
//update the grid width and height variable
{
RECT rect;
GetClientRect(hWnd,&rect);
BGHS[SelfIndex].gridwidth = rect.right - rect.left;
BGHS[SelfIndex].gridheight = rect.bottom - rect.top;
}
ReturnValue = 0;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case 1:
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
RECT rt;
GetClientRect(hWnd, &rt);
CalcVisibleCellBoundaries(SelfIndex);
//display title
DisplayTitle(hWnd,SelfIndex,BGHS[SelfIndex].htitlefont);
//display column 0;
DisplayColumn(hWnd,SelfIndex,0,0,BGHS[SelfIndex].hfont,BGHS[SelfIndex].hcolumnheadingfont);
{
int c,j,k,offset;
offset = BGHS[SelfIndex].columnwidths[0];
j=BGHS[SelfIndex].leftvisiblecol;
k=BGHS[SelfIndex].rightvisiblecol;
for(c=j;c<=k;c++)
{
DisplayColumn(hWnd,SelfIndex,c,offset,BGHS[SelfIndex].hfont,BGHS[SelfIndex].hcolumnheadingfont);
offset+=BGHS[SelfIndex].columnwidths[c];
}
}
EndPaint(hWnd, &ps);
//
if(GetFocus()==hWnd)
{
PostMessage(hWnd,BGM_DRAWCURSOR,(UINT)SelfIndex,0);
}
break;
case BGM_PAINTGRID:
{
RECT rect;
GetClientRect(hWnd, &rect);
InvalidateRect(hWnd,&rect,TRUE);
UpdateWindow(hWnd);
MessageBeep(0);
}
break;
case WM_SETTEXT:
{
int j,linecount;
SIZE size;
HDC gdc;
HFONT holdfont;
if(lstrlen((TCHAR*)lParam)>300)
{
lstrcpy(BGHS[SelfIndex].title, TEXT("Title too long (300 chars max)"));
}
else
{
lstrcpy(BGHS[SelfIndex].title,(TCHAR*)lParam);
}
gdc=GetDC(hWnd);
//get linecount of title;
if(lstrlen(BGHS[SelfIndex].title) > 0)
{
linecount=1;
for(j=0;j<(int)lstrlen(BGHS[SelfIndex].title);j++)
{
if(BGHS[SelfIndex].title[j]=='\n')
{
linecount++;
}
}
holdfont=(HFONT)SelectObject(gdc,BGHS[SelfIndex].htitlefont);
GetTextExtentPoint32(gdc,BGHS[SelfIndex].title,lstrlen(BGHS[SelfIndex].title),&size);
SelectObject(gdc,holdfont);
BGHS[SelfIndex].titleheight = (int)((size.cy*1.2) * linecount);
}
else
{
//no title
BGHS[SelfIndex].titleheight = 0;
}
ReleaseDC(hWnd,gdc);
RefreshGrid(hWnd);
SizeGrid(hWnd,SelfIndex);
}
break;
case BGM_GETROWS:
ReturnValue = BGHS[SelfIndex].rows;
break;
case BGM_GETCOLS:
ReturnValue = BGHS[SelfIndex].cols;
break;
case BGM_GETCOLWIDTH:
ReturnValue = BGHS[SelfIndex].columnwidths[wParam];
break;
case BGM_GETROWHEIGHT:
ReturnValue = BGHS[SelfIndex].rowheight;
break;
case BGM_GETHEADERROWHEIGHT:
ReturnValue = BGHS[SelfIndex].headerrowheight;
break;
case BGM_GETOWNERDRAWITEM:
ReturnValue = BGHS[SelfIndex].ownerdrawitem;
break;
case BGM_DRAWCURSOR:
DrawCursor(hWnd,wParam);
break;
case BGM_SETCURSORPOS:
DrawCursor(hWnd,SelfIndex);
if((((int)wParam <= BGHS[SelfIndex].rows)&&((int)wParam > 0))&&
(((int)lParam <= BGHS[SelfIndex].cols)&&((int)lParam > 0)))
{
BGHS[SelfIndex].cursorrow=wParam;
BGHS[SelfIndex].cursorcol=lParam;
}
else
{
DrawCursor(hWnd,SelfIndex);
break;
}
SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol);
SetHomeCol(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol);
DrawCursor(hWnd,SelfIndex);
RefreshGrid(hWnd);
break;
case BGM_SHOWHILIGHT:
BGHS[SelfIndex].DRAWHIGHLIGHT = (BOOL)wParam;
RefreshGrid(hWnd);
break;
case BGM_EXTENDLASTCOLUMN:
BGHS[SelfIndex].EXTENDLASTCOLUMN = (BOOL)wParam;
RefreshGrid(hWnd);
break;
case BGM_SHOWINTEGRALROWS:
BGHS[SelfIndex].SHOWINTEGRALROWS = (BOOL)wParam;
SizeGrid(hWnd,SelfIndex);
RefreshGrid(hWnd);
break;
case BGM_SETCOLAUTOWIDTH:
BGHS[SelfIndex].COLAUTOWIDTH = (BOOL)wParam;
break;
case BGM_SETALLOWCOLRESIZE:
BGHS[SelfIndex].ALLOWCOLUMNRESIZING = (BOOL)wParam;
break;
case BGM_PROTECTCELL:
LPBGcell=(_BGCELL*)wParam;
if(OutOfRange(LPBGcell))
{
wParam=MAKEWPARAM((UINT)GetMenu(hWnd),BGN_OUTOFRANGE);
lParam = 0;
SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam);
ReturnValue = -1;
break;
}
wsprintf(buffer, TEXT("%05d-%03d"), LPBGcell->row,LPBGcell->col);
//see if that cell is already loaded
FindResult = BinarySearchListBox(BGHS[SelfIndex].hlist1,buffer);
if(FindResult != LB_ERR)
{
//it was found, get the text, modify text delete it from list, add modified to list
SendMessage(BGHS[SelfIndex].hlist1,LB_GETTEXT,FindResult,(LPARAM)buffer);
if((BOOL)lParam)
{
buffer[10] = 'P';
}
else
{
buffer[10] = 'U';
}
SendMessage(BGHS[SelfIndex].hlist1,LB_DELETESTRING,FindResult,0);
SendMessage(BGHS[SelfIndex].hlist1,LB_ADDSTRING,FindResult,(LPARAM)buffer);
}
else
{
//protecting or unprotecting a cell that isn't in the list
//add it as blank;
lstrcat(buffer, TEXT("|"));
if((BOOL)lParam)
{
lstrcat(buffer, TEXT("PA"));
}
else
{
lstrcat(buffer, TEXT("UA"));
}
lstrcat(buffer, TEXT("|"));
SendMessage(BGHS[SelfIndex].hlist1,LB_ADDSTRING,FindResult,(LPARAM)buffer);
}
break;
case BGM_NOTIFYROWCHANGED:
NotifyRowChanged(hWnd,SelfIndex);
break;
case BGM_NOTIFYCOLCHANGED:
NotifyColChanged(hWnd,SelfIndex);
break;
case BGM_SETPROTECT:
if((BOOL)wParam)
{
lstrcpy(BGHS[SelfIndex].protect, TEXT("P"));
}
else
{
lstrcpy(BGHS[SelfIndex].protect, TEXT("U"));
}
break;
case BGM_AUTOROW:
if((BOOL)wParam)
{
BGHS[SelfIndex].AUTOROW = TRUE;
}
else
{
BGHS[SelfIndex].AUTOROW = FALSE;
}
break;
case BGM_SETEDITABLE:
if((BOOL)wParam)
{
BGHS[SelfIndex].EDITABLE = TRUE;
}
else
{
BGHS[SelfIndex].EDITABLE = FALSE;
}
break;
case BGM_SETCELLDATA:
LPBGcell=(_BGCELL*)wParam;
if(OutOfRange(LPBGcell))
{
wParam=MAKEWPARAM((UINT)GetMenu(hWnd),BGN_OUTOFRANGE);
lParam = 0;
SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam);
ReturnValue = -1;
break;
}
wsprintf(buffer, TEXT("%05d-%03d"), LPBGcell->row,LPBGcell->col);
//see if that cell is already loaded
FindResult = BinarySearchListBox(BGHS[SelfIndex].hlist1,buffer);
if(FindResult != LB_ERR)
{
//it was found, delete it
SendMessage(BGHS[SelfIndex].hlist1,LB_DELETESTRING,FindResult,0);
}
//now add it
lstrcat(buffer, TEXT("|"));
lstrcat(buffer,BGHS[SelfIndex].protect);
//determine data type (text,numeric, or boolean)(1,2,3)
//iDataType=DetermineDataType((TCHAR*)lParam);
iDataType = 1;
if(iDataType==1){lstrcat(buffer, TEXT("A"));}
if(iDataType==2){lstrcat(buffer, TEXT("N"));}
if(iDataType==3){lstrcat(buffer, TEXT("T"));}
if(iDataType==4){lstrcat(buffer, TEXT("F"));}
if(iDataType==5){lstrcat(buffer, TEXT("G"));}
lstrcat(buffer, TEXT("|"));
lstrcat(buffer, (TCHAR*)lParam);
FindResult=SendMessage(BGHS[SelfIndex].hlist1,LB_ADDSTRING,0,(LPARAM)buffer);
if(FindResult==LB_ERR)
{
MessageBeep(0);
}
{
RECT rect;
rect=GetCellRect(hWnd,SelfIndex,LPBGcell->row,LPBGcell->col);
InvalidateRect(hWnd,&rect,FALSE);
}
//get the last line and adjust grid dimmensions
if(BGHS[SelfIndex].AUTOROW)
{
int j;
j=SendMessage(BGHS[SelfIndex].hlist1,LB_GETCOUNT,0,0);
if(j>0)
{
SendMessage(BGHS[SelfIndex].hlist1,LB_GETTEXT,j-1,(LPARAM)buffer);
buffer[5]=0x00;
j=generic_atoi(buffer);
if(j>SendMessage(hWnd,BGM_GETROWS,0,0))
{
SendMessage(hWnd,BGM_SETGRIDDIM,j,BGHS[SelfIndex].cols);
}
}
else
{
//no items in the list
SendMessage(hWnd,BGM_SETGRIDDIM,j,BGHS[SelfIndex].cols);
}
}
//adjust the column width if COLAUTOWIDTH==TRUE
if((BGHS[SelfIndex].COLAUTOWIDTH)||(LPBGcell->row == 0))
{
HDC hdc;
SIZE size;
int required_width;
int current_width;
int required_height = 30;
int current_height;
int longestline;
HFONT holdfont;
hdc=GetDC(hWnd);
if(LPBGcell->row == 0)
{
holdfont=(HFONT)SelectObject(hdc,BGHS[SelfIndex].hcolumnheadingfont);
}
else
{
holdfont=(HFONT)SelectObject(hdc,BGHS[SelfIndex].hfont);
}
//if there are \n codes in the generic_string, find the longest line
longestline=FindLongestLine(hdc,(TCHAR*)lParam,&size);
//GetTextExtentPoint32(hdc,(TCHAR*)lParam,lstrlen((TCHAR*)lParam),&size);
required_width = longestline+15;
required_height = size.cy;
//count lines
{
int count=1;
TCHAR tbuffer[255];
lstrcpy(tbuffer,(TCHAR*)lParam);
for(int j=0;j<(int)lstrlen(tbuffer);j++)
{
if(tbuffer[j]=='\n'){count++;}
}
if((!BGHS[SelfIndex].ELLIPSIS)||(LPBGcell->row == 0))
{
required_height *= count;
}
required_height +=5;
}
SelectObject(hdc,holdfont);
ReleaseDC(hWnd,hdc);
current_width = BGHS[SelfIndex].columnwidths[LPBGcell->col];
if(LPBGcell->row == 0)
{
current_height = BGHS[SelfIndex].headerrowheight;
if(required_height > current_height)
{
SendMessage(hWnd,BGM_SETHEADERROWHEIGHT,required_height,0);
}
}
else
{
current_height = BGHS[SelfIndex].rowheight;
if(required_height > current_height)
{
SendMessage(hWnd, BGM_SETROWHEIGHT, /*required_height*/20, 0);
}
}
if(required_width > current_width)
{
SendMessage(hWnd,BGM_SETCOLWIDTH,LPBGcell->col,required_width);
}
ReleaseDC(hWnd,hdc);
}
break;
case BGM_GETCELLDATA:
LPBGcell=(_BGCELL*)wParam;
if(OutOfRange(LPBGcell))
{
wParam=MAKEWPARAM((UINT)GetMenu(hWnd),BGN_OUTOFRANGE);
lParam = 0;
SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam);
ReturnValue = -1;
break;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -