Creation and destruction of subdialog boxes
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.

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In C, the char type is used in strings: 1. Store a single character; 2. Use an array to represent a string and end with a null terminator; 3. Operate through a string operation function; 4. Read or output a string from the keyboard.

Multithreading in the language can greatly improve program efficiency. There are four main ways to implement multithreading in C language: Create independent processes: Create multiple independently running processes, each process has its own memory space. Pseudo-multithreading: Create multiple execution streams in a process that share the same memory space and execute alternately. Multi-threaded library: Use multi-threaded libraries such as pthreads to create and manage threads, providing rich thread operation functions. Coroutine: A lightweight multi-threaded implementation that divides tasks into small subtasks and executes them in turn.

The calculation of C35 is essentially combinatorial mathematics, representing the number of combinations selected from 3 of 5 elements. The calculation formula is C53 = 5! / (3! * 2!), which can be directly calculated by loops to improve efficiency and avoid overflow. In addition, understanding the nature of combinations and mastering efficient calculation methods is crucial to solving many problems in the fields of probability statistics, cryptography, algorithm design, etc.

std::unique removes adjacent duplicate elements in the container and moves them to the end, returning an iterator pointing to the first duplicate element. std::distance calculates the distance between two iterators, that is, the number of elements they point to. These two functions are useful for optimizing code and improving efficiency, but there are also some pitfalls to be paid attention to, such as: std::unique only deals with adjacent duplicate elements. std::distance is less efficient when dealing with non-random access iterators. By mastering these features and best practices, you can fully utilize the power of these two functions.

In C language, snake nomenclature is a coding style convention, which uses underscores to connect multiple words to form variable names or function names to enhance readability. Although it won't affect compilation and operation, lengthy naming, IDE support issues, and historical baggage need to be considered.

The release_semaphore function in C is used to release the obtained semaphore so that other threads or processes can access shared resources. It increases the semaphore count by 1, allowing the blocking thread to continue execution.

The history and evolution of C# and C are unique, and the future prospects are also different. 1.C was invented by BjarneStroustrup in 1983 to introduce object-oriented programming into the C language. Its evolution process includes multiple standardizations, such as C 11 introducing auto keywords and lambda expressions, C 20 introducing concepts and coroutines, and will focus on performance and system-level programming in the future. 2.C# was released by Microsoft in 2000. Combining the advantages of C and Java, its evolution focuses on simplicity and productivity. For example, C#2.0 introduced generics and C#5.0 introduced asynchronous programming, which will focus on developers' productivity and cloud computing in the future.

Dev-C 4.9.9.2 Compilation Errors and Solutions When compiling programs in Windows 11 system using Dev-C 4.9.9.2, the compiler record pane may display the following error message: gcc.exe:internalerror:aborted(programcollect2)pleasesubmitafullbugreport.seeforinstructions. Although the final "compilation is successful", the actual program cannot run and an error message "original code archive cannot be compiled" pops up. This is usually because the linker collects
