How to effectively use the dialog box

xiaoxiao2021-03-06  43

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

This article is "How to Effectively Use the Dialog box" to continue.

1. How to effectively make the initial window not display when we want the window to be initially not displayed, it usually uses showWindow (sw_hide), but actually starts to see a slit that the window flashes. Therefore, you can use the following method to implement it: (1.1) Set the Built Variable Visible value in the constructor is False.

Visible = false;

(1.2) Overload WM_WindowPoschanging and add the following code:

Void ctest_deletedlg :: OnWindowPoschanging (WindowPos Far * lpwndpos)

{

IF (! Visible)

LPWNDPOS-> FLAGS & = ~ SWP_SHOWINDOW;

CDIALOG :: OnWindowPoschanging (lpwndpos);

}

(1.3) Then set the Visible variable value of True and use showWindow (sw_show) when you want to display the window.

Visible = true;

ShowWindow;

2. The full screen display of the dialog box's full screen display can use SetWindowPos and HWND_TOPMOST to realize the rear size of the dialog 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 to get the focus under 2K / XP We can use AttachthReadInput and setForeGroup to valid access.

// 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 to the top of the top of OnInitDialog () to be implemented in setWindowPos.

SetWindowPOS (& this-> Wndtopmost, 0,0,0,0,0, swp_nomove | swp_nosize); 5. How to dynamically zoom in / narrowing dialogs can also be implemented 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 it is allowed

// 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 let the dialog back to the screen to bring it back to the screen when the dialog is dragged away from the screen.

SendMessage (DM_Reposition);

Note: It must be the top window and is not a Child window. 7. How to add or remove the maximum / minimize button to dialog box in onCreate () or onInitDialog () changes its display style.

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 to 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 colors of the dialog box can be implemented in InitInstance ().

// red background, green foreground

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

10. On the task bar, the icon is not displayed in the CWINAPP inheritance class to create a top-level window that is not displayed.

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. Add, hereby help in OnInitDialog modify the display style, join, the following HLP helps display.

Bool helpdialog :: oninitdialog ()

{

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;

}

}

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

New Post(0)