|
VCProgrammer wrote: my first thread should not resume its working untill thread2 finishes it work
So why are you using threads? This is serial processing not parallel, so using threads does not provide any advantage.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
VCProgrammer wrote: Can i use CEvent for this???
yes you can! however am agree with richard!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
I have a Delphi application which Creates a shared memory uses CreateFileMapping, OpenFileMapping, MapViewOfFile functions.
Now I wanted to share the same memory for my MFC application. I used the OpenFileMapping, MapViewOfFile functions.
I created a structure exactly same in size as the Delphi application and mapped the structure object.
sample code:
HANDLE hMapObject2;
hMapObject2 = OpenFileMapping( FILE_MAP_ALL_ACCESS, FALSE, "PP101U3_SHARED");
if( !hMapObject2 )
{
AfxMessageBox("Failed to open Simpack DataBase");
return( 0 );
}
Simpack = ( struct SIMPACKDB *) MapViewOfFile( hMapObject2, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
if( !Simpack )
{
AfxMessageBox("Failed to create Simpack File Map View");
return(0);
}
Esim->SPV1 = Simpack->SP_Z;
I am able to read the values exactly correct for all the member variables in the structure.
But when I try to write value in the shared memory, its not changing. It shows the previous value immediately.
The value of Simpack->SP_Z[15] is 0.5010 as read
from the shared memory which is set by the Delphi application.
When I set or write the value of the same variable to the shared memory using the code:
Simpack->SP_Z[15] = 0.6123;it still shows the previous value 0.5010. When I change the same variables value in the Delphi application it changes and the changed value can be read here in the MFC application.
Please help me how to write the values in the shared memory. Is there anything wrong in the code?
|
|
|
|
|
Please put your code between <pre> tags to make it easy to read.
What data type is the Simpack->SP_Z array?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
My Code:
hMapObject2 = OpenFileMapping( FILE_MAP_ALL_ACCESS, FALSE, "PP101U3_SHARED");
if( !hMapObject2 )
{
AfxMessageBox("Failed to open Simpack DataBase");
return( 0 );
}
Simpack = ( struct SIMPACKDB *) MapViewOfFile( hMapObject2, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
if( !Simpack )
{
AfxMessageBox("Failed to create Simpack File Map View");
return(0);
}
Simpack->SP_Z = 0.6212;
The member sp_z is of type float
|
|
|
|
|
Are you getting any Access violations when you try to set the value in the MFC program?
You might want to use the VirtualQuery function to investigate if the view you have mapped is as you expect.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I think it would have been mapped because I am able to read the values from the delphi application which is creating the shared memory. And the values are also updated in the MFC application when the value is changed in the Delphi application.
I checked till the last member variable in the entire structure.
|
|
|
|
|
I know, but I suggested using VirtualQuery because there might be something unusual about the access permissions on the pages of memory in the mapping.
Can you show the code that creates the file mapping?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Delphi Code:
while not bDone do begin
s_hMemFile := CreateFileMapping( $FFFFFFFF, Nil, PAGE_READWRITE,
0, cbSize, @sTemp[1] );
idErr := GetLastError;
if ( idErr <> 0 ) and { => Function Failed }
( idErr <> ERROR_ALREADY_EXISTS ) then begin
CloseHandle( s_hMemFile );
s_hMemFile := 0;
inc( iRetryCount );
// Map the File to Memory
if bDone or not FGenerateName then
Data := MapViewOfFile( s_hMemFile, FILE_MAP_ALL_ACCESS, 0, 0, ENTIRE_FILE )
else begin
if FGenerateName and (Data <> Nil) then begin
try
UnMapViewOfFile( Data );
finally
Data := Nil;
end; { try }
end; { if }
end; { if then else }
|
|
|
|
|
I don't see a problem there, however, I have to ask about the code you use to set the value(s) in the MFC program.
In your first post you showed SP_Z being used with an index, such as SP_Z[15] , and in the next post, you showed that you're setting it without an index. Is this an array or not an array?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I am sorry. The first one is correct. Its an array.
|
|
|
|
|
hello guys... I am trying to write this small chat application. Here, I want the user name, colored differently than his/her message. Now I had a look at the CHARFORMAT structure but don't know which of the value needs to be set, in order to change color of my user name only. Here is what it looks like
typedef struct _charformat {
UINT cbSize;
DWORD dwMask;
DWORD dwEffects;
LONG yHeight;
LONG yOffset;
COLORREF crTextColor;
BYTE bCharSet;
BYTE bPitchAndFamily;
TCHAR szFaceName[LF_FACESIZE];
} CHARFORMAT;
Here is definition for my function which adds the message to the rich edit control
void CConnectUserDlg::AddMessage(LPCTSTR strUser, LPCTSTR strMessage)
{
CString strCompleteMsg;
strCompleteMsg.Format("%s:\t%s\n", strUser, strMessage);
int nLength;
nLength = m_richMessages.GetTextLength();
m_richMessages.SetSel(nLength, nLength);
m_richMessages.ReplaceSel(strCompleteMsg);
m_richMessages.SetSel(-1, 0);
GetDlgItem(IDC_EDIT)->SetWindowText("");
GetDlgItem(IDC_EDIT)->SetFocus();
}
Thanks for any pointers.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
What have you tried so far? Did you examine the docs for the CHARFORMAT structure: CHARFORMAT[^]
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
oops..I forgot to paste the following code in the function body. Here is what I am trying at the top of the provided function body in OP.
CHARFORMAT Cfm;
m_richMessages.GetSelectionCharFormat(Cfm);
Cfm.cbSize = sizeof(CHARFORMAT);
Cfm.dwMask = CFM_ITALIC;
Cfm.dwEffects ^= CFE_ITALIC;
Cfm.crTextColor = RGB(0,255,0);
m_richMessages.SetSelectionCharFormat(Cfm);
1 - Now first, this code colors the entire rich edit box. But I want to change the color of the user name only, not his/her message.
2 - To surprise you, this code italicizes the text in the rich edit control but does not change the color of it.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
Well, one thing I see is that you forgot to add the CFM_COLOR flag to the mask:
Cfm.dwMask = CFM_ITALIC | CFM_COLOR;
This flag tells the function to set the color based upon the crTextColor member of the structure.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Thanks but how do I select UserName and change its color? Thanks for any input on this.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
When you're setting the text of the User Name and message, you must keep track of what character positions represent the user name, and then use the EM_EXSETSEL message to select those characters.
Once those characters are selected, then you can use the code you have shown in order to set the formatting.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Simple, Take the Name in CString or TCHAR Array, In OnPaint, or OnDraw Change the Text Color...
|
|
|
|
|
COLORREF crTextColor;
I would assume this field used with the EM_SETCHARFORMAT [^] message; a quick test should confirm it.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
hi,
i have developed a GUI in MFC vs2008. now i wanted to get GPS coordinates of different locations using offline map. the idea is to have a map in my GUI dialog, and by clicking on specific area inside the map would assign the coordinates of that area to specific variable in my GUI code.
now the problem is how to do it? where to start? and if i wanted to use Falcon-view or offline Google map, than what would i need to do?
Regards
Jawad
modified 23-May-12 6:18am.
|
|
|
|
|
jawadali477 wrote: where to start?
Looking at some of these links[^] is as good a place as any.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
I am trying to write a virtual chat system, in which you can ask the computer any question you want, and then it will give out the correct answer. My only problem is getting the code to loop back to the start, thus allowing the user to input another question, continuously getting the answer, until the user specifies to stop.
#include <iostream>
#include <string>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include <tchar.h>
using namespace std;
int Australia();
int main()
{
cout << "Welcome to Virtual Chat, ask any question you want.\n";
int Keep = 1;
string Input;
while (Keep == 1)
{
cin >> Input;
if (Input == "What is your name?" || "what is your name?" || "What is your name");
{
cout << "I am a computer, I do not have a Name";
break;
}
continue;
}
char f;
cin >> f;
return 0;
}
Thankyou for the help.
|
|
|
|
|
It looks your code is already doing it: the while loop accepts user input again and again.
Am I missing something?
Veni, vidi, vici.
|
|
|
|
|
Not really, at the moment it only accepts one input then stops.
|
|
|
|
|
Ah, OK. That is because the if condition is wrong, it should be
if (Input.compare("What is your name?")==0 || Input.compare("what is your name?")==0 || Input.compare("What is your name")==0)
note there is no trailing semicolon ( ';' ).
Veni, vidi, vici.
|
|
|
|