VC ++ programming skills three

zhaozj2021-02-17  52

VC programming skills three

(幄 July 12, 2001 11:49)

1. Let the toolbar are listed in parallel to assume a few toolbars in the Windows program window, and now we want these multiple toolbars to display, what is it implemented? Here, we can use the following functions to implement this function, which is made from the CJ60Lib library. The function implemented in the following program is to let the Leftof toolbar appear on the left side of the BAR toolbar, but also to display together, the following is the main code for implementing its function:

void CCJMDIFrameWnd :: DockControlBarLeftOf (CControlBar * Bar, CControlBar * LeftOf) {CRect rect; DWORD dw; UINT n; // use MFC to adjust the size of all toolbars // GetWindowRec ensure accurate RecalcLayout (TRUE); LeftOf-> GetWindowRect ( & rect); rect.OffsetRect (1,0); dw = LeftOf-> GetBarStyle (); n = 0; n = (dw & CBRS_ALIGN_TOP) AFX_IDW_DOCKBAR_TOP: n; n = (dw & CBRS_ALIGN_BOTTOM && n == 0) AFX_IDW_DOCKBAR_BOTTOM:? n; n? = (DW & CBRS_ALIGN_LEFT && N == 0)? AFX_IDW_DOCKBAR_LEFT: N; N = (DW & CBRS_ALIGN_RIGHT && n == 0)? AFX_IDW_DOCKBAR_RIGHT: N; DockControlbar (bar, n, & respons);}

2. Creating a Wizard dialog When using a specific software, we often use the wizard mode in the program to create new files, the most typical example is to create a web page file in the FrontPage2000 or Word2000. Or Word documentation. So after seeing other programs can provide the humanized wizard dialog, I don't know if you have any impulse? If there is, use the following code to create a wizard dialog:

Void CMY56_S1DLG :: Onwiz () {csheet sheet; sheet.SetwizardMode (); int rt = sheet.domodal (); // Return ID_WIZFINISH or IDCANCEL} // Reserved Bool CPropertyPage :: OnsetAtArtVE () to control the displayed button Bool CPage1 :: OnSetActive () {((CPropertySheet *) GetParent ()) -> SetWizardButtons (PSWIZB_BACK | PSWIZB_NEXT); return CPropertyPage :: OnSetActive ();} BOOL CPage2 :: OnSetActive () {((CPropertySheet *) GetParent () ) -> setWizardButtons (pswizb_back | pswizb_finish); return cpropertypage :: onsetactive ();}

3. Implementing the transceiver data between the computer knows that when the computer communicates between the computer, it is generally connected to the host of the specified IP address, and communicates with each other, in which one party is required. Play the server's role waiting for the connection request of the other party (client), so the server side needs to create a listener interface and wait on this set of connections. A new socket is generated after the connection is established. And the client only needs to simply call the connection function after creating a socket, you can create a connection. For communication, whether orientation is, whether the transmission or sequence of transmitting and reception is guaranteed. The following code is to use the CSocket provided by VC to implement the data transceiver function: / * The server side waits for the connection on port 6802, and closes the listening package after the connection is established. The client direction server port 6802 initiates a connection request * / BOOL CMY63_S1_SERVERDLG :: OnInitDialog () {Cdialog :: OnNIndialog (); csocket sucklisten; // Create a local set of interface SockListenTen.create (6802, Sock_Stream, "127.0.0.1"); // Binding parameters SockListen.bind (6802, "127.0.0.1" ); socklisten.listen (5); // Waiting for the connection request, m_socksend is a member variable, used to communicate socklisten.accept (m_socksend); // Close the listener interface SockListenTen.Close (); // Start the timer, time delivery Data setTimer (1,3000, null);} void cmy63_s1_serverdlg :: ONTIMER (uint nidevent) {static IINDEX = 0; char Szsend [20]; sprintf (szsend, "% 010d", IINDEX ); // Send TCP data int Isend = m_socksend.send (Szsend, 10, 0);} BOOL CMY63_S1_Clientdlg :: OnItDialog () {cdialog :: onInitdialog (); // Create a local set M_SockRecv.create (); // initiate connection request BOOL FC = m_sockRecv .Connect ("127.0.0.1", 6802); Trace ("Connect IS% S / N", (FC)? "OK": "Error"); // Start Timer, Timer Receive Data SETTIMER (1,3000 , NULL);} void cmy63_s1_clientdlg :: ONTIMER (uint nidevent) {char szrecv [20]; // Receive TCP Data INT IRECV = M_SockRecv.Receive (SzRecv, 10, 0); Trace ("ReceiveD% D Byte / N" , IRECV); if (IRECV> = 0) {szRecv [IRECV] = '/ 0'; m_szrecv = szre CV; Updatedata (false);}}

转载请注明原文地址:https://www.9cbs.com/read-29396.html

New Post(0)