|
If you set focus to Notepad then focus will remain there until you move it to another window. What's the problem?
The best things in life are not things.
|
|
|
|
|
|
Rajesh has supplied a good article about what you need, but this message[^] is specifically how to avoid the whole focus issue. It's all C#, but hopefully you can 'tranlsate' to C++.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
That's an excellent post you've pin pointed. Have a vote.
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
Thanks Rajesh. You got me started with that article link.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
You're welcome. And because you pointed him to the C# code, I advised (see my new reply to the OP below) on how to do that in C++.
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
In addition to what I suggested previously, Chris give you a very valuable suggestion. The message he pin pointed is in C#.
If you're using MFC, then you could see the example in this page: Changing the styles of a window created in MFC[^]. The list of available extended window styles is here: Extended Window Styles[^], and you should be specifically interested in WS_EX_TOOLWINDOW and WS_EX_NOACTIVATE .
If you're using Win32 programming, then you could set the style of the window while making a call to CreateWindow[^]. Pay attention to the third parameter, which is DWORD dwStyle .
Hope that helps.
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
Hi ALL,
How can i simulataneously read and write the values from other process.
I want to use Memory Mapped,but not clear with the concept ,how to write and read using it.
I have two procees,
1)where in from one process i get values from hardware,
example : LateralX=10, LongitudinalY=12 ... etc
2) In the second process i display the values in GUI.
Each time the hardware moves the values changes and reflects in GUI
Now presently i am using global variables to get the values.
How can i do the same with Memory Mapped file.
can someone suggest me any idea,how can i do this or any sample example..
Thanks
Sharan
|
|
|
|
|
|
Thanks a lot for the link given,it is very helpfull
If i want to write more then one value in one process.
How can i do it.
Presently now this is a msg i am writing into
Example
TCHAR szMsg[]=TEXT("Message from first process.");
CopyMemory((PVOID)pBuf, szMsg, (_tcslen(szMsg) * sizeof(TCHAR)));
This is how i am writing the message to Memory.
How can i do it for more then one message(multiple values)
In process2.cpp
Same way can i read more then one value from the other process
hMapFile = OpenFileMapping(
FILE_MAP_ALL_ACCESS,
FALSE,
szName);
pBuf = (LPTSTR) MapViewOfFile(hMapFile,
FILE_MAP_ALL_ACCESS,
0,
0,
BUF_SIZE);
MessageBox(NULL, pBuf, TEXT("Process2"), MB_OK);
Here i am reading the value from 1st process,how can i read multiple values
Thanks
Sharan
|
|
|
|
|
Let's just pause for a second, and think about it..
Your first process takes some data (in this case, a character based string) and copies it into a buffer.
Your second process reads from that buffer and displays this info as a string. The second process has no inherent knowledge of the data structure of the shared memory.
This much is no different to any normal file - it is up to the definer of the data to decide how it will be stored, and as a consequence, how it will be retrieved.
So, instead of blindly copying the message to the buffer, you may decide to use the first 4 bytes (for example) of the buffer to store the number of messages being passed. You may then write your messages 1 after another - remembering to make sure you have a null terminator between each string.
Here's some code that will demonstrate the concept:
#include <stdio.h>
#include <stdlib.h>
#define buffSize 2048
char buffer[buffSize];
void initBuffer()
{
memset((PVOID)buffer, 0, sizeof(char) * buffSize);
}
int addMsg(char *msg)
{
long msgCount, curMsgIndex, curMsgLen;
char *newStrPos;
memcpy((PVOID)&msgCount, buffer, sizeof(long));
newStrPos = (char*) (long)&buffer + sizeof(long);
for (curMsgIndex=0; curMsgIndex<msgCount; curMsgIndex++)
{
curMsgLen = strlen(newStrPos);
newStrPos += curMsgLen + 1;
}
{
printf("adding message\n");
strcpy(newStrPos, msg);
msgCount++;
memcpy((PVOID)buffer, &msgCount, sizeof(long));
}
}
void printMessages()
{
long msgCount, curMsgNum;
char *curMsg;
memcpy(&msgCount, buffer, sizeof(long));
curMsg = (char*)(long)&buffer + sizeof(long);
for (curMsgNum=0; curMsgNum<msgCount;curMsgNum++)
{
printf("%s\n", curMsg);
curMsg += strlen(curMsg) + 1;
}
}
int main()
{
initBuffer();
addMsg("This is msg 1");
addMsg("This is msg 2");
printMessages();
return 0;
}
S.
|
|
|
|
|
Hi,
Thanks for your reply,
If i am not wrong,the example you gave is within a single process,
How can i send to other process.
In the give link
"http://msdn.microsoft.com/en-us/library/aa366551(v=vs.85).aspx"
we have two process running,wherein we are sending data from one process to the other
In the example we are sending the below message
TCHAR szMsg[]=TEXT("Message from first process.");
"Message from first process." to second process,
How can i send more then one message
Thanks
Sharan
|
|
|
|
|
Hi, thanks for the mental exercise.
Er, sorry about that - I didn't bother making a pair of apps because it was around 3am, and I had thought that the next step would be obvious and unnecessary.
Wouldn't you just put the initBuffer & addMsg functions into the first program, and the printMessages function into the second program?? It's no different (in concept) to using a file to pass information from one program to another. 'Write' functions go in program (a), 'read' functions go in program (b).
I dunno, but it seems like it need not be more complicated than that...
|
|
|
|
|
Hi,
I tried splitting the functions as you said,but some junk values is coming in second process.
This is what i am trying to do.
In Process 1
// Procees1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <tchar.h>
#define BUF_SIZE 2048
char buffer[BUF_SIZE];
TCHAR szName[]=TEXT("Global\\MyFileMappingObject");
TCHAR szMsg[]=TEXT(" Read Values from first process.");
LPCTSTR pBuf;
int addMsg(char *msg)
{
long msgCount, curMsgIndex, curMsgLen;
char *newStrPos;
memcpy((PVOID)&msgCount, buffer, sizeof(long));
newStrPos = (char*) (long)&buffer + sizeof(long);
for (curMsgIndex=0; curMsgIndex<msgCount; curMsgIndex++)
{
curMsgLen = strlen(newStrPos);
newStrPos += curMsgLen + 1;
}
{
printf("adding message\n");
strcpy(newStrPos, msg);
CopyMemory((PVOID)pBuf, msg, (_tcslen(szMsg) * sizeof(TCHAR)));
msgCount++;
memcpy((PVOID)buffer, &msgCount, sizeof(long));
}
return 0;
}
int _tmain()
{
HANDLE hMapFile1;
hMapFile1 = CreateFileMapping(
INVALID_HANDLE_VALUE, // use paging file
NULL, // default security
PAGE_READWRITE, // read/write access
0, // maximum object size (high-order DWORD)
BUF_SIZE, // maximum object size (low-order DWORD)
szName); // name of mapping object
if (hMapFile1 == NULL)
{
_tprintf(TEXT("Could not create file mapping object (%d).\n"),
GetLastError());
return 1;
}
pBuf = (LPTSTR) MapViewOfFile(hMapFile1, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
BUF_SIZE);
if (pBuf == NULL)
{
_tprintf(TEXT("Could not map view of file (%d).\n"),
GetLastError());
CloseHandle(hMapFile1);
return 1;
}
memset((PVOID)buffer, 0, sizeof(char) * BUF_SIZE);
addMsg("This is msg 1");
addMsg("This is msg 2");
_getch();
UnmapViewOfFile(pBuf);
CloseHandle(hMapFile1);
return 0;
}
In Process2
// Process2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <tchar.h>
#pragma comment(lib, "user32.lib")
/*int main(int argc, char* argv[])
{
printf("Hello World!\n");
return 0;
}*/
#define BUF_SIZE 256
TCHAR szName1[]=TEXT("Global\\MyFileMappingObject");
int _tmain()
{
HANDLE hMapFile;
LPCTSTR pBuf;
hMapFile = OpenFileMapping(
FILE_MAP_ALL_ACCESS, // read/write access
FALSE, // do not inherit the name
szName1); // name of mapping object
if (hMapFile == NULL)
{
_tprintf(TEXT("Could not open file mapping object (%d).\n"),
GetLastError());
return 1;
}
pBuf = (LPTSTR) MapViewOfFile(hMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
BUF_SIZE);
if (pBuf == NULL)
{
_tprintf(TEXT("Could not map view of file (%d).\n"),
GetLastError());
CloseHandle(hMapFile);
return 1;
}
//MessageBox(NULL, pBuf, TEXT("Process2"), MB_OK);
long msgCount, curMsgNum;
char *curMsg;
memcpy(&msgCount, pBuf, sizeof(long));
curMsg = (char*)(long)&pBuf + sizeof(long);
for (curMsgNum=0; curMsgNum<msgCount;curMsgNum++)
{
printf("%s\n", curMsg);
curMsg += strlen(curMsg) + 1;
}
UnmapViewOfFile(pBuf);
CloseHandle(hMapFile);
return 0;
}
I dont know where i am wrong,Please can you help me where i am going wrong
Thanks
Sharan
|
|
|
|
|
Hullo again.
I've looked at your code and noticed that when referring to memory, there seemed to be mixed references to the buffer that was shared, and the one that was locally defined.
I've gone through and made a number of changes, sorry I can't think of them all right now. Sorry I also made it non-unicode. I've little experience with it and have no impulse to further that just now.
Try this: (yup, tested and working )
Hope your mileage is better than last time..
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <tchar.h>
#define BUF_SIZE 2048
char *szName = "Global\MyFileMappingObject";
char *pSharedBuffer;
int addMsg(char *msg, char *buffer)
{
long msgCount, curMsgIndex, curMsgLen;
char *newStrPos;
memcpy(&msgCount, buffer, sizeof(long));
newStrPos = (char*) (long)buffer + sizeof(long);
for (curMsgIndex=0; curMsgIndex<msgCount; curMsgIndex++)
{
curMsgLen = strlen(newStrPos);
newStrPos += curMsgLen + 1;
}
strcpy(newStrPos, msg);
msgCount++;
memcpy(buffer, &msgCount, sizeof(long));
return 0;
}
int main()
{
HANDLE handleMappedFile;
LPVOID lpMsgBuf;
handleMappedFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, HIWORD(BUF_SIZE), LOWORD(BUF_SIZE), szName);
if (handleMappedFile == NULL)
{
printf("Could not create file mapping object.\n");
LocalFree( lpMsgBuf );
return 1;
}
pSharedBuffer = (char*)MapViewOfFile(handleMappedFile, FILE_MAP_ALL_ACCESS, 0, 0, BUF_SIZE);
if (pSharedBuffer == NULL)
{
printf("Could not map view of file.\n");
CloseHandle(handleMappedFile);
return 1;
}
memset((PVOID)pSharedBuffer, 0, sizeof(char) * BUF_SIZE);
addMsg("This is msg 1", pSharedBuffer);
addMsg("This is msg 2", pSharedBuffer);
addMsg("This is msg 3", pSharedBuffer);
getch();
UnmapViewOfFile(pSharedBuffer);
printf("File unmapped\n");
CloseHandle(handleMappedFile);
printf("handle closed.\n");
return 0;
}
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <tchar.h>
#define BUF_SIZE 2048
char *szName1= "Global\MyFileMappingObject";
char *pSharedBuffer;
int main()
{
HANDLE hMappedFile;
hMappedFile = OpenFileMapping(ILE_MAP_ALL_ACCESS, FALSE, szName1);
if (hMappedFile == NULL)
{
printf("Could not open file mapping object (%d).\n",GetLastError());
return 1;
}
pSharedBuffer = MapViewOfFile(hMappedFile, FILE_MAP_ALL_ACCESS, 0, 0, BUF_SIZE);
if (pSharedBuffer == NULL)
{
printf("Could not map view of file (%d).\n", GetLastError());
CloseHandle(hMappedFile);
return 1;
}
long msgCount, curMsgNum;
char *curMsg;
memcpy(&msgCount, pSharedBuffer, sizeof(long));
printf("---- Messages retrieved: %d ----\n", msgCount);
curMsg = (char*)pSharedBuffer + sizeof(long);
for (curMsgNum=0; curMsgNum<msgCount; curMsgNum++)
{
printf("msg(%d): %s\n", curMsgNum, curMsg);
curMsg += strlen(curMsg) + 1;
}
UnmapViewOfFile(pSharedBuffer);
CloseHandle(hMappedFile);
getch();
return 0;
}
|
|
|
|
|
Thanks a lott,its working fine
Regards
Sharan
|
|
|
|
|
Hi,
Can we share the data simulatenously from process1 and process2,as well as process2 and process1.
means write and read data to and from another process??
Thanks
Sharan
|
|
|
|
|
Hi all,
I detected some diferences in my program results between Release and Debug versions. After some research I realized that some floating point optimizations are causing those differences. I have solved the problem by using fenv_access pragma for disabling some optimizations for some critical methods.
Thinking about it, I realized that, probably, is better to use fp:strict model instead of fp:precise in my program because of its characteristics but I am worried about performance. I have tried to find some information about performance issues of fp:strict or the differences in performance between precise and strict model but I have find very little information. Anybody knwos anything about this??
Thanks in advance.
|
|
|
|
|
Is it possible to receive an event in an MFC program running on the client when a file on a web server is modified?
I want to do this without .net or any special software, only HTML, PHP and javascript. I plan to host the web on a shared host and the code should work out-of-the-box on any web host which supports php programming.
If this is not possible, would it be possible for javascript (I don't know javascript) to inform the MFC program running on the client when it modifies the file (socket communication?)?.
I know how to poll a php page from MFC, but polling a web page every second to evaluate if a file has changed is certainly not the way to go.
Since I'm totally new to all this, code snippets would be very much appreciated.
Thank you
|
|
|
|
|
A tcp socket connection is ideal because the connection is always there. But in real life it's rarely feasible in most internet situations because of networking administration issues (can't have open ports, firewall configurations, etc.).
However, HTTP on standard port 80 works for pretty much anyone with internet access. But HTTP is request/reply so polling is generally used. Take a look at this document to see a description of how MS implemented the Polling Duplex HTTP support for Silverlight. Silverlight 2 WCF Polling Duplex Support – Part 1: Architecture[^] Maybe some ideas there...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
If I understand you and the linked article correctly, there is no real life possibility to use sockets. Setting up port-forwarding in modems is definitely out of question.
My only option seems, therefore, to be to use CHttpFile and send defined requests to a php web page every second (I need almost real-time performance) and read the web contents returned.
If this is the only way to do reliable duplex communications, so be it. To me it seems a terrible waste of bandwidth and I would have thaught that better methods existed.
Unless someone tells me that I have completely misunderstood the answer given, I will go ahead and experiment with CHttpFile and co.
|
|
|
|
|
The bandwidth issue isn't that bad. The implementation described at the link uses the reply timeout before sending another request, so if no data is available for the client, polling requests are only sent once every 60 seconds by default. And the requests are very small. Viewing a webpage can cause hundreds of requests in a very short period of time (like a second), so one little request a minute is nothing.
I personally would use (and have used) WinHTTP[^], but CHttpFile may be fine for your needs.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am Using the VC++ coding,I don't know how to sort the list of files in a folder.Can anybody know please give me the solution with syntax also....
Thanks,
manojkumar.U
|
|
|
|
|
What do you mean exactly by "sort the list of files in a folder" ? There is no such thing as that. You can view them sorted in the explorer but they still are not "sorted" on your hard disk.
What are you trying to achieve ? Do you want to modify the sort order for a specific folder within the explorer ? Do you want to retrieve a sorted list of files to use within your application ?
Which kind of sorting do you need ?
Well, you really need to describe your problem in more details...
|
|
|
|
|
This control[^] should help you get what you want.
The best things in life are not things.
|
|
|
|
|