?? guilib.cpp
字號:
CDC *pDC = (AfxGetApp()->m_pMainWnd)->GetDC();
pDC->Rectangle(self->prec->x, self->prec->y, self->prec->x+self->prec->w, self->prec->y+self->prec->l);
pDC->TextOut(self->prec->x, self->prec->y-self->font_y, self->caption );
textOut(self);
(AfxGetApp()->m_pMainWnd)->ReleaseDC(pDC);
}
void append(char c, CText* self){
if(self->endPos>=TEXT_BUFF_SIZE){
//wait to add erro message
}else{
int i=0;
for(i=self->endPos; i>=self->curPos; i--){
self->text[i+1] = self->text[i];
}
self->text[self->curPos] = c;
self->curPos++;
self->endPos++;
}
}
void delet(CText* self){
if(self->endPos>0){
int i=0;
for( i=self->curPos; i<=self->endPos; i++){
self->text[i-1] = self->text[i];
}
self->curPos--;
self->endPos--;
}
}
void format(CText* self){
int ncperLine = (self->prec->w-DSP_GAP*2)/self->font_x;
char* ptext = self->text;
int i=0;
int j=0;
int k=0;
int nCount = 0;
char* pch = NULL;
int nLineBgn = self->dspLnBgn;
int nLineEnd = self->dspLnBgn+(self->prec->l-DSP_GAP*2)/self->font_y;
// CNode* pnode0 = NULL;
// CNode* pnode1 = NULL;
CVector* pvec = self->pformatVec;
clear(self->pformatVec);
push_back(ptext, self->pformatVec);
for(i=0; i<=self->endPos-1; i++,ptext++){
nCount++;
if(nCount==ncperLine || *ptext==ENTER){
push_back(ptext+1, self->pformatVec);
nCount = 0;
}
}
push_back(self->text+self->endPos, self->pformatVec);
if(nLineEnd>pvec->size-1){
nLineEnd = pvec->size-1;
}
for(j=0; j<self->endPos; j++){
if(self->text+j==pvec->getByIndex(nLineBgn, pvec)){
self->dspChBgn = j;
self->dspChEnd = j+i;
break;
}
}
i = self->dspChBgn;
//for(j=0; j<pvec->size-1; j++){
for(j=nLineBgn; j<nLineEnd; j++){
//pnode0 = pvec->getByIndex(j, pvec);
//pnode1 = pvec->getByIndex(j+1, pvec);
k = 0;
for(pch=(char*)pvec->getByIndex(j, pvec); pch<pvec->getByIndex(j+1, pvec); pch++,i++,k++){
self->format_x[i] = self->prec->x+DSP_GAP + k*self->font_x;
self->format_y[i] = self->prec->y+DSP_GAP + (j-nLineBgn)*self->font_y;
}
}
}
void textOut(CText* self){
format(self);
CDC *pDC = (AfxGetApp()->m_pMainWnd)->GetDC();
int i=0;
for(i=self->dspChBgn; i<self->dspChEnd; i++){
pDC->TextOut(self->format_x[i], self->format_y[i], self->text[i]);
}
(AfxGetApp()->m_pMainWnd)->ReleaseDC(pDC);
}
void paint(void* pobj){//, int wintype){
int i;
int wintype = getPtrType(pobj);
void* pdata = NULL;
CVector* pvec = NULL;
CWin* pwin = (CWin*)pobj;
CButtn* pbtn = (CButtn*)pobj;
CText* ptxt = (CText*)pobj;
switch(wintype){
case CWIN:
drawWin(pwin);
pvec = pwin->pchild_vec;
for(i=0; i<pvec->size; i++){
pdata = pvec->getByIndex(i, pvec);
paint(pdata);//, wintype);
}
break;
case CBUTTN:
drawButtn(pbtn);
break;
case CTEXT:
drawText(ptxt);
break;
}
}
void show(CWin* pwin){
// CData* pdata = newCData(pwin, CWIN);
void* pdata = NULL;
paint(pwin);//, CWIN);
int index = gl_activeWinVec->getIndex(pwin, gl_activeWinVec);//renew gl_activeWinVec
if(index==-1){//not found, add directly
gl_activeWinVec->push_back(pwin, gl_activeWinVec);
}else if(index<gl_activeWinVec->size){
// freeOne(pdata);//free temp variable
pdata = gl_activeWinVec->getByIndex(index, gl_activeWinVec);
gl_activeWinVec->eraseByIndex(index, gl_activeWinVec);
gl_activeWinVec->push_back(pdata, gl_activeWinVec);
}
changeFocus();
}
void OnShow(CMssg* pmssg){
void* pdata = pmssg->pdata;
int nptrTp = getPtrType(pdata);
if(nptrTp == CWIN){
CWin* pwin = (CWin*)pdata;
show(pwin);
}
}
void OnClose(CMssg* pmssg){
void* pdata = pmssg->pdata;
int nptrTp = getPtrType(pdata);
if(nptrTp == CWIN){
CWin* pwin = (CWin*)pdata;
close(pwin);
}
}
void close(CWin* pwin){
CNode* pnode = NULL;
// void* pdata = NULL;//newCData(pwin, CWIN);
void* pdata = NULL;
gl_activeWinVec->eraseByKey(pwin, gl_activeWinVec);
// eraseFocus();//for test
paint(gl_desktop);//, CWIN);
pnode = gl_activeWinVec->tail;
if(pnode && pnode->pdata && pnode->pdata!=gl_desktop){
pdata = pnode->pdata;
paint(pdata);//, pdata->wintype);
}
changeFocus();
// freeOne(pdata);
}
void OnKeyDown(CMssg* pmssg){
CText* text = NULL;
if(getPtrType(pmssg->pdata)==CTEXT){
text = (CText*)pmssg->pdata;
append(pmssg->lparam, text);
if(text->parentWin){
show(text->parentWin);
setFocus(pmssg->pdata);
}
}
}
void OnDbKeyDown(CMssg* pmssg){
CText* text = NULL;
if(getPtrType(pmssg->pdata)==CTEXT){
text = (CText*)pmssg->pdata;
delet(text);
append(pmssg->lparam, text);
if(text->parentWin){
show(text->parentWin);
}
}
}
void sendMessage(CMssg* pmssg){
if(pmssg){
push_back(pmssg, gl_mssgVec);
}
}
CMssg* waitMessage(){
CMssg* ptemp = NULL;
for(;;){
if(gl_mssgVec->size>0){
ptemp = (CMssg*)gl_mssgVec->head->pdata;
eraseByKey(gl_mssgVec->head->pdata, gl_mssgVec);
Sleep(100);
return ptemp;
}
}
return NULL;
}
int dispatchMessage(CMssg* pmssg){
CWin* pwin = NULL;
CButtn* pbtn = NULL;
CText* ptxt = NULL;
int winType = TYPE_DEF;
if(pmssg->type==WM_DESTROY1){
return 0;
}
if(pmssg->pdata){
//gl_focus = pmssg->pdata;
winType = getPtrType(pmssg->pdata);
switch(winType){
case CWIN:
pwin = (CWin*)pmssg->pdata;
if(pwin->winproc[pmssg->type] && pmssg->type!=WM_CHANGEFOCUS1 && gl_focus!=pwin->pExtra){
setFocus(pwin);
}
if(pwin->winproc[pmssg->type] ){
pwin->winproc[pmssg->type](pmssg);
}
break;
case CBUTTN:
pbtn = (CButtn*)pmssg->pdata;
if(pbtn->winproc[pmssg->type] && pmssg->type!=WM_CHANGEFOCUS1 && gl_focus!=pbtn->pExtra){
setFocus(pbtn);
}
if(pbtn->winproc[pmssg->type]){
pbtn->winproc[pmssg->type](pmssg);
}
break;
case CTEXT:
ptxt = (CText*)pmssg->pdata;
if(ptxt->winproc[pmssg->type] && pmssg->type!=WM_CHANGEFOCUS1 && gl_focus!=ptxt->pExtra){
setFocus(ptxt);
}
if(ptxt->winproc[pmssg->type]){
ptxt->winproc[pmssg->type](pmssg);
}
int tp = getPtrType(gl_focus->pdata);//for test
break;
}//switch
}
// freeOne(pmssg);
return 1;
}
int enter_main_times = 0;//for test
char buff[20]; //for test
//////////////////////////////////////////////////////////////test////////////////////////////////////////////////////////
void main(){
// int a = 10;
// int i;
// char* caption=NULL;
// CVector* pv = NULL;
// CData* pda = NULL;
// CButtn* pbtn = NULL;
CDC *pDC = (AfxGetApp()->m_pMainWnd)->GetDC();
enter_main_times++;
char* str = itoa(enter_main_times, buff, 10);
pDC->TextOut(500, 200, str);
CRect1* wrect1 = newCRect(60, 60, 140, 200);
CRect1* brect1 = newCRect(80, 80, 40, 20);
CRect1* brect2 = newCRect(80, 120, 40, 20);
CRect1* brect3 = newCRect(80, 160, 40, 20);
CRect1* trect1 = newCRect(80, 160, 100, 80);
CWin* win1 = newCWin(wrect1,"win1");
CButtn* butn1 = newCButtn(win1, brect1, "butn1");
//CButtn* butn2 = newCButtn(win1, brect2, "butn2");
//CButtn* butn3 = newCButtn(win1, brect3, "butn3");
CText* text2 = newCText(win1, trect1, "text2", 8, 16);
CWin* win2 = newCWin(wrect1, "win2");
CButtn* butn4 = newCButtn(win2, brect2, "butn4");
CText* text1 = newCText(win2, trect1, "text1", 8, 16);
CMssg* pmssg0 = NULL;
iniGui(win2);
append('1',text1);
append('2',text1);
append('3',text1);
append('4',text1);
append('5',text1);
append('<',text1);
append('6',text1);
append('7',text1);
append('8',text1);
/* append('9',text1);
append('1',text1);
append('1',text1);
// append('0',text1);
append('2',text1);
append('2',text1);
append('2',text1);
append('3',text1);
append('4',text1);
append('5',text1);
append('6',text1);
append('7',text1);
append('8',text1);
append('9',text1);
append('1',text1);
append('1',text1);
// append('0',text1);
append('2',text1);
append('3',text1);
append('2',text1);
append('3',text1);
append('4',text1);
append('5',text1);
append('6',text1);
append('7',text1);
append('8',text1);
append('9',text1);
append('1',text1);
append('1',text1);
// append('0',text1);
append('2',text1);
append('4',text1);
append('2',text1);
append('3',text1);
append('4',text1);
append('5',text1);
append('6',text1);
append('7',text1);
append('8',text1);
append('9',text1);
append('1',text1);
append('1',text1);
append('<',text1);
append('2',text1);
append('5',text1);
append('2',text1);
append('3',text1);
append('4',text1);
append('5',text1);
append('6',text1);
append('7',text1);
append('8',text1);
append('9',text1);
append('1',text1);
append('1',text1);
append('<',text1);
append('2',text1);
append('6',text1);
append('2',text1);
append('3',text1);
append('4',text1);
append('5',text1);
append('6',text1);
append('7',text1);
append('8',text1);
append('9',text1);
append('1',text1);
append('1',text1);
// append('0',text1);
append('2',text1);
append('7',text1);
append('2',text1);
append('3',text1);
append('4',text1);
append('5',text1);
append('6',text1);
append('7',text1);
append('8',text1);
append('9',text1);
append('1',text1);
append('1',text1);
append('<',text1);
append('2',text1);
append('<',text1);*/
// text1->curPos--;
// append('2',text1);
// delet(text1);
// butn1->winproc[WM_CLICK1] = butn1_OnClick;
// butn4->winproc[WM_CLICK1] = butn4_OnClick;
//addComponent(win1, butn1, CBUTTN);
//addComponent(win1, butn2, CBUTTN);
//addComponent(win1, butn3, CBUTTN);
text1->dspLnBgn = 0;
// pv = win1->pchild_vec;
// CDC *pDC = (AfxGetApp()->m_pMainWnd)->GetDC();
void* pdata = gl_activeWinVec->tail->pdata;//newCData(win1, CWIN);
CMssg* pmssg = newCMssg(text2, WM_KEYDOWN1, 's', 0);
//paint(pmssg);
// OnChangeFocus(pmssg);
// OnChangeFocus(pmssg);
// OnDbKeyDown(pmssg);
CMssg* pmssg1 = newCMssg(win1, WM_SHOW1, 0, 0);
CMssg* pmssg2 = newCMssg(win1, WM_CHANGEFOCUS1, 0, 0);
CMssg* pmssg3 = newCMssg(butn1, WM_CHANGEFOCUS1, '8', 0);
CMssg* pmssg4 = newCMssg(text2, WM_CHANGEFOCUS1, 'w', 0);
CMssg* pmssg6 = newCMssg(win1, WM_CLOSE1, 'w', 0);
CMssg* pmssg7 = newCMssg(win2, WM_CLOSE1, 'w', 0);
CMssg* pmssg8 = newCMssg(win2, WM_SHOW1, 'w', 0);
CMssg* pmssg9 = newCMssg(text1, WM_KEYDOWN1, '5', 0);
CMssg* pmssg10 = newCMssg(text1, WM_TRIKEYDOWN1, 'v', 0);
CMssg* pmssg11 = newCMssg(butn4, WM_CLICK1, 'v', 0);
CMssg* pmssg5 = newCMssg(text2, WM_DESTROY1, '9', 0);
sendMessage(pmssg1);
// OnChangeFocus(pmssg2);
sendMessage(pmssg1);
sendMessage(pmssg2);
sendMessage(pmssg3);
// OnKeyDown(pmssg3);
// sendMessage(pmssg3);
sendMessage(pmssg4);
sendMessage(pmssg6);
sendMessage(pmssg7);
sendMessage(pmssg8);
sendMessage(pmssg9);
sendMessage(pmssg10);
sendMessage(pmssg11);
// sendMessage(pmssg5);
sendMessage(pmssg5);
// sendKeyMssg(nChar);
// CMssg* pmssg5 = newCMssg(text1, WM_KEYDOWN1, 'w', 0);
// OnKeyDown(pmssg1);
// OnChangeFocus(pmssg);
/* OnChangeFocus(pmssg);
OnChangeFocus(pmssg);
OnChangeFocus(pmssg);
win1->winproc[WM_CHANGEFOCUS1](pmssg);*/
for(int j=0;j<1000;j++){
pmssg0 = waitMessage();
if(!dispatchMessage(pmssg0)){
break;
}
// freeOne(pmssg0);
}
int i = getPtrType(gl_focus->pdata);//for test
//eraseFocus();//for test
freeAll();
// enter_main_times--;
// str = itoa(enter_main_times, buff, 10);
// pDC->TextOut(500, 220, str);
(AfxGetApp()->m_pMainWnd)->ReleaseDC(pDC);
}
//void sendKeyMssg(UINT nChar){
// CMssg* pmssg = newCMssg(gl_focus->pdata, WM_KEYDOWN1, nChar, 0);
// sendMessage(pmssg);
//}
void OnButtnClick(CMssg* pmssg){
CButtn* butn = NULL;
if(getPtrType(pmssg->pdata)==CBUTTN){
butn = (CButtn*)pmssg->pdata;
close(butn->parentWin);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -