Home > Software engineering >  CFileDialog save as dialog box does not show?
CFileDialog save as dialog box does not show?

Time:10-21

Implement a dialog based file transfer, the client to select a file, to start a thread function on the server, in serverdlg. CPP statement
 UINT server_thd (LPVOID p) 
{
If ((ssocket=accept (listen_sock, (struct sockaddr *) & amp; Client_addr, & amp; IaddrSize))==INVALID_SOCKET)
{
//MessageBox (__T (" failed to create listening "))
}
While (1)
{
Res=recv (ssocket, MSG, 1024, 0);
MSG (res)='\ 0';
: : MessageBox (NULL, "Recv a File"), NULL, MB_OK);
CFileDialog DLG (FALSE);
DLG. M_ofn. HInstance=AfxGetInstanceHandle ();
DLG. M_ofn. LpstrFilter="All Files (*. *) | (*. *)".
DLG. M_ofn. LpstrFile=filename;
DLG. M_ofn. Flags & amp;=~ OFN_EXPLORER;
If (DLG) DoModal ()==IDOK)
{
CFile file (filename, CFile: : modeCreate | CFile: : typeBinary | CFile: : modeWrite);
}
}
}

Transmission TXT and excel file are no problem, PDF and MP4 file, save as dialog can't open, single step mode to enter
INT_PTR CFileDialog: : DoModal () function,
 if (m_ofn hwndOwner!=NULL & amp; & : : IsWindowEnabled (m_ofn hwndOwner)) 
{
BEnableParent=TRUE;
: : EnableWindow (m_ofn hwndOwner, FALSE);
}

To: : EnableWindow (m_ofn hwndOwner, FALSE); Is stuck,
Mode output shows thread withdrew,
Thread 'Win32 threads (0 x1748) have withdrawn, the return value is zero (0 x0),
Thread 'Win32 threads (0 x1f14) have withdrawn, the return value is zero (0 x0),
Thread 'Win32 threads (0 x12fc) have withdrawn, the return value is zero (0 x0),
Thread 'Win32 threads (0 x1628) have withdrawn, the return value is zero (0 x0),
Ah, in asking great god answer puzzled me for a long time,

CodePudding user response:

In the thread function opens a dialog box, what a strange idea.

CodePudding user response:

Like logic is also wrong,
1 each receive 1024 bytes will save as a file, if sent by file bytes larger than 1024 to do,
2 filename is to save the file name. If the save dialog artificially modified file name a name can be a problem
3 to 2 floor

CodePudding user response:

In the second floor also have said, logic has a problem, the file size, good processing, you also too simple processing method

CodePudding user response:

Can't work in the open dialog box in the thread, this is wrong, no message loop in the worker thread processing, you can send window messages to the worker thread main thread, to do the work related to the UI, completes the synchronization between the thread processing,

CodePudding user response:

refer to the second floor mlqxj35674 response:
if logic is also wrong,
1 each receive 1024 bytes will save as a file, if sent by file bytes larger than 1024 to do,
2 filename is to save the file name. If the save dialog artificially modified file name a name can be a problem
3 to 2 floor

Well, just transfer to come over to the file name and file size for the first time, and then create a file, and then receive data writing, each receiving 1024, in 1024, how many bytes, depending on the transmission of the save as dialog filename is coming, the default is written in the save as dialog box, will be modified if there is a problem, but this is just a small problem, know where is wrong, mainly I don't know where is wrong, why the TXT can be normal, test the TXT file size of 3 m, more than 1024 b,

CodePudding user response:

reference 1st floor happyparrot response:
opens a dialog box in the thread function, is really a strange idea.

Why, just want to use a thread to monitor, the client sends the file to come over, will pop up a dialog,

CodePudding user response:

reference bojie5744 reply: 3/f
also said there were in the second floor, there is something wrong with the logic, the file size, good processing, you also too simple processing method

The logic of the file size is no problem, can I preach the TXT trillions, is to open the other format file, save as dialog box to open it, I use my estimates thread to open the dialog box in the right way, don't know you refers to the logic of I deal with logic or the file, or other aspects of the logic, please feel free to give directions in detail bai,

CodePudding user response:

The file filter type change, followed by \ \, "All Files (*. *) | (*. *) | |" have a try

CodePudding user response:

Thread used in the need to initialize the COM
 CoInitializeEx (NULL, COINIT_APARTMENTTHREADED); 
.
CoUninitialize ();
  • Related