|
so, i can't exchange the position of the list items with the LVS_AUTOARRANGE style, my god.
|
|
|
|
|
That sounds quite reasonable if you have specified that they should be arranged automatically.
MVP 2010 - are they mad?
|
|
|
|
|
but it can exchange items' position if you dragging the icon on the desktop within the application of explorer.exe, i want to have the utility in my own application, how can i do? thanks in advance
|
|
|
|
|
Well I guess you need to suppress the auto arrange feature and implement it within your own code so that it looks the same. I have no idea how explorer does this, you might try asking Microsoft.
MVP 2010 - are they mad?
|
|
|
|
|
thanks for your advice
|
|
|
|
|
Hi,
I need to create a process like
LPTSTR szCmdline[] = TEXT("ffmpeg -i " + ofn.lpstrFile + " -r 1 -ss 00:00:10 -vframes 1 -f image2 " + Buffer + "\\Initframe10.bmp");
For this I will be using CreateProcess API but problem is how to convert TCHAR to a LPTSTR lpCommandLine to be passed to CreateProcess?
ofn.lpstrFile (LPTSTR type) is obtained as outcome of GetOpenFileName API Call and Buffer (TCHAR type) is obtained as GetTempPath.
I get compilation errors which I am not able to fix. (I am new to Win32 programming so this may sound naive).
Can someone please help me in fixing the errors?
Thanks
modified on Thursday, January 28, 2010 7:30 AM
|
|
|
|
|
|
Thanks, I have gone over first link and is really informative.
I will go over second link now.
|
|
|
|
|
I'm glad it helped you.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
WideCharToMultiByte() function can be used for conversion. You can also use a _bstr_t class which has an operator char* which can convert unicode to char*
|
|
|
|
|
As well as the other suggestions you should study the basics of arrays and pointers in C and how they are used.
MVP 2010 - are they mad?
|
|
|
|
|
Dear all,
I have a question about Winsock.
My program is a TCP client which manipulates lots of socket connection concurrently.
One socket for each thread.
I use blocking mode at most of time, except creating a new connection to server.
I turn socket into non-blocking mode first, then use select() to check the socket before turning back.
I really don't want to waste time on uncertain blocking timeout and make sure the connection is established in the specific time.
Everything works well when most of server are reachable.
But here comes the question.
If the number of unreachable server increases(more than 5), the rest reachable server will fail on creating connection.
In this case, select() always return 0(means timeout) even though the server is originally reachable.
Here is the portion of my program to create connection:
Open(LPCTSTR addr, int port, DWORD dwTimeout)
{
_socket = 0;
SOCKET theSocket;
int nRet;
LPHOSTENT lpHostEntry;
lpHostEntry = gethostbyname(addr);
if (lpHostEntry == NULL) {
return;
}
theSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (theSocket == INVALID_SOCKET) {
return;
}
unsigned long ul = 1;
nRet = ioctlsocket(theSocket, FIONBIO, (unsigned long*)&ul);
if (nRet == SOCKET_ERROR) {
closesocket(theSocket);
return;
}
SOCKADDR_IN saServer;
saServer.sin_family = AF_INET;
saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
saServer.sin_port = htons(port);
nRet = connect(theSocket,
(LPSOCKADDR)&saServer,
sizeof(struct sockaddr));
if (nRet == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) {
closesocket(theSocket);
return;
}
struct timeval timeout;
fd_set r;
FD_ZERO(&r);
FD_SET(theSocket, &r);
timeout.tv_sec = dwTimeout / 1000;
timeout.tv_usec = (dwTimeout % 1000) * 1000;
nRet = select(0, 0, &r, 0, &timeout);
if (nRet <= 0 ) {
closesocket(theSocket);
return;
}
ul= 0;
nRet = ioctlsocket(theSocket, FIONBIO, (unsigned long*)&ul);
if (nRet == SOCKET_ERROR){
closesocket(theSocket);
return;
}
_socket = theSocket;
}
Is there anything wrong in this code?
Or any constraint on the number of unreachable socket select() concurrently in multithread?
|
|
|
|
|
luderjane wrote: I use blocking mode at most of time, except creating a new connection to server.
I turn socket into non-blocking mode first, then use select() to check the socket before turning back.
Just an idea, you could use a "master thread" to check for timeouts and close socket handles. This should make threads return from blocking connect() calls if necessary... and you can remove the select-timeout-code (untested).
/M
|
|
|
|
|
I wrote a simple testbed to exclude other factor in my program as follows(builds in VC2005, must depends on Ws2_32.lib):
#include <stdio.h>
#include <tchar.h>
#include <Winsock2.h>
typedef struct ServerInfo {
char sIP[32];
int iPort;
DWORD dwTimeout;
BOOL bPrintable;
} ServerInfo, *pServerInfo;
DWORD WINAPI OpenThreadProc(void* lpParam);
void BlockingOpen(pServerInfo pServer);
void NonBlockingOpen(pServerInfo pServer);
int _tmain(int argc, _TCHAR* argv[])
{
int iNumOfURServer = 0;
char sIP[32];
int iPort = 80;
DWORD dwTimeout = 5000;
printf("Number of unreachable server: ");
scanf("%d", &iNumOfURServer);
printf("Reachable server IP: ");
scanf("%s", sIP);
printf("Reachable server port: ");
scanf("%d", &iPort);
printf("Timeout(in millisecond, 0 indicates blocking mode): ");
scanf("%u", &dwTimeout);
WSADATA wsaData;
WORD version = MAKEWORD(2,2);
WSAStartup(version, &wsaData);
pServerInfo ServerArray = new ServerInfo[iNumOfURServer+1];
char sURIP[32];
for (int i = 0; i < iNumOfURServer; i++)
{
sprintf(sURIP, "192.168.1.1%02d", i);
strcpy_s(ServerArray[i].sIP, sURIP);
ServerArray[i].iPort = 3456;
ServerArray[i].dwTimeout = dwTimeout;
ServerArray[i].bPrintable = FALSE;
CreateThread(NULL, 0, OpenThreadProc, &ServerArray[i], 0, NULL);
}
strcpy_s(ServerArray[iNumOfURServer].sIP, sIP);
ServerArray[iNumOfURServer].iPort = iPort;
ServerArray[iNumOfURServer].dwTimeout = dwTimeout;
ServerArray[iNumOfURServer].bPrintable = TRUE;
CreateThread(NULL, 0, OpenThreadProc, &ServerArray[iNumOfURServer], 0, NULL);
scanf("%d", &iPort);
return 0;
}
DWORD WINAPI OpenThreadProc(void* lpParam)
{
pServerInfo pServer = (pServerInfo)lpParam;
while (true)
{
if (pServer->dwTimeout == 0)
{
BlockingOpen(pServer);
}
else
{
NonBlockingOpen(pServer);
}
Sleep(1000);
}
return 0;
}
void BlockingOpen(pServerInfo pServer)
{
SOCKET theSocket;
int nRet;
LPHOSTENT lpHostEntry;
lpHostEntry = gethostbyname(pServer->sIP);
if (lpHostEntry == NULL) {
return;
}
theSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (theSocket == INVALID_SOCKET) {
return;
}
SOCKADDR_IN saServer;
saServer.sin_family = AF_INET;
saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
saServer.sin_port = htons(pServer->iPort);
DWORD dwStartTime = GetTickCount();
nRet = connect(theSocket,
(LPSOCKADDR)&saServer,
sizeof(struct sockaddr));
if (pServer->bPrintable)
{
if (nRet == SOCKET_ERROR)
{
printf("%s:%d blocking open failed takes %d ms\n", pServer->sIP, pServer->iPort,
GetTickCount()-dwStartTime);
}
else
{
printf("%s:%d blocking open successful takes %d ms\n", pServer->sIP, pServer->iPort,
GetTickCount()-dwStartTime);
}
}
closesocket(theSocket);
}
void NonBlockingOpen(pServerInfo pServer)
{
SOCKET theSocket;
int nRet;
LPHOSTENT lpHostEntry;
lpHostEntry = gethostbyname(pServer->sIP);
if (lpHostEntry == NULL) {
return;
}
theSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (theSocket == INVALID_SOCKET) {
return;
}
unsigned long ul = 1;
nRet = ioctlsocket(theSocket, FIONBIO, (unsigned long*)&ul);
if (nRet == SOCKET_ERROR) {
closesocket(theSocket);
return;
}
SOCKADDR_IN saServer;
saServer.sin_family = AF_INET;
saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
saServer.sin_port = htons(pServer->iPort);
nRet = connect(theSocket,
(LPSOCKADDR)&saServer,
sizeof(struct sockaddr));
if (nRet == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) {
closesocket(theSocket);
return;
}
struct timeval timeout;
fd_set r;
FD_ZERO(&r);
FD_SET(theSocket, &r);
timeout.tv_sec = pServer->dwTimeout / 1000;
timeout.tv_usec = (pServer->dwTimeout % 1000) * 1000;
DWORD dwStartTime = GetTickCount();
nRet = select(0, 0, &r, 0, &timeout);
if (pServer->bPrintable)
{
if ( nRet <= 0 )
{
printf("%s:%d non-blocking open failed takes %d ms\n", pServer->sIP, pServer->iPort,
GetTickCount()-dwStartTime);
}
else
{
printf("%s:%d non-blocking open successful takes %d ms\n", pServer->sIP,
pServer->iPort, GetTickCount()-dwStartTime);
}
}
closesocket(theSocket);
}
This testbed simply creates multiple thread which opens a socket repeatedly.
There is only one reachable server and the rest are unreachable.
When I use non-blocking mode(timeout = 5000) and 2 unreachable servers, the open procedure takes 0 ms at most of time.
If I gradually increase the number of unreachable server and keep the same timeout, the open procedure takes more and more time.
In the end(about 16 unreachable servers), the open procedure failed every time(except first 5 times).
Even in blocking mode(timeout = 0), the opening time consuming will increase with the number of unreachable server.
There seems to be a constraint on the socket connection in multithread.
But I cannot google any official document about it...
|
|
|
|
|
hello everybody,
Have gone through some application made in WPF and saw their painting means, drawing of controls, image etc..
They were just amazing.
One thing to be asked is how internally they are managing such fast, flicker free painting.
I tried to achieve such kind of optimized painting in Win32 or MFC applications, but to no success.
Please tell me which all points I am missing. Where I should look for concerned resources.
Thanks for your time.
|
|
|
|
|
|
Hi,
Following on from a question I asked yesterday, I am left with my document being closed and my view being reverted to default (empty) state, but being unable to open the file I was last viewing because the CDocTemplate has the file marked "yesAlreadyOpen".
The file is not open as I read the content of the file and then close it, but a I am uanble to re-view teh file again until I have opened another file and then come back to it.
Is there a flag or reset I need to apply in my OnFileClose function to clear that CDocTemplate flag?
If so, what would would I need to call?
TIA
Tony
|
|
|
|
|
I'm not totally sure of this as I am not a regular user of MFC but you might try looking at RemoveDocument() [^].
MVP 2010 - are they mad?
|
|
|
|
|
Hi again.
I just looked at the code in one of my SDI apps that does not exhibit the problem you're seeing, and I notice in the OnNewDocument function, it uses
if (!CDocument::OnNewDocument())
return FALSE;
Perhaps you can call that when you close your first document and it might reset your flag.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Hi,
In my applcaition the menu is default like
------------------
File. View. Help.
------------------
But i dont want this.I want like
------------------
Applicaitionname
-------------------
To get this,i delete Help menu first and the applcaiton works fine.I delete Statusbar from View,works fine.Then i delete Toolbar from view menu but it shows the assertion error in
atmfc\src\mfc\winmdi.cpp on Line 132.
How can i get my custom menu.
Even i cannot these IDR_MAINFRAME menu and using new IDR_MAINFRAME with my menu.THis also creates same assertion problem.
Pls help me.
Im using VS2008.
Anu
|
|
|
|
|
If you are removing resources then you may have to remove some parts of the source code as well which might be using these deleted resources. May be you can debug and check the call stack to see which call leads to the assertion.
|
|
|
|
|
I'm going to guess that your application is an MFC MDI app. If that's the case, the MFC framework requires that the main menu MUST contain a minimum of 2 items (Normally File and View).
If you debug your application you should get a Debug Assertion. Click on the retry button and it will take you to the line that caused the problem. In my test case, it's on line 132 of winmdi.cpp (MFC source file). Look at the surrounding code and you'll see
int iMenu = pMenu->GetMenuItemCount() - 2;
ASSERT(iMenu >= 0);
In the comments, it tells you how to handle this - override OnCreateClient.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
How to deselect the tree item when clicking outside the tree node (i need to remove focusbox). I used the below code but i failed.
void CEditableView::OnLButtonDown(UINT nFlags, CPoint point)
{
TVHITTESTINFO tvInfo;
CPoint pt;
HTREEITEM m_pOldSel;
GetCursorPos(&pt);
m_treeCtrl.ScreenToClient(&pt);
tvInfo.pt = pt;
UINT uFlags = 1;
UINT flags;
HTREEITEM htItem = m_treeCtrl.HitTest(pt);
if ((htItem != NULL))
{
m_pOldSel = m_treeCtrl.GetSelectedItem();
m_treeCtrl.Select(htItem, TVGN_DROPHILITE);
m_treeCtrl.GetCheck(htItem);
}
else
{
m_treeCtrl.Select(htItem, TVGN_DROPHILITE);
}
CView::OnLButtonDown(nFlags, point);
}
|
|
|
|
|
ratheeshnair123 wrote: else
{
m_treeCtrl.Select(htItem, TVGN_DROPHILITE);
}
Why would you do this if htItem is NULL ?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hi...
I have to some static library files.
I have added the library name in project setting.
but the library files are not working...
any help will be appriciated...
Thanks...
G.Paulraj
|
|
|
|
|