How to effectively use the dialog box

zhaozj2021-02-08  214

How to use the translator of how to use dialog box: Xu Jingzhou (original: Nishant S)

1. How to effectively make the initial window not displayed

When we want the window to start when the window is not displayed, it usually uses ShowWindow, but actually still launches the window that can be seen by the window. Therefore, you can use the following method to implement it:

l Set in the constructor to set the Visible value for False.

Visible = false;

l Reload WM_WINDOWPOSCHANGING and add the following code:

Void ctest_deletedlg :: OnWindowPoschanging (WindowPos Far * lpwndpos)

{

IF (! Visible)

LPWNDPOS-> FLAGS & = ~ SWP_SHOWINDOW;

CDIALOG :: OnWindowPoschanging (lpwndpos);

}

l Then set the cloth Visible Value True and use ShowWindow (sw_show) when you want to display the window.

Visible = true;

ShowWindow;

2. Direct screen display of the dialog

The full screen display of the dialog can be rearranged with SETWINDOWPOS and HWND_TOPMOST in OnInitDialog ().

Bool cfullscrdlgdlg :: oninitdialog ()

{

CDIALOG :: OnInitdialog ();

// ...

INT CX, CY;

HDC DC = :: getdc (null);

CX = getDeviceCaps (DC, Horzres)

GetSystemMetrics; SM_CXBORDER

CY = getDeviceCaps (DC, Vertres)

GetSystemMetrics; SM_CYBORDER

:: ReleaseDC (0, DC);

// Remove the title and border

Setwindowlong (m_hwnd, gwl_style,

GetWindowlong (M_HWND, GWL_STYLE) &

(~ (WS_CAPTION | WS_BORDER)))))));

// Set the dialog as the top and expand to the entire screen

:: SetwindowPos (M_HWND, HWND_TOPMOST,

- (GetSystemMetrics 1),

- (GetSystemMetrics 1),

CX 1, CY 1, SWP_NOZORDER);

// ...

Return True;

}

3. How to get the window in 2K / XP

Under 2k / XP we can use AttachthReadInput and setForegroundWindow to get focus.

// Capture and set the current focus window for our window

AttachthreadInput

GetWindowThreadProcessId

:: getForegroundWindow (), NULL,

GetCurrentThreadId (), true);

// Place our focus window

SetForegroundWindow ();

Setfocus ();

// Release Thread

AttachthreadInput

GetWindowThreadProcessId

:: getForegroundWindow (), NULL,

GetCurrentThreadID (), FALSE);

4. Make your dialog box at the top

You can use SetWindowPos in OnInitDialog ().

SetwindowPos (& this-> Wndtopmost, 0,0,0,0,0, swp_nomove | swp_nosize); 5. How to dynamically zoom / Reduce dialog

It is still possible to implement it with SetWindowPos or MoveWindow.

Void ctest_deletedlg :: onmakesmall ()

{

SetwindowPOS (NULL, 0, 0, 200, 200, SWP_NOZORDER | SWP_NOMOVE);

}

Void ctest_deletedlg :: Onexpand ()

{

SetwindowPos (NULL, 0, 0, 500, 300, SWP_NOZORDER | SWP_NOMOVE);

}

or:

// Stretch, shrink between IDC_DYCREDITS and IDC_COPYRIGHT two STITIC controls, as partitionline

Bool cabout :: OnInitDialog ()

{

CDIALOG :: OnInitdialog ();

// "About" dialog box can shrink

CRECT RECT1, RECT2; / / Dialog Seasonal

Getdlgitem (IDC_DYCREDITS) -> getWindowRect (Rect1);

Getdlgitem (IDC_CopyRight) -> getWindowRect (Rect2);

m_nreducedheight = Rect1.Height () (Rect1.top -Rect2.bottom) / 2; // After shrinking the form height

DLGRect.bottom - = (Rect1.Height () (Rect1.top -Rect2.bottom) / 2);

MoveWindow (& DLGRECT); / / If you want to display the dialog starting dynamic effect, you cannot use this sentence.

m_bvertical = false; // Default Continue dialog

}

/ / -------------------------------------------------------------------------------------------- ---------

// Name: Onmore

// Function: Whether to honor

// Variable: no

// Return: None

// Write: Xu Jing Zhou, 2002.4.8

/ / -------------------------------------------------------------------------------------------- ---------

Void Cabout :: ONMORE ()

{

m_bvertical =! m_bvertical;

IF (m_bvertage == false // does not display

{

Setdlgitemtext (ID_MORE, _T ("more >>"));

SizeWindow (M_nReducedheight, true);

// m_dycredits.endscrolling (); // Stop scrolling

}

ELSE // Display

{

Setdlgitemtext (ID_MORE, _T ("<< Hide"));

SizeWindow (M_nReducedheight, False);

m_dycredits.startscrolling (); // Start scrolling

}

UpdateWindow ();

}

/ / -------------------------------------------------------------------------------------------- --------- // Name: SizeWindow

// Function: Stretch or Contract dialog

// Variable: reduceheight - contraction height, bextend - is stretched

// Return: None

// Write: Xu Jing Zhou, 2002.4.8

/ / -------------------------------------------------------------------------------------------- ---------

Void Cabout :: SizeWindow (Int ReduceHeight, Bool Bextend)

{

CRECT RC;

GetWindowRect (& RC);

IF (bextend)

{

For (int i = 0; i

{

Rc.bottom

MoveWindow (& RC);

}

}

Else

{

For (int i = 0; i

{

RC.BOTTOM ;

MoveWindow (& RC);

}

}

}

6. How to make the dialog back to the screen

When the dialog is dragged from the screen, you can use the following code to return it to the screen.

SendMessage (DM_Reposition);

Note: It must be the top window and is not a chind window.

7. How to add or remove the maximum / minimize button to the dialog

Change its display style in onCreate () or OnInitDialog ().

INT ctest_deletedlg :: oncreate (lpcreateStruct lpcreatestruct)

{

IF (cdialog :: oncreate (lpcreatestructure) == -1)

Return -1;

// Todo: Add Your Specialized Creation Code Here

Setwindowlong (this-> m_hwnd, gwl_style,

GetWindowlong (this-> m_hwnd, gwl_style) |

WS_MINIMIZEBOX | WS_MAXIMIZEBOX;

Return 0;

}

Or use:

ModifyStyle (NULL, WS_MAXIMIZEBOX);

8. Change the mouse pointer

Can be implemented in OnsetCursor.

BOOL CTEST_DELETEDLG :: OnsetCursor (CWND * PWND, UINT NHITTEST, UINT MESSAGE)

{

// Todo: add your message handler code here and / or call default

SetCursor (AFXGetApp () -> LoadStandardCursor (IDC_UPARROW);

// Now we return instead of calling the base class

Return 0;

// Return CDIALOG :: OnsetCursor (PWND, NHitTest, Message);

}

9. Change the foreground and background color of the dialog

Can be implemented in InitInstance ().

// red background, green foreground

SetDialogbkcolor (RGB (255, 0), RGB (0,255,0));

10. Icon not displayed on the task bar

First create a top-level window that is not displayed from the CWINAPP inheritance class.

CframeWnd * ABC = New CFrameWnd ();

ABC-> CREATE (0, 0, WS_OVERLAPPEDWINDOW);

CNotaskBaricondlg DLG (ABC);

m_pmainwnd = & dlg;

INT nresponse = dlg.domodal ();

IF (NRESPONSE == iDok)

{

}

Else IF (nresponse == idcancel)

{

}

DELETE ABC;

Modify the display style WS_EX_APPWindow in OnInitDialog.

Bool cnotaskbaricondlg :: oninitdialog ()

{

CDIALOG :: OnInitdialog ();

ModifyStyleex (WS_EX_APPWINDOW, 0);

Seticon (M_Hicon, True); // set Big icon

Seticon (M_Hicon, False); // set small icon

// Todo: Add Extra Initialization Here

Return True; // Return True UnsS you set the focus to a control

}

11. Join, here to help

Modify the display style, join on LinitDialog, join, HLP Help Help Display.

Bool helpdialog :: oninitdialog ()

{

// Blah Blah Blah

// Blah Blah Blah

ModifyStyleex (0, WS_EX_CONTEXTHELP);

Return cdialog :: oninitdialog ();

}

Overload onhelpinfo (...), with display related help information

Bool helpdialog :: onhelpinfo (helpinfo * phelpinfo)

{

Short State = getKeyState (VK_F1);

IF (State <0) // F1 Key Is Down, Get Help for THE DIALOG

Return CDIALOG :: onhelpinfo (Phelpinfo);

Else

{// F1 Key Not Down, Get Help for Specific Control

IF (Phelpinfo-> dwconTextID)

Winhelp (Phelpinfo-> dwcontextid,

Help_contextpopup;

Return True;

}

}

Contact information:

Author email: jingzhou_xu@163.com

Future Studio (Future Studio)

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

New Post(0)