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

📄 twl.cpp

📁 UC Library Extensions UnderC comes with a pocket implementation of the standard C++ libraries, wh
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  if (m_client) n++;  if (n==0) return;  GetClientRect(m_hwnd,&rt);  hdwp = BeginDeferWindowPos(n);  if (m_status) {   DeferWindowPos(hdwp,m_status,NULL,0,0,       //???                     rt.right - rt.left, 20, SWP_NOZORDER);   bottom_extra = 20;  }   if (m_client)  DeferWindowPos(hdwp,m_client->handle(),NULL,0,0,                     rt.right - rt.left, rt.bottom-rt.top - bottom_extra,                      SWP_NOZORDER | SWP_NOMOVE);  EndDeferWindowPos(hdwp);}/// Windows controls - TControl ////////////TControl::TControl(TWin *parent, pchar classname, pchar text,int id, long style): TEventWindow(parent,classname,text,id,style){   m_colour = RGB(0,0,0); //RGB(255,255,255);  // shd depend on background!   m_font = NULL;   SetWindowLong(m_hwnd,GWL_USERDATA,(long)this);   m_parent = (TEventWindow *)parent;   //calc_size();}TControl::~TControl(){}TControl *TControl::user_data(Handle handle){ return (TControl *)GetWindowLong(handle,GWL_USERDATA);}void TControl::calc_size(){  int cx,cy;  m_parent->get_dc()->get_text_extent(get_text(),cx,cy,m_font);  resize(int(1.05*cx),int(1.05*cy));}bool TControl::is_type(char *tname){    return strcmp(type_name(),tname)==0;}void TControl::set_font(TFont *fnt){    m_font = fnt;    calc_size();    if (m_font)      send_msg(WM_SETFONT,(WPARAM)m_font->handle(),(LPARAM)TRUE);}void TControl::set_colour(float r, float g, float b){    m_colour = (long)RGBF(r,g,b);    update();}TLabel::TLabel(TWin *parent, pchar text, int id)//--------------------------------------: TControl(parent,"STATIC",text,id,0x0){ }TEdit::TEdit(TWin *parent, pchar text, int id, long style)//-----------------------------------------------: TControl(parent,"EDIT",text,id,style | WS_BORDER){  }//-----------------Dialog boxes--------------------------TDialog::~TDialog () { FreeProcInstance((DLGPROC)m_lpfnBox); }bool TDialog::was_successful(){   if (modeless()) return as_bool(handle());   else return as_bool(m_ret);}DLGFN DialogProc (HWND hdlg, UINT msg, UINT wParam,LONG lParam);void TDialog::go ()//-----------------{    HWND hdlg,hOwner;    hOwner = (m_owner) ? m_owner->handle() : NULL; //GetDesktopWindow();    m_lpfnBox = (void FAR *)MakeProcInstance((FARPROC)DialogProc,hInst);     if (modeless()) {      hdlg = CreateDialogParam(hInst,m_name,hOwner,(DLGPROC)m_lpfnBox,(long)this);      hModeless = hdlg;     } else {       m_ret = DialogBoxParam(hInst,m_name,hOwner,(DLGPROC)m_lpfnBox,(long)this);       m_hwnd = 0;  // thereafter, this object is not a valid window...    }     ShowWindow(hdlg,SW_SHOW);}TWin * TDialog::field(int id){  return new TWin(GetDlgItem(m_hwnd,id));}//....Modeless Dialog Box procedure.........................DLGFN DialogProc (HWND hdlg, UINT msg, UINT wParam,LONG lParam){  int ret;  TDialog *This = (TDialog *) GetWindowLong(hdlg,DWL_USER);  switch (msg)  {     case WM_INITDIALOG:        //..... 'This' pointer passed as param from CreateDialogParam()         SetWindowLong(hdlg,DWL_USER,lParam);         This = (TDialog *)lParam;         if (This->modeless()) hModeless = hdlg;         This->set(hdlg);         return This->init();     case WM_COMMAND:        switch(LOW_WORD(wParam)) {         case IDOK:             ret = This->finis();             if (! ret) return FALSE;  // no, we're not finished yet!         case IDCANCEL:             if (This->modeless()) SendMessage(hdlg,WM_CLOSE,0,0L);                                  else EndDialog(hdlg,wParam==IDOK);         break;         default:             This->command(wParam);         break;        }        return TRUE;     case WM_CLOSE:         DestroyWindow(hdlg);         hModeless = 0;         break;  }  return FALSE;  // we did not process the message...}WNDFN WndProc (HWND hwnd, UINT msg, UINT wParam,LONG lParam);//----------------Window Registration----------------------void RegisterEventWindow(HANDLE hIcon=0, HANDLE hCurs=0)//------------------------------------------------------{    WNDCLASS    wndclass;    wndclass.style         = CS_HREDRAW | CS_VREDRAW |                             CS_OWNDC | CS_DBLCLKS;    wndclass.lpfnWndProc   = WndProc;    wndclass.cbClsExtra    = 0;    wndclass.cbWndExtra    = 4;    wndclass.hInstance     = hInst;    wndclass.hIcon         = hIcon ? hIcon : LoadIcon (NULL, IDI_APPLICATION) ;    wndclass.hCursor       = hCurs ? hCurs : LoadCursor (NULL, IDC_ARROW) ;    wndclass.hbrBackground = NULL; //GetStockObject(LTGRAY_BRUSH);    wndclass.lpszMenuName  = NULL;   wndclass.lpszClassName = EW_CLASSNAME;   RegisterClass (&wndclass); }char *args[N_CMD_LINE];int n_args;int ParseCmdLine(LPSTR CmdLine, char **args);int get_argc(){ return n_args; }char **get_argv(){ return args; }int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,            LPSTR lpszCmdLine, int nCmdShow)//----------------------------------------------------------------{  #ifdef COMMCTRL InitCommonControls(); #endif hInst = hInstance; CmdShow = nCmdShow; n_args = ParseCmdLine(lpszCmdLine, args); if (! hPrevInstance) RegisterEventWindow(); return SMain(n_args,args);}//--------------Default Window Proc for EventWindow-----------------typedef void *PVOID;WNDFN WndProc (HWND hwnd, UINT msg, UINT wParam,LONG lParam)//----------------------------------------------------------------------------{//  static SWin w;  static BOOL dragging = FALSE;  static long MouseTime = 0;  static UINT size_flags;  LPMINMAXINFO pSizeInfo;  long ret;  TEventWindow *This = (TEventWindow *) GetWindowLong(hwnd,0);  switch (msg)  {     case WM_CREATE:      {         LPCREATESTRUCT lpCreat = (LPCREATESTRUCT) lParam;         PVOID *lpUser;         lpUser  = (PVOID *)lpCreat->lpCreateParams;      //..... 'This' pointer passed as first word of creation parms         SetWindowLong(hwnd,0,(long)lpUser[0]);         This = (TEventWindow *)lpUser[0];         This->get_dc()->set_twin(This);      }     return 0;    case WM_SIZE:      This->size(LOWORD(lParam),HIWORD(lParam));      return 0;    case WM_MOVE:      This->on_move();      return 0;    case WM_GETMINMAXINFO:        if (This && This->cant_resize()) {          pSizeInfo = (LPMINMAXINFO) lParam;          pSizeInfo->ptMaxTrackSize = This->fixed_size();          pSizeInfo->ptMinTrackSize = This->fixed_size();        }        return 0;  //    case WM_COMMAND:      if (This->m_dispatcher) {             This->m_dispatcher->dispatch(LOW_WORD(wParam),HIWORD(wParam),(Handle)lParam);            return 0;      }      if (This->command(LOW_WORD(wParam))) return 0;      else break;   case WM_USER_PLUS:      return This->handle_user(wParam,lParam);    case WM_KEYDOWN:        This->keydown(wParam);        return 0;    case WM_CHAR:         This->on_char(wParam,LOWORD(lParam));  // 1         return 0;    case WM_HSCROLL:       if (This->m_dispatcher) {             int id = GetWindowLong((HWND)lParam,GWL_ID);            This->m_dispatcher->dispatch(id,LOWORD(wParam),(Handle)lParam);       }        return 0;    case WM_VSCROLL:       This->vscroll(wParam,This->scroll_bar()->get_pos());       return 0;    case WM_PAINT:     {        PAINTSTRUCT ps;        TDC *dc = This->get_dc();        dc->set_hdc(BeginPaint(hwnd,&ps));        This->paint(*dc);        dc->set_hdc(NULL);        EndPaint(hwnd,&ps);     }     return 0;// Mouse messages....  case WM_LBUTTONDOWN:  case WM_LBUTTONUP:  case WM_RBUTTONDOWN:  case WM_LBUTTONDBLCLK:    {        Point pt(LOWORD(lParam),HIWORD(lParam));        //pt.to_logical(*This);     switch (msg) {        case WM_LBUTTONDOWN:            This->mouse_down(pt);         break;        case WM_LBUTTONUP:         This->mouse_up(pt);         break;        case WM_RBUTTONDOWN:            This->right_mouse_down(pt);            break;        case WM_LBUTTONDBLCLK:            This->mouse_double_click(pt);            break;      }    }    return 0;    case WM_MOUSEMOVE:  // needs different treatment??     {        Point pt(LOWORD(lParam),HIWORD(lParam));          This->mouse_move(pt);     }     return 0;  case WM_ERASEBKGND:    {      RECT rt;      GetClientRect(hwnd,&rt);      FillRect((HDC)wParam,(LPRECT)&rt, This->m_bkgnd_brush);    }    return 0;  #ifdef _WIN32  case WM_CTLCOLORSTATIC:    {     TControl *ctl = (TControl *)GetWindowLong((HWND)lParam,GWL_USERDATA);     SetBkColor((HDC)wParam, (COLORREF)This->m_bk_color);     SetTextColor((HDC)wParam, ctl->get_colour());    }    return (long)This->m_bkgnd_brush;  #endif  case WM_SETFOCUS:     This->focus(true);     return 0;  case WM_KILLFOCUS:     This->focus(false);     return 0;  case WM_SYSCOMMAND:     if (This->sys_command(LOW_WORD(wParam))) return 0; //?     else break;  case WM_TIMER:      This->timer();      return 0;  case WM_CLOSE:    if (! This->query_close()) return 0;    break;  // *NOTE* this was not here!!  case WM_DESTROY:
    //*fix 1.2.8 This had been commented out; prevents closing via usual window operation.     This->destroy();    if (This->m_hmenu) DeleteObject(This->m_hmenu);  // but why here?    return 0 ; } ret = DefWindowProc (hwnd , msg, wParam, lParam) ; return ret;}

char *_quote_strtok(char *str, char str_delim)
{
// a specialized version of strtok() which treats quoted strings specially 
// (used for handling command-line parms)
    static char *tok;
    if(str != NULL) tok = str;
          
    while (*tok && isspace(*tok)) tok++;
    if (*tok == '\0') return NULL;
    
    if (*tok == str_delim) {       
       tok++;            // skip "
       str = tok;
       while (*tok && *tok != str_delim) tok++;        
    } else {
       str = tok;
       while (*tok && ! isspace(*tok)) tok++;
    }
    if (*tok) *tok++ = '\0';  
    return str;
}
int ParseCmdLine(LPSTR CmdLine, char **args)//-----------------------------------------{  int i;  char *arg;  static char app_path[255];  GetModuleFileName(NULL,app_path,255);  lstrcpy(buff,CmdLine);  args[0] = app_path;   args[1] = _quote_strtok(buff,'\"');  if (! args[1]) return 1;  // at least one argument!  i = 2;  while (arg = _quote_strtok(NULL,'\"')) args[i++] = arg;  return i;}

⌨️ 快捷键说明

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