|
zizzzz wrote: Cstring rvalue
switch (rvalue)
{
You cannot create a switch statement using strings. You need to do if-else if-else for this.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Have you tried:
switch((LPCTSTR)rvalue)
{
}
or
switch(rvalue.GetBuffer(rvalue.GetLength()))
{
}
Best,
Jun
|
|
|
|
|
This will only compare the value of the pointer, not the contents of the string. Thus it won't work at all (even if this compiles fine).
|
|
|
|
|
Jun Du wrote: switch((LPCTSTR)rvalue)
{
//blablabla...
}
Bad!
Jun Du wrote: switch(rvalue.GetBuffer(rvalue.GetLength()))
{
//blablabla...
}
WORSE!!!!
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I seem to remember that I could get something similar to work. Probably I am completely wrong here. Everybody says we cannot directly use CString in switch. Thank Cedric and Zac for pointing this out.
Best,
Jun
|
|
|
|
|
can you verify with me this syntax
if (rvalue=="0")AfxMessageBox("Communication Error");
else if (rvalue=="A")AfxMessageBox("Checksum Error");
else if (rvalue=="H")AfxMessageBox("Data Length Error");
else m_baud.AddString(rvalue);
is it correct?
zzzzzzzz
|
|
|
|
|
|
It is correct, though I loathe that formatting
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Ahh come on, Zac. You know how the compiler hates messing with all of those superfluous spaces and carriage returns! They need to be removed for better performance.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I'm just waiting for someone to post code like this:
if (rvalue=="0")AfxMessageBox("Communication Error");else if (rvalue=="A")AfxMessageBox("Checksum Error");else if (rvalue=="H")AfxMessageBox("Data Length Error");else m_baud.AddString(rvalue);
And ask for help finding problems with it ...
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I wish you had waited instead of posting it yourself
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
zizzzz wrote: Cstring rvalue
switch (rvalue)
This won't work unless rvalue is an integral type or of a class type for which there is an unambiguous conversion to integral type.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
case uses ordinal values, try a single character from the string such as '0', 'Z' etc..
Elaine
|
|
|
|
|
Trollslayer wrote: case uses ordinal values...
Did you mean integral here?
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
hi.
i would like to get the content (graphics) of a window whose HWND i have, but it is not visible (meaning, visible as in WM_VISIBLE, but not to the human eye i.e. concealed by other windows).
And i would like to do this without bringing the window to the front, as this takes too much time.
i tried the following:
<pre>
HDC hdcWind = GetDC(windowHWND);
HDC hdcComp = CreateCompatibleDC(hdcWind);
HBITMAP hbmWind = CreateCompatibleBitmap(hdcWind,
GetDeviceCaps(hdcWind, HORZRES),
GetDeviceCaps(hdcWind, VERTRES));
SelectObject(hdcComp,hbmWind);
BitBlt(hdcComp,0,0,100,100,hdcWind,0,0,SRCCOPY);
</pre>
Then to display the result i did:
<pre>
HDC hdcScreen = CreateDC("DISPLAY",NULL,NULL,NULL);
BitBlt(hdcScreen,0,0,100,100,hdcComp,0,0);
ReleaseDC(hdcWind);
</pre>
It draws an image onto the left top corner of my screen. The size is correct and the top left corner of the drawing is even taken from the correct point (top left corner of the windowHWND !!). But the contents of the drawing is the background at the moment of execution. As if he gets the window, uses its position to take the "picture", but the window is "invisible" and gets only the background.
Every and any help will be much appreciated.
Thank you
imran
|
|
|
|
|
I am not sure but try sending the WM_PRINT meesage to the window.
In ur case pass the hdcComp as the wparam of the message. i think u will get the screenshot of the window in that dc.
nave
|
|
|
|
|
I tried it just now. But the drawing is all completely black. It doesnt even print the NONCLIENT area.
I tried:
<pre>
SendMessage(hWnd, WM_PRINT, (WPARAM) hDCMem, PRF_CLIENT | PRF_NONCLIENT);
</pre>
and
<pre>
SendMessage(hWnd, WM_PRINT, (WPARAM) hDCMem, PRF_CLIENT | PRF_ERASEBKGND | PRF_NONCLIENT);
</pre>
Shouldnt it always be able to print the title bar etc. no matter which app. made the window? What does that mean, if everything is black.
thanks again
imran
|
|
|
|
|
i tried it here, Its just working fine. see the code below( sorry that its mfc )
ShowWindow( FALSE );<br />
CWindowDC dc(this);<br />
CRect WindRect;<br />
GetWindowRect( WindRect );<br />
m_MemDC.CreateCompatibleDC( &dc );<br />
m_bmp.CreateCompatibleBitmap( &dc, WindRect.Width(), WindRect.Height());<br />
m_MemDC.SelectObject( &m_bmp );<br />
SendMessage( WM_PRINT, (WPARAM)m_MemDC.m_hDC,PRF_CLIENT | PRF_NONCLIENT|PRF_ERASEBKGND);<br />
CWindowDC Desk(0);<br />
Desk.BitBlt( 0,0,WindRect.Width(), WindRect.Height(), & m_MemDC,0,0,SRCCOPY );
The above code paints the window to the desktop.
nave
|
|
|
|
|
hmmm....sorry to ask you this, but i am really a beginner at windows programming
-my ShowWindow doesnt just take 1 parameter
-what is m_MemDC ?(what kind of object, DC or what?)
-must i work with CWindowDC ? how do i create a CWindowDC with a HWND ? i dont have a 'this' in this program
thanks alot
imran
|
|
|
|
|
hi..
i have tried alot the whole day, with no success
basically, using the SendMessage function, gives me a completely black image. always. bitblt works, but only if window is visible.
i copied your code, got it working (i know what mfc, CWindowDC and all that is now ).
but still the returned image is all black.
have you got any clue what the problem could be?
thanks alot
imran
|
|
|
|
|
here is a non-mfc version of the code. this code will draw the image to the desktop.If u have any other windows in the desktop plz minimize them before testing this code.
::ShowWindow( m_hWnd, FALSE );<br />
HDC hdc = ::GetDC(m_hWnd);<br />
RECT WindRect;<br />
::GetWindowRect( m_hWnd, &WindRect );<br />
HDC MemDC = ::CreateCompatibleDC( hdc );<br />
HBITMAP bmp = CreateCompatibleBitmap( hdc, WindRect.right - WindRect.left, WindRect.bottom- WindRect.top );<br />
SelectObject( MemDC,bmp );<br />
SendMessage( WM_PRINT, (WPARAM)MemDC,PRF_CLIENT | PRF_NONCLIENT|PRF_ERASEBKGND);<br />
HDC DeskDc = ::GetDC(0);<br />
BitBlt( DeskDc,0,0,WindRect.right - WindRect.left, WindRect.bottom- WindRect.top , MemDC,0,0,SRCCOPY );
astabasta wrote: but still the returned image is all black.
how do u verify the image in the dc? I mean how u came in to conclusion that the images is black?
nave
|
|
|
|
|
hi nave
thanks for the reply again
your code goes exactly the same thing too. actually almost exactly. basically it draws a black rectangle onto my screen excatly the size of the window in question. usually the whole rectangle was completely black. with your code, there's a 'hole' in the black rectangle, where i can see the desktop background and around it all is black.
any ideas?
cheers mate
imran
|
|
|
|
|
give me ur email id. I will send a sample..
nave
|
|
|
|
|
hey i found out the function PrintWindow() will work in your case.
nave
|
|
|
|
|
astabasta wrote: i would like to get the content (graphics) of a window whose HWND i have, but it is not visible (meaning, visible as in WM_VISIBLE, but not to the human eye i.e. concealed by other windows).
The screen does not have "thickness". When Window A is covered by Window B on the screen, you won't be able to get the portion of A right behinde B. If you really want it, you have to maintain a double buffer (memory DC) for each window. Then, you may retrieve any portion of a window from its double buffer.
Best,
Jun
|
|
|
|
|