Thousands of strange forms (windows)

xiaoxiao2021-04-10  391

Any extension of the VC dialog

Bull77 Yesky

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 problems, of which the name, gender, age, political face, position, education, department, and contact call are the information that must be entered, while marital status, graduation school, giving and health The condition is the information that can be lost without losing, and there is no need to enter, how to provide a convenient input interface for information entry, and we provide a better way I think about this problem.

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, and the final result is that the dialog is divided into two parts by the IDC_DIVIDER control, where the lower half can dynamically display or display 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 Bexpand);

Step 4: The implementation code defined in expanddlgdlg.cpp is as follows:

Void Cexpanddlgdlg :: ExpandDialog (int NResourceId, Bool BEXPAND)

{

// The dialog is divided into two parts by nresourceid, if the value of bexpand is True

// The dialog is completely displayed, otherwise the dialog box displays the upper part.

Static CRECT RCLARGE;

Static CRECT RCSMALL;

Cstring sexpand;

// At the beginning, the dialog only shows the upper part.

IF (RcLarge.Inectnull ())

{

CRECT RCLANDMARK;

CWND * PWNDLANDMARK = getdlgitem (nresourceID);

Assert (pwndlandmark);

GetWindowRect (rcline);

PWNDLANDMARK-> getWindowRect (rclandmark);

Rcsmall = rclarge;

RCSMALL.BOTTOM = rclandmark.top;

}

IF (BEXPAND)

{

// Extended dialog to maximum size

Setwindowpos (NULL, 0, 0, RCLARGE.WIDTH (), RCLARGE.HEIGHT (),

SWP_NOMOVE | SWP_NOZORDER);

Sexpand = "<< & less";

Enablevisiblechildren ();

}

Else

{

// Only the upper part of the dialog box

SetwindowPos (NULL, 0, 0, RCSMALL.WIDTH (), RCSMall.Height (),

SWP_NOMOVE | SWP_NOZORDER);

SEXPAND = "& more >>";

Enablevisiblechildren ();

}

Setdlgitemtext (IDC_MORE, Sexpand);

}

Void Cexpanddlgdlg :: enablevisiblechildren () {

/ / Remove the functions 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 the full rectangle frame of the dialog

GetWindowRect (rcshow);

While (PWndCTL! = NULL)

{// Get the rectangular size of the currently displayed dialog

PWNDCTL-> GetWindowRect (RcControl);

IF (rctest.intersectRect (rcshow, rccontrol))

PWNDCTL-> EnableWindow (TRUE);

Else

PWNDCTL-> EnableWindow (FALSE);

// Get the second rectangle

PWNDCTL = PWNDCTL-> getWindow (GW_HWndNext);

}

}

Void Cexpanddlgdlg :: onore ()

{

Static Bool Bexpand = True;

ExpandDialog (IDC_DIVIDER, BEXPAN);

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

Yixian time and space

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 implements 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 part of the code and notes to implement the IE style interface: int CMAINFRAME :: OnCreate (lpcreatestruct lpcreatestruct)

{

Crebar M_Wndrebar; // Declare CREBAR object

CIMAGELIST IMG; // Declaration Image List Object

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)) // Create a toolbar object

{

Trace0 ("Failed to Create Toolbar / N);

Return -1; // fail to create

}

// SET UP TOOLBAR PROPERTIES

M_WndtoolBar.gettoolbarctrl (). setButtonWidth (50, 150);

File: // Set the maximum, minimum size of the button on the toolbar

M_WndToolBar.gettoolbarctrl (). setExtendedStyle (TBSTYLE_EX_DRAWDDARROWS);

File: // Toolbar can bring a drop-down button

Img.create (IDB_Hottoolbar, 22, 0, RGB (255, 0, 255);

File: / / load hotspot image resource to the image list, IDB_HOTTOOLBAR is a hot 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 resources of the normal state, IDB_COLDTOOLBAR is the image resource ID

m_wndtoolbar.gettoolbarctrl (). setimagelist (& IMG); // Put the image into the toolbar

img.detach ();

M_WndToolBar.ModifyStyle (0, TBStyle_FLAT | TBSTYLE_TRANSPARENT);

File: // Tools Tools are flat-style m_wndtoolbar.setButtons (NULL, 9); // has 9 buttons on the toolbar

// SET UP Each Toolbar Button

File: // The following sets of nine buttons to set the style and button Chinese prompts, respectively.

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.setButtonText (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 the size of the button

CRECT RECTTOOLBAR;

m_wndtoolbar.getItemRect (0, & RectToolbar); // Get the size of 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 an address bar

IF (! m_wndaddress.create (CBS_DropDown | WS_CHILD, CRECT (0, 0, 200, 120), This, AFX_IDW_TOOLBAR 1))

{

Trace0 ("Failed to Create ComboBOX / N");

Return -1; // fail to create

}

File: // Add Toolbar, address bar m_wndrebar.addbar (& m_wndtoolbar);

Str.LoadString (IDS_ADDRESS);

M_WndreBar.Addbar (& M_Wndaddress, Str, NULL, RBBS_FIXEDBMP | RBBS_BREAK);

File: // Define the RebarbandInfo object, set the ideal size for the toolbar and address bar

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_Wndaddress.Geteditctrl () -> getWindowRect (& RectAddress);

RBBI.CYMINCHILD = RectAddress.Height () 10;

RBBI.CXIDEAL = 200;

m_wndrebar.getrebarctrl (). setBandInfo (2, & RBI); // Set the address bar size

m_wndtoolbar.setbarstyle (m_wndtoolbar.get barStyle () |

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 personally experiment.

VC restriction window size is another method

Yixian time and space

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 before the main program

CPCW

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 adds a bitmap in the MDI main frame window

Liu Tao Yesky

The author wants to add a color bitmap in the MDI program when developing a project, and experimented several ways, but there are some small problems. After multi-find information, this is finally achieved, and now I will Implementation method introduction 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, and has certain difficulties to program 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.Height (),

Memdc.m_hdc, 0,0, size.cx, size.cy, srccopy;

MEMDC.SELECTOBJECT (OLDBITMAP);

MEMDC.DELETEDC ();

dc.deletedc ();

CmdiframeWnd :: onpaint ();

}

According to the above steps, you can display the color bitmap in the MDI program. I will use the 256 color bitmap. You can also realize the display of true color bitmaps. If I don't have much way, I am interested Friends can try it.

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

New Post(0)