|
Looking again at your example, you have #ifdef UNICODE to type the std::string you want, but then later on you use a char buffer and an explicit cast.
You could use a TCHAR buffer (and no cast), which would give you whatever the compile flags say you're using (UNICODE/wchar ANSI/char). That way you may not need to do conversions at all in many cases, or use conditional conversion for different builds.
Don't despair.
Getting to grips with UNICODE when all you've done before used simple char[] stuff takes time.
Use the debugger to examine memory (not just display strings) so that you can see whether what you have in various places is what you think you should have.
Steve S
Developer for hire
|
|
|
|
|
Thanks for the encouragement , I've been busy last few days but hopefully will give this a shot tonight.
|
|
|
|
|
Hi,
can aynone tell me where can i get a program that involves threads in serial communication...
Pragya
Life is not tomorrow...
|
|
|
|
|
Have a look at Joe Newcomer's article about serial programming here[^].
He describes a way of doing serial communication that I've used myself for several years and it's both fast and reliable.
It's also a good idea to read some of his other articles to get a better understanding of multithreading and message management.
Hope this helps
--
Roger
It's supposed to be hard, otherwise anybody could do it!
|
|
|
|
|
Dear sirs,
Last time I had a problem to align numbers of my list. Someone advise me to change the font and it was ok.
Now I change printer from Laser printer to Dot matrix printer . There is now a new problem, the font is very big when I print from dot matrix printer.But from laser it's good. What font to choice so to align numbers and to printer well from dot matrix or laserjet printer.
this my font i use now:
font.CreateFont(80,0,0,0,FW_DONTCARE,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_MODERN,"Courrier");
dc.SetMapMode(MM_TEXT);
Thanks to all can help me
|
|
|
|
|
I think 80 is big
|
|
|
|
|
Typically you don't hard-code sizes in this way.
You ask the device what size dots it has, and then use that to calculate how big to make the font.
If you have a device context, you can use GetDeviceCaps to retrieve the number of dots in an inch (for vertical and horizontal, coping with the case where dots do not have an aspect ratio of 1:1).
For instance, to get 10 point, you can do this;
int pt = -MulDiv( 10, GetDeviceCaps(dc, LOGPIXELSY), 72);
and that would be the size to use. The different DCs for printers and the screen will give you answers appropriate to the device. Lasers, for instance, might have between 300 and 1200 dpi, while a screen is theoretically 96dpi. Dot matrix printers might be 120 dpi.
By specifying the value as a negative number, the font mapper transforms this value into device units and matches it against the cell height of the available fonts, giving hopefully better results.
In MFC, you can use CreatePointFont or CreatePointFontIndirect and pass in a DC, so that it can correctly calculate the right values for you.
Since the height is in device dots, using the same value for different devices will generally give you odd results.
Steve S
Developer for hire
|
|
|
|
|
Thanks for your reply, I try with mulDiv(8,GetDeviceCaps,LOGPIXELY,72) to detrmine the size.
It's OK ,but I have another problem on dot matrix, the same line is printed twice in the same line in horizontal like:
------------------- -------------------
Why ?
I am using Lx 300
On deskjet and LAser no problem
|
|
|
|
|
How are you deciding where to print?
Again, if you're using MM_TEXT mode, you need to determine Y values correctly for line positioning. You can do this by determining the printing height of a single line, using GetTextMetrics(dc, &tm) where tm is a TEXTMETRIC structure. This will give you tm.tmHeight which is the line height, you may want to add tm.tmExternalLeading to space the lines out more. Or again, to print at positions relative to the page top, if you know the distance in say, inches, you can use MulDiv again to calculate Y values.
If you have
yInch = GetDeviceCaps(dc,LOGPIXELSY);
then 1.1" down would be
MulDiv(720+72, yInch, 720)
Steve S
Developer for hire
|
|
|
|
|
This all my code when I print.
With dot matrix printer I print only the first dc.TextOut but others are not printed.
With LAser or deskjet printer all is printed, no problem here.
What to do ? so to print on dot matrix what I need like:
CFont font;
font.CreateFont(-MulDiv (8, dc.GetDeviceCaps (LOGPIXELSY),72),0,0,0,FW_DONTCARE,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_MODERN,"Courrier");
dc.SetMapMode(MM_TEXT);
CFont* pOldFont = (CFont*) dc.SelectObject(&font);;
dc.GetTextMetrics(&tm);
nHeight = tm.tmHeight + tm.tmExternalLeading ;
hauteur = nHeight; l += 1;
strCommand.Format("|%-50s","Matric." );
dc.TextOut(Info.m_rectDraw.left ,Info.m_rectDraw.top + (l * hauteur) , strCommand);
strCommand.Format("|%-80s","Nom" );
dc.TextOut(Info.m_rectDraw.left + 300 ,Info.m_rectDraw.top + (l * hauteur) , strCommand);
strCommand.Format("|%-50s","Postnom" );
dc.TextOut(Info.m_rectDraw.left + 900 ,Info.m_rectDraw.top + (l * hauteur) , strCommand);
strCommand.Format("|%-50s","Initial" );
dc.TextOut(Info.m_rectDraw.left + 2500 ,Info.m_rectDraw.top + (l * hauteur) , strCommand);
strCommand.Format("|%-50s","Nb.retenu" );
dc.TextOut(Info.m_rectDraw.left + 3000 ,Info.m_rectDraw.top + (l * hauteur) , strCommand);
strCommand.Format("|%-50s","Restant" );
dc.TextOut(Info.m_rectDraw.left + 3500 ,Info.m_rectDraw.top + (l * hauteur) , strCommand);
Urgent
|
|
|
|
|
Thanks for your reply, I try with mulDiv(8,GetDeviceCaps,LOGPIXELY,72) to detrmine the size.
It's OK ,but I have another problem on dot matrix, the same line is printed twice in the same line in horizontal like:
------------------- -------------------
Why ?
I am using Lx 300
On deskjet and LAser no problem
|
|
|
|
|
Hi all,
some time ago, i had to write a program which starts other executeables (i did this with CreateProcess). Not a single process started was depending on the termination of another started one. Since then, the requirements changed and i have to include the execution of processes which depend on the termination of other processes. as i am not a programmer in general, i have no idea how this could be done. could someone please guide me how to do this?
CreateProcess A.exe --> A.exe is working without a dependency
CreateProcess B.exe --> Should be started when A.exe terminates
CreateProcess C.exe --> Should be started when B.exe terminates
Thanks in advance,
nmx
|
|
|
|
|
U can use the handle returned by CreateProcess as a parameter to WaitForSingleObject(..).. This will make your process wait for the process to exit and then continue.
<br />
In ur scenario it will be,<br />
HANDLE hprocessa = CreateProcess("a.exe", .. other parameters);<br />
WaitForSingleObject( hprocessa, INFINITE );<br />
HANDLE hprocessb = CreateProcess("b.exe", .. other parameters);<br />
WaitForSingleObject( hprocessb, INFINITE );<br />
CreateProcess("c.exe", .. other parameters);<br />
Chao!
|
|
|
|
|
Ciao nutkase. Thanks for your answer.
This is exactly the way i do it right now, but this is way too unflexbile. Lets say I want to start another Process D while Process A is running. Process B and C are waiting for the termination of Process A. If I use WaitForSingleObject(A, INFINITE) on Process A, i won't be able to execute another process (Process D) at the same time.
What i think about is having Events for the termination of a process.
Greets, nmx
|
|
|
|
|
Well, its just the matter of syncronization now. U will have to make a compromise on flexibility at some point. Events is a gr8 idea. best of luck
Unless lions have their historians, the tales of hunt will always glorify the hunters!
|
|
|
|
|
|
Your sig is looking a lot better ;0)
|
|
|
|
|
Thanks
|
|
|
|
|
Ok guys, i solved the problem using the processes HANDLE and PROCESS_INFORMATION
<br />
PROCESS_INFORMATION piProcessA;<br />
...<br />
DWORD dwExitCode;<br />
GetExitCodeProcess(piProcessA, &dwExitCode);<br />
while (dwExitCode == STILL_ACTIVE)<br />
{<br />
GetExitCodeProcess(process, &dwExitCode);<br />
Sleep(500);<br />
}<br />
Next challenge: How could it be done to have dynamic process dependencies. The configuration should be made in a header file (f.e. via #define)
There are a few processes: A,B,C and D
B depends on A and C --> #define B_DEPS "A,C"
Any ideas?
Ciao, nmx
|
|
|
|
|
Hi,
I want minimize,maximize,close icon in child window.How can i do this?
I tried lot of things but failed.
The problem is..I got these icons in my child window, when i minimized it has gone somewhere, so i cudn't maximize the window again..and also when i click restoreup in that three icon(middle one) it didn't minimized to small size..nothing get changed but three icons will disappeared.
One morething these three icons didnot display when the application opens, when i switch to another window in the same application then come back to this window then the three icons appear,
What can i do?
My requiremnt is same as vc++ coding environment(i.e., we can minimize,close and maximize the text editor in our vc++ complier)I need the same functionality..Pls help me out?
Anu
|
|
|
|
|
hi all i had made application that send() recv() through winsock API's not the MFC classes and winsock controll.
when i send one time it works fine and receives well but when i send more than once at a time
i.e
if((send(conn,"11",strlen("13"),0))==2)<br />
AfxMessageBox("11");<br />
if((send(conn,"12",strlen("13"),0))==2)<br />
AfxMessageBox("11");<br />
if((send(conn,"13",strlen("13"),0))==2)<br />
AfxMessageBox("13");<br />
and then closing the sockets<br />
other side cannot receive anything i mean it receive 0 bytes.i m using the receive side in for loop here is the code.
for (int i=0;i<3;i++)<br />
{<br />
int numbytes;<br />
char buf[5];<br />
if((numbytes=recv(new_fd,buf,strlen(buf),0))==0)<br />
AfxMessageBox("Conn Forcefully Rejected Receive Error");<br />
else<br />
{<br />
buf[(numbytes+1)] = '\0';<br />
AfxMessageBox(buf);<br />
} <br />
} and then it closes sockets also.
but it shows the conn forefully rejected receive error.
i dont why it is this.
Tasleem Arif
|
|
|
|
|
you just mention length '2'.
recv(new_fd,buf,strlen(buf),0)
instead use this
recv(new_fd,buf,2,0)
|
|
|
|
|
thanks it did worked.
Tasleem Arif
|
|
|
|
|
It seems that you find your answer but see an article about transfer file with socket on codeproject maybe it helpful for you.
|
|
|
|
|
In my opinion there could be many reasons for this code not working. The most important and in my opinion the one with the brightest chances is the connection not properly set up. post the full code then may be anybody would be able to help!
Unless lions have their historians, the tales of hunt will always glorify the hunters!
|
|
|
|
|