⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialog.c

📁 MinGUI 可视化程序代码
💻 C
📖 第 1 页 / 共 5 页
字号:
       if(ModuleResult) break;
     }
  }
    
  /*销毁对话框图标*/
  if(LogoBitmap) DestroyBitmap(LogoBitmap); 

  /*递减对话框的嵌套深度*/
  MessageDlgCount--;
  
  /*激活前一个对话框*/
  if(MessageDlgCount>0)
  { EnableWindow(LastDlg,true);
  }
  
  /*销毁对话框*/
  DestroyWindow(hMessageDlg);

  /*记录当前的对话框*/
  hMessageDlg=LastDlg;
  
  return ModuleResult;
}
//---------------------------------------------------------------------------
static void SysBtnRepaint(HWND hWnd,HDC dc,BOOL OnlyBorder)
{  TCaptionBarInfo *dlginfo=(TCaptionBarInfo *)WndClsBuf(hWnd);
   int x=dlginfo->SysBtnPos.x;
   int y=dlginfo->SysBtnPos.y;

   GroupOn(dc);
   
   if(!OnlyBorder)
   { SetBackColor(dc,CL_BTNFACE);
     ClearRect(dc,x,y,DLG_SYSBTN_WIDTH,DLG_SYSBTN_HEIGHT);
     if(dlginfo->CloseBtnEnabled)
     { SetColor(dc,CL_BLACK);
     }
     else
     { SetColor(dc,CL_WHITE);
       DrawLine(dc,x+6,y+DLG_SYSBTN_HEIGHT-5,x+DLG_SYSBTN_WIDTH-5,y+5);
       DrawLine(dc,x+6,y+DLG_SYSBTN_HEIGHT-4,x+DLG_SYSBTN_WIDTH-5,y+6);
       DrawVerLine(dc,x+DLG_SYSBTN_WIDTH-5,y+DLG_SYSBTN_HEIGHT-5,2);
       SetColor(dc,CL_DARKGRAY);
     }
     DrawLine(dc,x+5,y+4,x+DLG_SYSBTN_WIDTH-6,y+DLG_SYSBTN_HEIGHT-6);
     DrawLine(dc,x+5,y+DLG_SYSBTN_HEIGHT-6,x+DLG_SYSBTN_WIDTH-6,y+4);
     DrawLine(dc,x+5,y+5,x+DLG_SYSBTN_WIDTH-6,y+DLG_SYSBTN_HEIGHT-5);
     DrawLine(dc,x+5,y+DLG_SYSBTN_HEIGHT-5,x+DLG_SYSBTN_WIDTH-6,y+5);
   } 
   if(dlginfo->CloseBtnDown)  Draw3dInset(dc,x,y,DLG_SYSBTN_WIDTH,DLG_SYSBTN_HEIGHT);
   else  Draw3dOutset(dc,x,y,DLG_SYSBTN_WIDTH,DLG_SYSBTN_HEIGHT);
 
   GroupOff(dc,x,y,DLG_SYSBTN_WIDTH,DLG_SYSBTN_HEIGHT);

}
//---------------------------------------------------------------------------
static HRESULT CALLBACK CaptionBarProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{ switch(message)  
  { case WM_LBUTTONDOWN:
         { TCaptionBarInfo *dlginfo=(TCaptionBarInfo *)WndClsBuf(hWnd);
		   PWND pMain=WNDPTR(hWnd)->Parent; 
		   int mx=LOWORD(lParam)-pMain->WndRect.left;
		   int my=HIWORD(lParam)-pMain->WndRect.top; 
           if(dlginfo->CloseBtnEnabled)
           { if(mx>=dlginfo->SysBtnPos.x && mx<dlginfo->SysBtnPos.x+DLG_SYSBTN_WIDTH 
		     && my>=dlginfo->SysBtnPos.y && my<dlginfo->SysBtnPos.y+DLG_SYSBTN_HEIGHT)
             { HDC dc=GetDC((HWND)pMain);
               dlginfo->CloseBtnDown=true;
               SysBtnRepaint(hWnd,dc,true);
               ReleaseDC(dc);
			   break;
			 }
           }
		   dlginfo->xDragging=mx;
           dlginfo->yDragging=my;
          }
          break;

     case WM_LBUTTONUP:
          { TCaptionBarInfo *dlginfo=(TCaptionBarInfo *)WndClsBuf(hWnd);
		    PWND pMain=WNDPTR(hWnd)->Parent; 
            if(dlginfo->CloseBtnDown)
            { HDC dc=GetDC((HWND)pMain);
			  int mx=LOWORD(lParam)-pMain->WndRect.left;
              dlginfo->CloseBtnDown=false;
              SysBtnRepaint(hWnd,dc,true);
			  ReleaseDC(dc);
              if(mx>=dlginfo->SysBtnPos.x && mx<dlginfo->SysBtnPos.x+DLG_SYSBTN_WIDTH)
			  { int my=HIWORD(lParam)-pMain->WndRect.top; 
			    if(my>=dlginfo->SysBtnPos.y && my<dlginfo->SysBtnPos.y+DLG_SYSBTN_HEIGHT)
				{ PostMessage(WNDPTR(hWnd)->Parent,WM_CLOSE,0,0);
			      break;
				}
			  }
            }
		    dlginfo->xDragging=dlginfo->yDragging=0;
          }
          return 0;

     case WM_MOUSEMOVE:
		  { TCaptionBarInfo *dlginfo=(TCaptionBarInfo *)WndClsBuf(hWnd);
		    if(dlginfo->xDragging || dlginfo->yDragging)
			{ PWND pMain=WNDPTR(hWnd)->Parent;
			  int nx=LOWORD(lParam)-dlginfo->xDragging;
              int ny=HIWORD(lParam)-dlginfo->yDragging;
			  if(nx!=pMain->WndRect.left || ny!=pMain->WndRect.top)
			  {  SetWindowPos((HWND)pMain,nx-pMain->Parent->ClientRect.left,ny-pMain->Parent->ClientRect.top);
			  }

			}
		  }
		  return 0;

	 case WM_SETTEXT:
		  { PWND pMain=WNDPTR(hWnd)->Parent;
		    if(SaveWindowText(WNDPTR(hWnd)->Parent,(char *)lParam))
			{ if(!pMain->unmapcount)
			  { int  captionwidth,captionleft,clientwidth,clientheight;
			    HDC dc=GetDC((HDC)pMain);
				GroupOn(dc);
                
				clientwidth=crWidth(hWnd);
				clientheight=crHeight(hWnd);

                captionleft=(pMain->Logo)?pMain->Logo->Width+DLG_CaptionBarMargin*2:DLG_CaptionBarMargin;
                captionwidth=clientwidth - captionleft - DLG_SYSBTN_WIDTH - DLG_CaptionBarMargin*2;
                captionleft+=DLG_BORDER_SIZE;

                ((TWndCanvas *)dc)->Background = (pMain->Family==g_CurrentFocus->Family)?WNDPTR(hWnd)->Background:WNDPTR(hWnd)->Background>>1;
                ClearRect(dc, captionleft,DLG_BORDER_SIZE,captionwidth,clientheight);
            
                if(lParam && *(char *)lParam)
				{ SetFontStyle(dc,FS_PLAIN,true); 
				  ((TWndCanvas *)dc)->Foreground=WNDPTR(hWnd)->Foreground;
				  DrawText(dc,captionleft,DLG_BORDER_SIZE,captionwidth,clientheight,(char *)lParam,alLeft|alMiddle);
				}
                GroupOff(dc,captionleft,DLG_BORDER_SIZE,captionwidth,clientheight);
                ReleaseDC(dc);
			  }
			}
		  }
		  return 0;

     case WM_SETLOGO:
		  { PWND pMain=WNDPTR(hWnd)->Parent;
		    TBitmap *newLogo=(TBitmap *)lParam;
		    if(!pMain->unmapcount)
			{ int newlogowidth=(newLogo)?newLogo->Width:0;
			  int oldlogowidth=(pMain->Logo)?pMain->Logo->Width:0;
			  if(newlogowidth!=oldlogowidth)
			  { Invalidate(hWnd);
			  }
			  else if(newLogo)
			  { /*
                 * There may be such case that the Logo pointer is not change but the pointed is changed,
                 * so,if comes the WM_SETLOGO message, we'll repaint the logo,no matter whether the Logo pointer is changed.
                 */				  
			    HDC dc=GetDC((HDC)pMain);
				DrawBitmap(dc,DLG_BORDER_SIZE+DLG_CaptionBarMargin,DLG_BORDER_SIZE+(crHeight(hWnd) - newLogo->Height)/2,newLogo);
				ReleaseDC(dc);
			  }
 			}
			pMain->Logo=newLogo;
		  }
		  return 0;

     case WM_PAINT:
          {char *FormCaption;
		   int clientwidth=crWidth(hWnd),clientheight=crHeight(hWnd);
           int  captionleft=DLG_BORDER_SIZE+DLG_CaptionBarMargin;
	       PWND pMain=WNDPTR(hWnd)->Parent;
		   HDC dc=GetDC((HDC)pMain);
		   GroupOn(dc);

           ((TWndCanvas *)dc)->Background = (pMain->Family==g_CurrentFocus->Family)?WNDPTR(hWnd)->Background:WNDPTR(hWnd)->Background>>1;
           ClearRect(dc, DLG_BORDER_SIZE,DLG_BORDER_SIZE,clientwidth,clientheight);

           /*draw bitmap*/
           if(pMain->Logo)
           { DrawBitmap(dc,captionleft,DLG_BORDER_SIZE+((clientheight-pMain->Logo->Height)>>1),pMain->Logo);
             captionleft=captionleft+pMain->Logo->Width+DLG_CaptionBarMargin;
           }

           FormCaption=GetWindowText((HWND)pMain);
           if(FormCaption && *FormCaption)
           {  int captionwidth=clientwidth - captionleft - DLG_SYSBTN_WIDTH - DLG_CaptionBarMargin*2;
			  SetFontStyle(dc,FS_PLAIN,true); 
			  ((TWndCanvas *)dc)->Foreground=WNDPTR(hWnd)->Foreground;
		      DrawText(dc,captionleft,DLG_BORDER_SIZE,captionwidth,clientheight,FormCaption,alLeft|alMiddle);
           }
           SysBtnRepaint(hWnd,dc,false);
           
		   GroupOff(dc,DLG_BORDER_SIZE,DLG_BORDER_SIZE,clientwidth,clientheight);
		   ReleaseDC(dc);
		 }
		 WndSubAttr(hWnd,WS_NCPAINT|WS_NEEDPAINT);
		 return 0;

	case WM_CREATE:
		 { TCaptionBarInfo *dlginfo=(TCaptionBarInfo *)WndClsBuf(hWnd);
           dlginfo->SysBtnPos.x=DLG_BORDER_SIZE+crWidth(hWnd)-DLG_SYSBTN_WIDTH-2;
		   dlginfo->SysBtnPos.y=DLG_BORDER_SIZE+2;
           dlginfo->CloseBtnDown=false;
           dlginfo->CloseBtnEnabled=WndGetAttr(WNDPTR(hWnd)->Parent,WS_SYSMENU);
		   dlginfo->xDragging=dlginfo->yDragging=0;
         }
		 return 0;
  }
  return DefWindowProc(hWnd,message,wParam,lParam);
}
//---------------------------------------------------------------------------
HWND GetCaptionBar(HWND hWnd)
{ PWND pBar=WNDPTR(hWnd)->Children;
  while(pBar)
  { if(pBar->WinClass->lpszClassName==CAPTIONBAR_CLASS_NAME)break;
	else pBar=pBar->Next;
  }
  return (HWND)pBar;
}
//---------------------------------------------------------------------------
void CM_RegisterDialog(void)
{  TWNDCLASS wc;
   memset(&wc,0,sizeof(wc));

   wc.clForeground=CL_CAPTIONTEXT;
   wc.clBackground=CL_CAPTIONBAR;
   wc.cbWndExtra=sizeof(TCaptionBarInfo);
   wc.lpfnWndProc=CaptionBarProc;
   wc.lpszClassName=CAPTIONBAR_CLASS_NAME;
   RegisterClass(&wc);

   wc.clForeground=CL_BTNTEXT;
   wc.clBackground=CL_BTNFACE;
   wc.cbWndExtra=sizeof(TDialogInfo);
   wc.lpfnWndProc=DefWindowProc;
   wc.lpszClassName="dialog";
   RegisterClass(&wc);
}
//---------------------------------------------------------------------------


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -