Reformat some codes

This commit is contained in:
Don HO 2020-01-10 20:11:36 +01:00
parent 87d6cd1d04
commit 638ff65ba1
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E

View File

@ -1291,33 +1291,29 @@ ATOM RegisterGridClass(HINSTANCE hInstance)
void SizeGrid(HWND hWnd,int /*SI*/) void SizeGrid(HWND hWnd,int /*SI*/)
{ {
SendMessage(hWnd,WM_SIZE,SIZE_MAXIMIZED,0); SendMessage(hWnd,WM_SIZE,SIZE_MAXIMIZED,0);
//obsolete }
//SendMessage(hWnd,WM_SIZE,SIZE_MAXIMIZED,MAKELPARAM(BGHS[SI].wannabewidth,BGHS[SI].wannabeheight));
//SendMessage(hWnd,WM_SIZE,SIZE_MAXIMIZED,MAKELPARAM(BGHS[SI].wannabewidth,BGHS[SI].wannabeheight));
}
int FindLongestLine(HDC hdc,TCHAR* text,SIZE* size) int FindLongestLine(HDC hdc, wchar_t* text, SIZE* size)
{ {
int longest = 0; int longest = 0;
TCHAR temptext[1000]; wchar_t temptext[1000];
TCHAR *p; wchar_t *p;
wcscpy_s(temptext,text); wcscpy_s(temptext, text);
p = wcstok(temptext, TEXT("\n")); p = wcstok(temptext, TEXT("\n"));
while(p) while (p)
{ {
GetTextExtentPoint32(hdc,p,lstrlen(p),size); GetTextExtentPoint32(hdc, p, lstrlen(p), size);
if(size->cx > longest) if (size->cx > longest)
{ {
longest=size->cx; longest=size->cx;
} }
TCHAR temptext2[2]; wchar_t temptext2[2] = {'\0'};
temptext2[0] = TEXT('\0'); p = wcstok(temptext2, TEXT("\n"));
p = wcstok(temptext2, TEXT("\n")); }
} return longest;
return longest;
} }
@ -1376,18 +1372,18 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
//display column 0; //display column 0;
DisplayColumn(hWnd,SelfIndex,0,0,BGHS[SelfIndex].hfont,BGHS[SelfIndex].hcolumnheadingfont); DisplayColumn(hWnd,SelfIndex,0,0,BGHS[SelfIndex].hfont,BGHS[SelfIndex].hcolumnheadingfont);
{ {
int c,j,k,offset; int c,j,k,offset;
offset = BGHS[SelfIndex].columnwidths[0]; offset = BGHS[SelfIndex].columnwidths[0];
j=BGHS[SelfIndex].leftvisiblecol; j=BGHS[SelfIndex].leftvisiblecol;
k=BGHS[SelfIndex].rightvisiblecol; k=BGHS[SelfIndex].rightvisiblecol;
for(c=j;c<=k;c++) for(c=j;c<=k;c++)
{ {
DisplayColumn(hWnd,SelfIndex,c,offset,BGHS[SelfIndex].hfont,BGHS[SelfIndex].hcolumnheadingfont); DisplayColumn(hWnd,SelfIndex,c,offset,BGHS[SelfIndex].hfont,BGHS[SelfIndex].hcolumnheadingfont);
offset+=BGHS[SelfIndex].columnwidths[c]; offset+=BGHS[SelfIndex].columnwidths[c];
} }
} }
EndPaint(hWnd, &ps); EndPaint(hWnd, &ps);
// //
if(GetFocus()==hWnd) if(GetFocus()==hWnd)
@ -1400,33 +1396,34 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case BGM_PAINTGRID: case BGM_PAINTGRID:
{ {
RECT rect; RECT rect;
GetClientRect(hWnd, &rect); GetClientRect(hWnd, &rect);
InvalidateRect(hWnd,&rect,TRUE); InvalidateRect(hWnd,&rect,TRUE);
UpdateWindow(hWnd); UpdateWindow(hWnd);
MessageBeep(0); MessageBeep(0);
} }
break; break;
case WM_SETTEXT: case WM_SETTEXT:
{ {
int j,linecount; int j,linecount;
SIZE size; SIZE size;
HDC gdc; HDC gdc;
HFONT holdfont; HFONT holdfont;
if(lstrlen((TCHAR*)lParam)>300) if(lstrlen((TCHAR*)lParam)>300)
{ {
wcscpy_s(BGHS[SelfIndex].title, TEXT("Title too long (300 chars max)")); wcscpy_s(BGHS[SelfIndex].title, TEXT("Title too long (300 chars max)"));
} }
else else
{ {
wcscpy_s(BGHS[SelfIndex].title,(TCHAR*)lParam); wcscpy_s(BGHS[SelfIndex].title,(TCHAR*)lParam);
} }
gdc=GetDC(hWnd); gdc=GetDC(hWnd);
//get linecount of title; //get linecount of title;
if(lstrlen(BGHS[SelfIndex].title) > 0) if(lstrlen(BGHS[SelfIndex].title) > 0)
{ {
linecount=1; linecount=1;
for (j = 0; j<static_cast<int>(lstrlen(BGHS[SelfIndex].title)); j++) for (j = 0; j<static_cast<int>(lstrlen(BGHS[SelfIndex].title)); j++)
{ {
@ -1434,26 +1431,26 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
linecount++; linecount++;
} }
} }
holdfont=(HFONT)SelectObject(gdc,BGHS[SelfIndex].htitlefont); holdfont=(HFONT)SelectObject(gdc,BGHS[SelfIndex].htitlefont);
GetTextExtentPoint32(gdc,BGHS[SelfIndex].title,lstrlen(BGHS[SelfIndex].title),&size); GetTextExtentPoint32(gdc,BGHS[SelfIndex].title,lstrlen(BGHS[SelfIndex].title),&size);
SelectObject(gdc,holdfont); SelectObject(gdc,holdfont);
BGHS[SelfIndex].titleheight = static_cast<int>((size.cy*1.2) * linecount); BGHS[SelfIndex].titleheight = static_cast<int>((size.cy*1.2) * linecount);
} }
else else
{ {
//no title //no title
BGHS[SelfIndex].titleheight = 0; BGHS[SelfIndex].titleheight = 0;
} }
ReleaseDC(hWnd,gdc); ReleaseDC(hWnd,gdc);
RefreshGrid(hWnd); RefreshGrid(hWnd);
SizeGrid(hWnd,SelfIndex); SizeGrid(hWnd,SelfIndex);
}
break;
}
break;
case BGM_GETROWS: case BGM_GETROWS:
ReturnValue = BGHS[SelfIndex].rows; ReturnValue = BGHS[SelfIndex].rows;
break; break;
@ -1485,15 +1482,15 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
DrawCursor(hWnd,SelfIndex); DrawCursor(hWnd,SelfIndex);
if((((int)wParam <= BGHS[SelfIndex].rows)&&((int)wParam > 0))&& if((((int)wParam <= BGHS[SelfIndex].rows)&&((int)wParam > 0))&&
(((int)lParam <= BGHS[SelfIndex].cols)&&((int)lParam > 0))) (((int)lParam <= BGHS[SelfIndex].cols)&&((int)lParam > 0)))
{ {
BGHS[SelfIndex].cursorrow = static_cast<int32_t>(wParam); BGHS[SelfIndex].cursorrow = static_cast<int32_t>(wParam);
BGHS[SelfIndex].cursorcol = static_cast<int32_t>(lParam); BGHS[SelfIndex].cursorcol = static_cast<int32_t>(lParam);
} }
else else
{ {
DrawCursor(hWnd,SelfIndex); DrawCursor(hWnd,SelfIndex);
break; break;
} }
SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol);
SetHomeCol(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); SetHomeCol(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol);
DrawCursor(hWnd,SelfIndex); DrawCursor(hWnd,SelfIndex);
@ -1547,18 +1544,18 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case BGM_PROTECTCELL: case BGM_PROTECTCELL:
LPBGcell=(_BGCELL*)wParam; LPBGcell=(_BGCELL*)wParam;
if(OutOfRange(LPBGcell)) if(OutOfRange(LPBGcell))
{ {
wParam=MAKEWPARAM(GetMenu(hWnd),BGN_OUTOFRANGE); wParam=MAKEWPARAM(GetMenu(hWnd),BGN_OUTOFRANGE);
lParam = 0; lParam = 0;
SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam);
ReturnValue = -1; ReturnValue = -1;
break; break;
} }
wsprintf(buffer, TEXT("%05d-%03d"), LPBGcell->row,LPBGcell->col); wsprintf(buffer, TEXT("%05d-%03d"), LPBGcell->row,LPBGcell->col);
//see if that cell is already loaded //see if that cell is already loaded
FindResult = BinarySearchListBox(BGHS[SelfIndex].hlist1,buffer); FindResult = BinarySearchListBox(BGHS[SelfIndex].hlist1,buffer);
if(FindResult != LB_ERR) if(FindResult != LB_ERR)
{ {
//it was found, get the text, modify text delete it from list, add modified to list //it was found, get the text, modify text delete it from list, add modified to list
auto lbTextLen = ::SendMessage(BGHS[SelfIndex].hlist1, LB_GETTEXTLEN, FindResult, 0); auto lbTextLen = ::SendMessage(BGHS[SelfIndex].hlist1, LB_GETTEXTLEN, FindResult, 0);
if (lbTextLen > bufferLen) if (lbTextLen > bufferLen)
@ -1567,15 +1564,15 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
SendMessage(BGHS[SelfIndex].hlist1, LB_GETTEXT, FindResult, reinterpret_cast<LPARAM>(buffer)); SendMessage(BGHS[SelfIndex].hlist1, LB_GETTEXT, FindResult, reinterpret_cast<LPARAM>(buffer));
if((BOOL)lParam) if((BOOL)lParam)
{ {
buffer[10] = 'P'; buffer[10] = 'P';
} }
else else
{ {
buffer[10] = 'U'; buffer[10] = 'U';
} }
SendMessage(BGHS[SelfIndex].hlist1, LB_DELETESTRING, FindResult, 0); SendMessage(BGHS[SelfIndex].hlist1, LB_DELETESTRING, FindResult, 0);
SendMessage(BGHS[SelfIndex].hlist1, LB_ADDSTRING, FindResult, reinterpret_cast<LPARAM>(buffer)); SendMessage(BGHS[SelfIndex].hlist1, LB_ADDSTRING, FindResult, reinterpret_cast<LPARAM>(buffer));
} }
else else
{ {
//protecting or unprotecting a cell that isn't in the list //protecting or unprotecting a cell that isn't in the list
@ -1601,35 +1598,35 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
NotifyColChanged(hWnd,SelfIndex); NotifyColChanged(hWnd,SelfIndex);
break; break;
case BGM_SETPROTECT: case BGM_SETPROTECT:
if((BOOL)wParam) if((BOOL)wParam)
{ {
wcscpy_s(BGHS[SelfIndex].protect, TEXT("P")); wcscpy_s(BGHS[SelfIndex].protect, TEXT("P"));
} }
else else
{ {
wcscpy_s(BGHS[SelfIndex].protect, TEXT("U")); wcscpy_s(BGHS[SelfIndex].protect, TEXT("U"));
} }
break; break;
case BGM_AUTOROW: case BGM_AUTOROW:
if((BOOL)wParam) if((BOOL)wParam)
{ {
BGHS[SelfIndex].AUTOROW = TRUE; BGHS[SelfIndex].AUTOROW = TRUE;
} }
else else
{ {
BGHS[SelfIndex].AUTOROW = FALSE; BGHS[SelfIndex].AUTOROW = FALSE;
} }
break; break;
case BGM_SETEDITABLE: case BGM_SETEDITABLE:
if((BOOL)wParam) if((BOOL)wParam)
{ {
BGHS[SelfIndex].EDITABLE = TRUE; BGHS[SelfIndex].EDITABLE = TRUE;
} }
else else
{ {
BGHS[SelfIndex].EDITABLE = FALSE; BGHS[SelfIndex].EDITABLE = FALSE;
} }
break; break;
case BGM_SETCELLDATA: case BGM_SETCELLDATA: