We may have a lot of information when you enter information, and this information is not necessary. At this time, we need to give a selection interface to the information. For example, the employee information of a personnel department has such a problem.
Among them, the name, gender, age, political face, position, education, department, and contact number are information that must be entered, while marital status, graduation schools, origin, and health status are information that can be lost without losing, and in most cases You need to enter, how to provide a convenient input interface for information entry, let's provide a method I think a better way for this issue.
Step 1: Create a dialog-based project in the VC programming environment, the project is named expanddlg, all options take defaults.
Step 2: Establish our all dialogs, which must have two controls, one is the Picture control, one for the button, the id value is IDC_DIVIDER and IDC_MORE. Other controls can be arranged in any layout, the final result is that the dialog is divided into two parts by the IDC_Divider control, where the lower half can be dynamically displayed or not displayed according to your hobby, the dialog box is shown below:
Step 3: Generate the message mapping function of the button IDC_More, defined two functions in ExpandDLGDLG.H:
Public: void enablevisiblechildren (); Void ExpandDialog (int NResourceId, Bool BEXPAN);
Step 4: The implementation code defined in expanddlgdlg.cpp is as follows:
Void Cexpanddlgdlg :: ExpandDialog (INT NRESOURCEID, BOOL BEXPAND) {// Dialog is divided into top and bottom two parts by nresourceid, if the value of BEXPAND is completely displayed, otherwise the dialog box displays the upper part. static CRect rcLarge; static CRect rcSmall; CString sExpand; // at the beginning, only shows the upper half of the dialog if (rcLarge.IsRectNull ()) {CRect rcLandmark; CWnd * pWndLandmark = GetDlgItem (nResourceID); ASSERT (pWndLandmark); GetWindowRect (rcline); pWndlandMark-> getWindowRect (rcsmallmark); rcsmall = rclarge; rcsmall.bottom = rclandmark.top;}}} {// extension dialog to maximum size setWindowPos (NULL, 0, 0, RCLARGE.WIDTH) ), rclarge.height (), swP_nomove | swp_nozorder; sexpand = "<< & less"; enablevisiblechildren ();} else {// only displayed on the upper half of the dialog setWindowPos (NULL, 0, 0, RCSMALL.WIDTH) ), rcSmall.Height (), SWP_NOMOVE | SWP_NOZORDER); sExpand = "& More >>"; EnableVisibleChildren ();} SetDlgItemText (IDC_MORE, sExpand);} void CExpandDlgDlg :: EnableVisibleChildren () {// removed The function and shortcuts of the controls that do not display the dialog box. // Get the first window CWnd * pwndctl = getWindow (GW_CHILD); CRECT RCTEST; CRECT RCCONTROL; CRECT RCSHOW; // Get full rectangular box for dialog GetWindowRect (rcshow); while (pwndctl! = Null) {// get The rectangular dimensions of the currently displayed dialog PWNDCTL-> getWindowRect (rccontrol);
if (rcTest.IntersectRect (rcShow, rcControl)) pWndCtl-> EnableWindow (TRUE); else pWndCtl-> EnableWindow (FALSE); // get a second rectangular frame pWndCtl = pWndCtl-> GetWindow (GW_HWNDNEXT);}} void CExpandDlgDlg :: onmore () {static bool bexpand = true; expanddialog (idc_divider, bexpand; bexpand =!
Follow the steps above to generate our executable and run, click [more] on the dialog, we can discover the dialog extension, click [Less], we find that the dialog contraction, I hope you can bring you convenience.
Create an irregular shape window using VC
Take a closer look at the Win32 API and find that the window that creates any shape is also very simple. The simple step in the VC is as follows:
When we register and create a window class, we do the following in the WM_CREATE message:
(1) Create a zone, use createPolyonRGN, which creates a polygon area (you can also use other methods such as CreateRectrgn to create a rectangular area), which returns an HRGN handle;
(2) Call the function setWindowRGN, you can set the shape of the window.
Supplementary, we can make multiple areas, then combine multiple regions into a zone with the Combinergn method. This way we can make a more rich window.
VC Programming Implementation IE Style Interface Liu Tao ·· Yesky
Using the IE browser knows the flat toolbar on the IE interface, the button on the address bar, the button on the flat toolbar is flat, the image on the button is gray, when the mouse is placed on the button, the button protrudes (This state is called a handle), and the image on which it is made fresh, and there is a Chinese character note or a drop button labeled a small black triangle. When you click, the drop-down menu is displayed. How is these technologies achieve? This article introduces these issues to implement them with VC programming.
The implementation of the IE style is mainly implemented in the main framework CMAINFRAME :: OnCreate (), its main idea is as follows: First, a CREBAR object is defined to make a toolbar, the container of the address bar, then declare the image list object IMG. The image of the hotspot image of the toolbar and the image displayed in the normal state. To display the flat toolbar, you need to create a CreateEx () function M_WndToolBar, with the modifystyle () function Set the toolbar's style as a flat type, you can't use CToolBar :: Create () or CToolbar :: setbarstyle () to set this New style. The CToolbar class does not support TBStyle_FLAT. To solve this problem, you must bypass the CToolbar class, use CWnd :: ModifyStyle (). The toolbar object calls the setButtonInfo () Setting button's style to TBStyle_Dropdown, you can set the toolbar button to attach the drop-down button. As for the button with a Chinese prompt, it can be easily implemented with setButtonTontext () in the toolbar. Here is some code and annotations that implement the IE style interface:
int CMainFrame :: OnCreate (LPCREATESTRUCT lpCreateStruct) {CReBar m_wndReBar; // declare CReBar objects CImageList img; // declare a list of image objects CString str; if (CFrameWnd :: OnCreate (lpCreateStruct) == -1) return -1; if ( ! m_wndrebar.create (this)) // Create a Crebar object {trace0 ("failed to create rebar / n"); return -1; // fail to create} if (! m_wndtoolbar.createex (this)) // creation tool Object {trace0 ("failed to create toolbar / n"); return -1; // fail to create} // set up Toolbar Properties m_wndtoolbar.gettoolbarctrl (). SetButtonWidth (50, 150); file: // Settings Tool The largest, minimum size m_wndtoolbar.gettoolbarctrl (). SetExtendedStyle (TBSTYLE_EX_DRAWDDARROWS); File: // Toolbar can bring drop-down button img.create (IDB_HOTTOOLBAR, 22, 0, RGB (255, 0, 255)); File: // Load hotspot image resources to the image list, idb_hottoolbar is the hotspot image resource ID m_wndtoolbar.gettoolbarctrl (). sethotimagelist (& img); // Toolbar loading hotspot image img.detach (); img.create (idb_coldtoolbar, 22, 0, RGB (255, 0, 255); File: // Image list loads the image resource of the normal state, IDB_Coldtoolbar is the image resource ID m_wndtoolbar.gettoolbarctrl (). Setimagelist (& img); // Put the image to the toolbar img.detach (); M_WndtoolBar.ModifyStyle (0, TBStyle _FLAT | TBSTYLE_TRANSPARENT); File: // Toolbar is a flat-style m_wndtoolbar.setButtons (NULL, 9); // Toolbar // SET UP Each Toolbar Button File: // The following respectively nine buttons respectively Chinese style settings and button prompts m_wndToolBar.SetButtonInfo (0, ID_BUTTON0, TBSTYLE_BUTTON, 0); str.LoadString (IDS_ BUTTON0); m_wndToolBar.SetButtonText (0, str); m_wndToolBar.SetButtonInfo (1, ID_BUTTON1, TBSTYLE_BUTTON, 1); str .LoadString (IDS_ BUTTON1); m_wndToolBar.SetButtonText (1, str); m_wndToolBar.SetButtonInfo (2, ID_BUTTON2, TBSTYLE_BUTTON, 2); str.LoadString (IDS_ BUTTON2); m_wndToolBar.SetButtonText (2, str); m_wndToolBar.SetButtonInfo ( 3, ID_Button3, TBStyle_Button, 3); str.loadstring (IDS_ Button3); m_wndtoolbar.setButtonTontext (3, STR);
m_wndToolBar.SetButtonInfo (4, ID_BUTTON4, TBSTYLE_BUTTON, 4); str.LoadString (IDS_ BUTTON4); m_wndToolBar.SetButtonText (4, str); m_wndToolBar.SetButtonInfo (5, ID_BUTTON5, TBSTYLE_BUTTON, 5); str.LoadString (IDS_ BUTTON5) ; m_wndToolBar.SetButtonText (5, str); m_wndToolBar.SetButtonInfo (6, ID_BUTTON6, TBSTYLE_BUTTON | TBSTYLE_DROPDOWN, 6); str.LoadString (IDS_ BUTTON6); m_wndToolBar.SetButtonText (6, str); m_wndToolBar.SetButtonInfo (7, ID_BUTTON7, TBSTYLE_BUTTON, 7); str.LoadString (IDS_ BUTTON7); m_wndToolBar.SetButtonText (7, str); m_wndToolBar.SetButtonInfo (8, ID_BUTTON8, TBSTYLE_BUTTON | TBSTYLE_DROPDOWN, 8); str.LoadString (IDS_ BUTTON8); m_wndToolBar.SetButtonText (8 , STR); File: / / Re-adjust button CRECT RECTTOOLBAR; M_WNDTOOLBAR.GETITEMRECT (0, & RectToolBar); // Get the first button of the toolbar M_WndtoolBar.setsizes (RectToolBar.Size (), CSIZE (30, 20)); file: // The first parameter is the button size, the second parameter is image size file: // Create a combo box as the address bar if (! M_Wnddress.create (CBS_DROPDOWN | WS_CHILD, CRECT (0, 0) , 200, 120), AFX_IDW_TOOLBAR 1)) {Trace0 ("Failed to C reate combobox / n "); return -1; // fail to create} file: // Add the tool bar, address bar m_wndReBar.AddBar (& m_wndToolBar); str.LoadString (IDS_ADDRESS); m_wndReBar.AddBar (& m_wndAddress, str, NULL , RBBS_FIXEDBMP | RBBS_BREAK); file: // define REBARBANDINFO object, toolbar and address bar to set the desired size REBARBANDINFO rbbi; rbbi.cbSize = sizeof (rbbi); rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE; rbbi.cxMinChild = rectToolBar .Width (); rbbi.cyminchild = RectToolbar.height (); rbbi.cx = rbbi.cxideal = RectToolBar.width () * 9; m_wndrebar.getrebarctrl (). SetBandInfo (0, & RBBI); // Setting toolbar size Rbbi.cxminchild = 0; CRECT RectAddress; rbbi.fmask = rbbim_childsize | RBBIM_IDEALSIZE; M_WNDDRESS.GETEDITCTRL () -> GetWindowRect (&)
rectAddress); rbbi.cyMinChild = rectAddress.Height () 10; rbbi.cxIdeal = 200; m_wndReBar.GetReBarCtrl () SetBandInfo (2, & rbbi); // Set the address bar size m_wndToolBar.SetBarStyle (m_wndToolBar.GetBarStyle (.) | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED); if (! m_wndStatusBar.Create (this) || m_wndStatusBar.SetIndicators (indicators, sizeof (indicators) / sizeof (UINT))) {TRACE0 ( "Failed to create status bar / n");! Return -1; // fail to create} return 0;} The above code is compiled in the Windows2000 and Visual C environments. The program runs properly, interested friends can do it personally.
VC restricted window size is still a method of emissivity
Generally speaking, it is intercepted WM_GETMAXMININFO message.
There is another experience to be realized.
Due to the change in the size of the general window, it is caused by the user drag the window border. Therefore, we can intercept the main window message WM_NCHITTEST to determine if the return value of CWnd :: onnchittest () in its response function is one of the four values of htright, htleft, httop, htbottom, if so, explain that the user is already clicked four One of the borders, at this time we should return htclient. So, the shape of the mouse will not turn horizontally or vertically two-way arrows, and users cannot rely on drag border to change the window size.
In addition, it should be added to a small loophole, which is also to remove SC_SIZE in the system menu.
Copyright window CPCW before the main program
WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int) {DWORD lTime; try {Application-> Initialize (); AboutBox = new TAboutBox (AboutBox); AboutBox-> BorderStyle = bsNone; AboutBox-> OKButton-> Visible = false; AboutBox -> Height = 185; Aboutbox-> show (); AboutBox-> update (); ltime = gettickcount (); application-> createform (__ classid (tMAINFORM), & MainForm); while ((GettickCount () - ltime) / 1000 <3); Aboutbox-> Hide (); Aboutbox-> Free (); Application-> Run ();} catch (exception & exception) {Application-> showexception (& Exception);} return 0;}
Visual C 6.0 Add a bitmap in the MDI main frame window Liu Tao Yesky author wants to add a color bitmap in the MDI program when developing a project, and experimented several methods, but there are some small problems. Find information, finally achieved this function, now introduced my implementation to everyone.
First, you must clearly include a special sub-window for a MDI application, called a MDICLIENT window, and a member variable m_hwndmdiclient refers to the Mdiclient window in the primary frame class of the application. The MDICLIENT window is responsible for managing the client area of the main framework window, which has a certain difficulty of programming the MDI customer window. The reason is that the client area of MDIFrameWnd is completely covered by the MDICLIENT window. In this way, the background color and cursor of the MDI main window MDIFRAMEWND do not work. At the same time, Microsoft does not support the MDICLIENT window as a subclass, and the MDICLIENT window can only use standard background colors and cursors. So, the MDI customer window cannot be easily overloaded to the message processing function of WM_Paint as simple as the normal window. We can intercept the redo message about the MDICLIENT window at the main frame window, and then join your own code. I intercepted the MDI client window WM_PAINT message with PretranslateMessage (MSG * PMSG), transmitting a WM_PAINT message to the main frame window in this function, and the display of the color bitmap is implemented in the processing function of the message. My specific implementation is as follows: 1, add 256 color color bitmap resources to the program, named IDB_bitmap1; 2, add function to the main frame class with ClassWizard; 3, use classwizard to the main framework Add a function cmainframe :: onpaint (); now give the implementation of the two functions:
BOOL CMainFrame :: PreTranslateMessage (MSG * pMsg) {// TODO: Add your specialized code here and / or call the base class if (pMsg-> hwnd == m_hWndMDIClient && pMsg-> message == WM_PAINT) PostMessage (WM_PAINT); Return Cmdiframewnd :: PretranslateMessage (PMSG);
void CMainFrame :: OnPaint () {CDC dc, memdc; dc.m_hDC = :: GetDC (this-> m_hWndMDIClient); CRect rect; CBitmap bitmap; BITMAP szbitmap; bitmap.LoadBitmap (IDB_BITMAP1); bitmap.GetObject (sizeof (BITMAP ), & szbitmap); CSize size (szbitmap.bmWidth, szbitmap.bmHeight); memdc.CreateCompatibleDC (& dc); CBitmap * oldbitmap = memdc.SelectObject (& bitmap); GetClientRect (& rect); StretchBlt (dc.m_hDC, 0,0, Rect.width (), rect.m_hdc, 0,0, size.cx, size.cy, srccopy; MEMDC.SELECTOBJECT (OldbitMap); MEMDC.DELETEDC (); dc.deletedc (); CMDIFrameWnd :: onpaint ();} You can display a color bitmap in the MDI program in the MDI program. The example I will use 256 color bitmap, you can also display the display of true color bitmaps, specific methods I Not much to say, interested friends can try it