1. Display dialog box
1.1 Display modal dialog box:
CDialogDemo dlg; dlg.DoModal();
1.2 Display non-modal dialog box:
CDialogDemo *dlg=new CDialogDemo(this); dlg->Create(IDD_GENERAL_CONTROL); dlg->ShowWindow(SW_SHOW);
2. Destroy dialog box
1.CDialog::OnOK(); // OK button pressed CDialog ::OnCancel(); //The cancel button is pressed
2.CDialog::DestoryWindow();
3.CDialog::EndDialog( IDD );
3. Close the own dialog in the modal dialog class Box
can close its own dialog box through PostMessage(WM_CLOSE) in the modal dialog class. After closing the MessageBox dialog box, the modal dialog box is closed.
The reference code is as follows:
<span style="font-size:18px;">BOOL CImportDataPromptDialog::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here HANDLE hThread = StartImportDataThread(); if (!hThread) { LOG("启动导入数据线程失败") } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } DWORD WINAPI CImportDataPromptDialog::ImportDataThread(LPVOID Param) { CImportDataPromptDialog* importDlg = (CImportDataPromptDialog*)Param; if (CImportLog::ExtractionXMLData(importDlg->m_sXmlFilePath, importDlg->m_sDBPath)) { importDlg->MessageBox("导入数据成功","平台", MB_ICONINFORMATION); importDlg->PostMessage(WM_CLOSE); } else { importDlg->MessageBox("导入数据失败","平台", MB_ICONEXCLAMATION); importDlg->PostMessage(WM_CLOSE); } return 0; } HANDLE CImportDataPromptDialog::StartImportDataThread() { LOG("启动导入数据线程"); CWinThread* hThread = AfxBeginThread((AFX_THREADPROC)CImportDataPromptDialog::ImportDataThread,(LPVOID)this); return (hThread->m_hThread); }</span>
4. Detailed explanation of several related important functions
4.1 CloseWindow
function function: This function minimizes the specified window, but does not destroy the window.
Function prototype: BOOL CloseWindow(HWND hWnd);
Parameters: hWnd: handle of the window to be minimized.
Return value: If the function succeeds, the return value is non-zero; if the function fails, the return value is zero. If you want to get more error information, please call the GetLastError function.
Note: The window size is minimized to an icon and moved to the icon area of the screen. The system displays the window's icon without displaying the window, and displays the window title beneath the icon. Applications must use the DestroyWindow function to destroy the window.
4.2 DestroyWindow
Function: Destroy the specified window. This function invalidates the window and removes its keyboard focus by sending the WM_DESTROY message and the WM_NCDESTROY message. This function also destroys the window's menu, clears the thread's message queue, destroys the timer related to the window process, releases the window's ownership of the clipboard, and interrupts the clipboard viewer's viewing chain.
Function prototype: BOOL DestroyWindow(HWND hWnd // handle to window to destroy);
hWnd: handle of the window to be destroyed.
Return value: If the function succeeds, the return value is non-zero: If the function fails, the return value is zero. If you want to get more error information, please call the GetLastError function.
Note: A thread cannot use this function to destroy windows created by other threads. If this window is a child window that does not have the WS_EX_NOPARENTNOTIFY style, the WM_PARENTNOTIFY message will be sent to its parent window when the window is destroyed. Windows CE: This function will not send the WM_NCDESTROY message.
4.3 EndDialog
Function: This function clears a modal dialog box and causes the system to terminate any processing of the dialog box.
Function prototype: BOOL EndDialog(HWND hDlg, int nResult);
Parameters: hDlg: Indicates the dialog window to be cleared. NResult: Specifies the value returned to the application from the create dialog function.
Return value: If the function call is successful, the return value is non-zero; if the function call fails, the return value is zero. If you want to get the error information, please call the GetLastError function.
Note: Dialog boxes created by DialogBox, DialogBoxParam, DialogBoxlndirect and DialogBoxlndirectParam functions must be cleared using the EndDialog function. The application calls the EndDialog function from within the dialog box application and this function cannot be used for other purposes. A dialog box application can call the EndDialog function at any time; even during WM_INITDIALOG message processing. If the application calls this function during WM_INTDIALOG message processing, the dialog box is cleared before display and input focus are set. The EndDialog function does not clear the dialog box immediately. Instead, it sets a flag and allows the dialog box application to return control to the system. The system detects the flag before attempting to retrieve the next message from the application queue. If the flag has been set, the system terminates the message loop, clears the dialog box, and uses the value in nResUlt as the value returned from the function that created the dialog box.

C# and .NET runtime work closely together to empower developers to efficient, powerful and cross-platform development capabilities. 1) C# is a type-safe and object-oriented programming language designed to integrate seamlessly with the .NET framework. 2) The .NET runtime manages the execution of C# code, provides garbage collection, type safety and other services, and ensures efficient and cross-platform operation.

To start C#.NET development, you need to: 1. Understand the basic knowledge of C# and the core concepts of the .NET framework; 2. Master the basic concepts of variables, data types, control structures, functions and classes; 3. Learn advanced features of C#, such as LINQ and asynchronous programming; 4. Be familiar with debugging techniques and performance optimization methods for common errors. With these steps, you can gradually penetrate the world of C#.NET and write efficient applications.

The relationship between C# and .NET is inseparable, but they are not the same thing. C# is a programming language, while .NET is a development platform. C# is used to write code, compile into .NET's intermediate language (IL), and executed by the .NET runtime (CLR).

C#.NET is still important because it provides powerful tools and libraries that support multiple application development. 1) C# combines .NET framework to make development efficient and convenient. 2) C#'s type safety and garbage collection mechanism enhance its advantages. 3) .NET provides a cross-platform running environment and rich APIs, improving development flexibility.

C#.NETisversatileforbothwebanddesktopdevelopment.1)Forweb,useASP.NETfordynamicapplications.2)Fordesktop,employWindowsFormsorWPFforrichinterfaces.3)UseXamarinforcross-platformdevelopment,enablingcodesharingacrossWindows,macOS,Linux,andmobiledevices.

C# and .NET adapt to the needs of emerging technologies through continuous updates and optimizations. 1) C# 9.0 and .NET5 introduce record type and performance optimization. 2) .NETCore enhances cloud native and containerized support. 3) ASP.NETCore integrates with modern web technologies. 4) ML.NET supports machine learning and artificial intelligence. 5) Asynchronous programming and best practices improve performance.

C#.NETissuitableforenterprise-levelapplicationswithintheMicrosoftecosystemduetoitsstrongtyping,richlibraries,androbustperformance.However,itmaynotbeidealforcross-platformdevelopmentorwhenrawspeediscritical,wherelanguageslikeRustorGomightbepreferable.

The programming process of C# in .NET includes the following steps: 1) writing C# code, 2) compiling into an intermediate language (IL), and 3) executing by the .NET runtime (CLR). The advantages of C# in .NET are its modern syntax, powerful type system and tight integration with the .NET framework, suitable for various development scenarios from desktop applications to web services.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools