📄 twl.cpp
字号:
void TWin::scroll(int dx, int dy){ ScrollWindow(m_hwnd,dx,dy,NULL,NULL); }int TWin::get_int(int id)//-----------------------{ BOOL success; return (int)GetDlgItemInt(m_hwnd,id,&success,TRUE);}TWin *TWin::get_twin(int id)//--------------------{ HWND hwnd = GetDlgItem(m_hwnd,id); if (hwnd) { // Extract the 'this' pointer, if it exists TWin *pwin = (TWin *)GetWindowLong(hwnd,0); // if not, then just wrap up the handle if (!pwin) pwin = new TWin(hwnd); return pwin; } else return NULL;}TWin *TWin::get_active_window(){ return new TWin(GetActiveWindow());}void TWin::set_focus(){ SetFocus((HWND)m_hwnd);}intTWin::get_id()//------------{ return GetWindowLong(m_hwnd,GWL_ID); }void TWin::close(){ DestroyWindow(m_hwnd);}void TWin::resize(int x0, int y0, int w, int h)//--------------------------------------------{ MoveWindow(m_hwnd,x0,y0,w,h,TRUE); //*SJD* This is a hack to ensure that WCON child console // windows do indeed appear on the top on Win95 systems. on_top();}void TWin::on_top() // *add 0.9.4{ SetWindowPos(handle(),HWND_TOP,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);}void TWin::resize(int w, int h)//------------------------------{ SetWindowPos(handle(),NULL,0,0,w,h,SWP_NOMOVE); }void TWin::move(int x0, int y0)//------------------------------{ SetWindowPos(handle(),NULL,x0,y0,0,0,SWP_NOSIZE); }void TWin::show(int how)//--------------------------------{ ShowWindow(m_hwnd,how); }void TWin::set_style(dword s)//---------------------------{ SetWindowLong(m_hwnd,GWL_STYLE,s); }int TWin::send_msg(int msg, int wparam, int lparam) const//---------------------------------------------------{ return SendMessage(m_hwnd, msg, wparam, lparam); }int TWin::post_msg(int msg, int wparam, int lparam) const{ return PostMessage(m_hwnd, msg, wparam, lparam); } TWin *TWin::create_child(pchar winclss, pchar text, int id, dword styleEx)//------------------------------------------------------------------------{ return new TWin(this,winclss,text,id,styleEx);}int TWin::message(char *msg, int type)//-------------------------------------{ int flags; char *title; if (type == MSG_ERROR) { flags = MB_ICONERROR | MB_OK; title = "Error"; } else if (type == MSG_WARNING) { flags = MB_ICONEXCLAMATION | MB_OKCANCEL; title = "Warning"; } else { flags = MB_OK; title = "Message"; } return MessageBox(m_hwnd, msg, title,flags);}TScrollBar::TScrollBar(Handle hwnd, int type): TWin(hwnd),m_type(type){}void TScrollBar::set_range(int rmin, int rmax, bool repaint/*=false*/){ SetScrollRange(m_hwnd,m_type,rmin,rmax,repaint);}void TScrollBar::set_pos(int rpos, bool repaint/*=false*/){ SetScrollPos(m_hwnd,m_type,rpos,repaint);}int TScrollBar::get_pos(){ return GetScrollPos(m_hwnd,m_type);}//----TEventWindow class member definitions---------------------TEventWindow::TEventWindow(pchar caption, TWin *parent, dword style)//-----------------------------------------------------------------{ set_defaults(); if (style) m_style |= style; create_window(caption, parent); get_dc()->set_text_align(TA_TOP | TA_LEFT); enable_resize(true);}TEventWindow::~TEventWindow(){ if (m_timer) kill_timer(); if (m_dc) delete m_dc; DestroyWindow((HWND)m_hwnd);}void TEventWindow::pre_create() {}void TEventWindow::vert_scroll(){ m_sb_vert = (TScrollBar *)this; // just to flag!}void TEventWindow::create_window(pchar caption, TWin *parent)//-------------------------------------------------------------------{ HWND hParent; void *CreatParms[2]; pre_create(); m_dc = new TDC; CreatParms[0] = (void *)this; if (parent) hParent = parent->handle(); else hParent = NULL; m_hwnd = CreateWindow (EW_CLASSNAME, caption, m_style, CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT, hParent,NULL, hInst, CreatParms); if(m_style & WS_VSCROLL) m_sb_vert = new TScrollBar(m_hwnd,SB_VERT); set_window();}void TEventWindow::set_defaults()//-------------------------------{ m_style = WS_OVERLAPPEDWINDOW | CS_DBLCLKS; m_bkgnd_brush = GetStockObject (WHITE_BRUSH /*LTGRAY_BRUSH*/); m_bk_color = RGB(192,192,192); m_hmenu = NULL; m_timer = 0; m_dispatcher = NULL; m_dc = NULL; m_bail_out = false; m_sb_vert = NULL;}void TEventWindow::add_handler(AbstractMessageHandler *m_hand){ if (!m_dispatcher) m_dispatcher = m_hand; else m_dispatcher->add_handler(m_hand);}void TEventWindow::update_data(){ get_handler()->write();}void TEventWindow::update_controls(){ get_handler()->read(); }bool TEventWindow::cant_resize(){ return !m_do_resize;}int TEventWindow::metrics(int ntype)//----------------------------------// Encapsulates what we need from GetSystemMetrics() and GetTextMetrics(){ if (ntype < TM_CAPTION_HEIGHT) { // text metrics TEXTMETRIC tm; GetTextMetrics(get_dc()->get_hdc(),&tm); if (ntype == TM_CHAR_HEIGHT) return tm.tmHeight; else if (ntype == TM_CHAR_WIDTH) return tm.tmMaxCharWidth; } else { switch(ntype) { case TM_CAPTION_HEIGHT: return GetSystemMetrics(SM_CYMINIMIZED); case TM_MENU_HEIGHT: return GetSystemMetrics(SM_CYMENU); case TM_CLIENT_EXTRA: return metrics(TM_CAPTION_HEIGHT) + (m_hmenu != NULL) ? metrics(TM_MENU_HEIGHT) : 0; case TM_SCREEN_WIDTH: return GetSystemMetrics(SM_CXMAXIMIZED); case TM_SCREEN_HEIGHT: return GetSystemMetrics(SM_CYMAXIMIZED); default: return 0; } } return 0;}void TEventWindow::client_resize(int cwidth, int cheight){// *SJD* This allows for menus etc - really is a frame window method?? resize(cwidth,cheight + metrics(TM_CLIENT_EXTRA));}void TEventWindow::enable_resize(bool do_resize, int w, int h){ m_do_resize = do_resize; m_fixed_size.x = w; m_fixed_size.y = h;}POINT TEventWindow::fixed_size(){ return m_fixed_size;}void TEventWindow::cursor(CursorType curs){ HCURSOR new_cursor; if (curs == RESTORE) new_cursor = m_old_cursor; else switch(curs) { case HOURGLASS: new_cursor = LoadCursor(NULL,IDC_WAIT); break; } SetCursor(new_cursor);}void TEventWindow::set_window()//-----------------------------{ set(m_hwnd);// set_win(*this); //...set up DC part.....??}void TEventWindow::set_background(float r, float g, float b)//-----------------------------------------{ COLORREF rgb = RGBF(r,g,b); m_bkgnd_brush = CreateSolidBrush(rgb); get_dc()->get(this); SetBkColor(get_dc()->get_hdc(),rgb); get_dc()->select(m_bkgnd_brush); m_bk_color = rgb; get_dc()->release(this); invalidate();}void TEventWindow::set_menu(char *res)//------------------------------------{ if (m_hmenu) DeleteObject(m_hmenu); set_menu(LoadMenu(hInst,res));}void TEventWindow::set_menu(Handle menu)//------------------------------------{ m_hmenu = menu; SetMenu(m_hwnd,menu);}void TEventWindow::check_menu(int id, bool check){ CheckMenuItem(m_hmenu,id, MF_BYCOMMAND | (check ? MF_CHECKED : MF_UNCHECKED));}void TEventWindow::show(int cmd_show)//-----------------------------------{ // default: use the 'nCmdShow' we were _originally_ passed if (! cmd_show) cmd_show = CmdShow; ShowWindow(m_hwnd,cmd_show);}void TEventWindow::create_timer(int msec)//---------------------------------------{ if(m_timer) kill_timer(); m_timer = SetTimer(m_hwnd,1,msec,NULL); }void TEventWindow::kill_timer()//-----------------------------{ KillTimer(m_hwnd, m_timer); }
// *fix 1.2.2 (Eric) We were spending an excessive amount of time doing idle processing
#ifdef BUILD_WITH_GTK
void special_idle(); // in UCW_GTK
#else
void special_idle() { WaitMessage(); }
#endif// Message Loop!// *NB* this loop shd cover ALL cases, controlled by global// variables like mdi_sysaccell, accell, hModelessDlg, etc.// 31/08/00 - there's a bail out flag - not perhaps the// most elegant method, but it'll do.int TEventWindow::run()//---------------------{ MSG msg; while (TRUE) {
if (PeekMessage (&msg, NULL, 0, 0,PM_REMOVE)) {
if (msg.message == WM_QUIT) break; if (m_bail_out) { m_bail_out = false; return -1; } if (! hAccel || !TranslateAccelerator(m_hwnd,hAccel,&msg)) { if (! hModeless || !IsDialogMessage(hModeless,&msg)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } }
}
else special_idle();
} return msg.wParam ;}
static unsigned long mMainThread;
void set_main_thread(unsigned long id)
{
mMainThread = id; // GetCurrentThreadId();
}void TEventWindow::quit_loop(){ m_bail_out = true; //post_msg(WM_CHAR,' ',1);
ULONG id = GetWindowThreadProcessId((HWND)handle(),NULL);
BOOL res = PostThreadMessage(id,WM_CHAR,' ',1);
}// Place holder functions - no functionality offered at this level!void TEventWindow::size(int,int) {}void TEventWindow::on_move() {}bool TEventWindow::command(int) { return true; }bool TEventWindow::sys_command(int) { return false; }void TEventWindow::paint(TDC&) {}void TEventWindow::mouse_down(Point&) {}void TEventWindow::mouse_up(Point&) { }void TEventWindow::right_mouse_down(Point&) {}void TEventWindow::mouse_move(Point&) { }void TEventWindow::mouse_double_click(Point& pt) { }void TEventWindow::focus(bool) {}void TEventWindow::keydown(int) { }void TEventWindow::on_char(int,int) { }void TEventWindow::destroy() { }void TEventWindow::timer() { }void TEventWindow::vscroll(int code, int posn) { }int TEventWindow::handle_user(long lparam, long wparam) { return 0; }////// Members of TFrameWindowTFrameWindow::TFrameWindow(pchar caption, TWin *cli, int style, TWin *parent): TEventWindow(caption,parent,style){ // int SBParts[2]; set_client(cli); #ifdef COMMCTRL /* m_status = CreateStatusWindow(WS_CHILD | WS_BORDER | WS_VISIBLE, "", m_hwnd, 1); if(!m_status) set_text("no status"); SBParts[0] = width()/2; SBParts[1] = -1; SendMessage(m_status,SB_SETPARTS,2,(LPARAM)SBParts); */ m_status = NULL; // for now!! #else m_status = NULL; #endif}TFrameWindow::~TFrameWindow(){ delete m_client;}void TFrameWindow::set_status_text(int id, pchar txt){#ifdef COMMCTRL SendMessage(m_status,SB_SETTEXT,id,(LPARAM)txt);#endif}void TFrameWindow::destroy()//....overrides the default w/ application-closing behaviour!!{ PostQuitMessage(0);}void TFrameWindow::set_client(TWin *cli){ m_client = cli; if (m_client) { m_client->show(); } }void TFrameWindow::size(){ RECT rt; HDWP hdwp; int n = 0, bottom_extra = 0; if (m_status) n++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -