|
The description of the SetWindow/MoveWindow functions is correct when it says you have to use client corrdinates.
However it does not tell you that you move you child window within the client space of the parent window and therefore need to give the coordinates in the parent window client space format.
This is one possible solution:
inline void CMyWnd::MoveWindowRelative(RECT* Displacement, BOOL bRepaint)
{CWnd* pParCWnd;
RECT WndCoor;
pParCWnd = GetParent();
ASSERT (IsKindOf (RUNTIME_CLASS(CWnd)));
GetWindowRect(&WndCoor);
pParCWnd->ScreenToClient(&WndCoor);
WndCoor.left += Displacement->left;
WndCoor.top += Displacement->top;
WndCoor.right += Displacement->right;
WndCoor.bottom += Displacement->bottom;
MoveWindow(&WndCoor, bRepaint);
}
top + left of Displacement specify the amount you want to shift the window, bottom + rightod Displacement specify how you want to shrink or enlarge the window.
Regards
Leo
|
|
|
|
|
hi
i write a Tetris. i have completed it about 60%. main problem is that how can i bound the border of windows that block can't pass it.
another problem is their moving. They shouldn't collision with together.
how can i do that?
sorry for poor english
#Mojtaba Karimi#
|
|
|
|
|
both questions have one answer:
i guess you re-draw tetris blocks each time they move, using rectangles (RECT structure) of the block parts. so what you have to do is to check if left-most,right-most and bottom-most rectangles are inside the main window rectangle. also, the block should stop moving when the bottom-most rectangle of it touches the top-most block's rectangle on the same game column (each block part is one column wide).
you can get the rectangle of the main window using GetWindowRect() function.
but don't forget to use, ClientToScreen() and ClientToParent() functions when needed, they save more than just time.
|
|
|
|
|
Maybe the IntersectRect function (see here [^]) or the MFC flavor CRect::IntersectRect ([^]) will be useful.
Good luck.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hi everyone,
I've been digging up for a way to handle key presses (specifically CTRL+A KeyDown) for the EditBox in the ComboBoxEx in my IE toolbar and have failed everytime.
I tried to handle the WM_KEYDOWN events but I just couldn't. The ComboBox won't fire any event and I want to select all the text within the EditBox when user presses CTRL+A.
There must surely be a way but what could that be?
|
|
|
|
|
|
I checked out the article but there's something I just can't catch:
The ComboBoxEx does not recieve any WM_KEYDOWN events from the EditBox within. I used Spy++ to see that the event doesn't even get past the ComboBox control inside the ComboBoxEx. So, how can I catch the WM_KEYDOWN event when I can't catch it on the parent?
|
|
|
|
|
Not sure if this helps but you need to use this code to get return keys in your derived class. Maybe the same for your probem?
UINT CEdit_xx::OnGetDlgCode()
{
return( CEdit::OnGetDlgCode() | DLGC_WANTALLKEYS );
}
|
|
|
|
|
CRect stbRect;
CString cs2;
staticTextBox.GetClientRect(stbRect);
staticTextBox.GetWindowTextW(cs2);
CSize textSize = staticTextBox.GetDC()->GetTextExtent(cs2);
cs2.Format((_T("%d - %d")), textSize.cx, stbRect.Width());
AfxMessageBox(cs2,0,0);
cs2 fits the width of the static control
MessageBox reports
260 - 178
because the text is the same width as
the static control I was expecting
size.cx == stbRect.Width()
Where am i going wrong ?
-- modified at 11:19 Wednesday 16th May, 2007
|
|
|
|
|
Sorry but I was unable to locate GetWindowTextW function ,and size is variable of which class ?
|| ART OF LIVING ||
|
|
|
|
|
CSize textSize = staticTextBox.GetDC()->GetTextExtent(cs2);
If the static control is from a dialog, it may use a different font.
staticTextBox.GetDC() is returning a DC for the control but you've selected no font into it
before calculating the text extents.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
>> staticTextBox.GetDC() is returning a DC for the control but you've selected no font into it
Greetings Mark
I now have this ...
void CmyAppDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
//OnOK();
CRect stbRect;
CString cs2;
staticTextBox.GetClientRect(stbRect);
staticTextBox.GetWindowTextW(cs2);
CFont * font = GetDC()->GetCurrentFont();
staticTextBox.SetFont(font,1);
CSize textSize = staticTextBox.GetDC()->GetTextExtent(cs2);
cs2.Format((_T("%d - %d")), textSize.cx, stbRect.Width());
AfxMessageBox(cs2,0,0);
}
Now when the text fills the width of the
static control textSize.cx equals stbRect.Width().
This is a good thing .
I am setting the font of the control to the
same font used by GetTextExtent .
How may I instead , set the font used by
GetTextExtent to the same font used by
the static control ?
Thanks for reading this .
|
|
|
|
|
Here's an example - using the dialog's font...
void CmyAppDlg::OnBnClickedOk()
{
CRect stbRect;
CString cs2;
staticTextBox.GetClientRect(stbRect);
staticTextBox.GetWindowTextW(cs2);
// Get a DC for the static control
//*edit* this could be "CClientDC ClientDC(this);"
//*edit* (any window/screen-compatible DC will do)
CClientDC StaticDC(&staticTextBox);
// Select the dialog's font into it
CFont *pOldFont = StaticDC.SelectObject(GetFont());
// Get the text extent based on the dialog font
CSize textSize = StaticDC.GetTextExtent(cs2);
// restore the DC
StaticDC.SelectObject(pOldFont);
cs2.Format((_T("%d - %d")), textSize.cx, stbRect.Width());
AfxMessageBox(cs2,0,0);
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-- modified at 14:29 Wednesday 16th May, 2007
|
|
|
|
|
Thank you Mark !
You have made many things very clear .
I have this now
CRect stbRect;
CString stbStr;
staticTextBox.GetClientRect (stbRect);
staticTextBox.GetWindowTextW(stbStr);
CClientDC stbCDC(&staticTextBox);;
CFont *pOldFont = stbCDC.SelectObject(GetFont());
CSize textSize = stbCDC.GetTextExtent(stbStr);
stbCDC.SelectObject(pOldFont);
int stbLines = stbRect.bottom / textSize.cy ;
stbStr = _T("this is on the top line");
for(int i=1 ; i<stbLines ; i++){stbStr += _T("\r\n");}
stbStr += _T("this is on the bottom line");
staticTextBox.SetWindowTextW(stbStr);
|
|
|
|
|
Cool does it work like you need it to? I was never sure what you were up to
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
|
how do I input info entered for a enumerated object?
enum typeofbook {fiction, nonfiction, reference, pond};
I'm trying to prompt the user which type of book they are entering information for.
Any ideas would be appreciated.
thanks
|
|
|
|
|
Your question is not very clear.
cout << "Which type of book... (1=fiction, 2=nonfiction, 3=reference, 4=pond)";
int nType;
cin >> nType;
switch (nType)
{
case 1:
break;
...
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I put enum typeofbook {fiction, nonfiction, reference, pond}; in a structure which is then declared the structure as books. I am asking the user which type of book he is entering information for, 1 fiction, 2 nonfiction, 3 reference, 4 pond. Once they enter either the number or name for type of book, I need to cin>> the information or something so I can store into a text file.
|
|
|
|
|
enum are only an internal semantic representation of an integer value.
you will store the integer value; not it's "representation"
if a user enters 1 ( in the enum is fiction ) it will be stored as 1.
pseudo code :
you can either directly do something like :
typedef enum {fiction, nonfiction, reference, pond} typeofbook;
typeofbook myBookType;
int i;
cin>>i;
myBookType = (typeofbook) i;
|
|
|
|
|
Dear all
this is very urgent issue for my project, my image processing interface is 2-dimenssion image procesing. but how to build a 3-dimenssion image processing inside my interface?
thanks
Li Zhiyuan
5/10/2006
|
|
|
|
|
Your question is very generic. If you want to render a 3D scene in your application, I suggest you take a look at DirectX or OpenGL.
|
|
|
|
|
|
Dear All;
I am trying to save an image to my harddrive, the image should be of depth 24 or less ie.16, 8, 4. regardless of of the monitor's resolution
I have the tried the following code and its works fine but the saved images are of 32 bit depth. I have tried to fiddle with the code but i cant get an image of 24 bit depth or less , can anyone please advise and i will be grateful.
<br />
void Example:: SaveBitmap(char *name,HBITMAP hBitMap)<br />
{<br />
CBitmap bmp;<br />
bmp.Attach(hBitMap);<br />
<br />
BITMAP bitmap;<br />
bmp.GetBitmap(&bitmap);<br />
int size = bitmap.bmWidth*bitmap.bmHeight*bitmap.bmBitsPixel/8;<br />
BYTE *lpBits = new BYTE[size];<br />
<br />
::GetBitmapBits(hBitMap,size,lpBits);<br />
WriteBmp(name,&bitmap,(int*)lpBits);<br />
delete []lpBits;<br />
}<br />
void Example::WriteBmp(char* name,BITMAP *bmp,int* data)<br />
{<br />
BITMAPINFO Bmi;<br />
memset(&Bmi,0,sizeof(BITMAPINFO));<br />
Bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);<br />
Bmi.bmiHeader.biWidth = bmp->bmWidth;<br />
Bmi.bmiHeader.biHeight = bmp->bmHeight;<br />
Bmi.bmiHeader.biPlanes = 1;<br />
Bmi.bmiHeader.biBitCount = bmp->bmBitsPixel;<br />
Bmi.bmiHeader.biCompression = BI_RGB;<br />
Bmi.bmiHeader.biSizeImage = bmp->bmHeight*bmp->bmWidth*bmp->bmBitsPixel/8;<br />
<br />
FILE* image = fopen (name,"wb");<br />
if(image==0)<br />
return;<br />
int h = abs(Bmi.bmiHeader.biHeight);<br />
int w = abs(Bmi.bmiHeader.biWidth);<br />
Bmi.bmiHeader.biHeight=-h;<br />
Bmi.bmiHeader.biWidth=w;<br />
int sz = Bmi.bmiHeader.biSizeImage;<br />
<br />
BITMAPFILEHEADER bfh;<br />
bfh.bfType=('M'<<8)+'B'; <br />
bfh.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); <br />
bfh.bfSize=sz+bfh.bfOffBits; <br />
bfh.bfReserved1=0; <br />
bfh.bfReserved2=0; <br />
fwrite(&bfh,sizeof(bfh),1,image);<br />
fwrite(&Bmi.bmiHeader,sizeof(BITMAPINFOHEADER),1,image);<br />
fwrite(data,sz,1,image);<br />
fclose(image);<br />
}<br />
<\code><br />
<br />
Thank you <br />
<br />
<div class="ForumSig">llp00na</div>
|
|
|
|
|
You are converting a device-dependent bitmap (DDB) to a device independent bitmap (DIB) to save.
Since you don't do any conversion of the bitmap format, if the source DDB is 32-bit, then the
saved DIB is 32-bit.
If you want to convert the format, you can use GetDIBits() to get the DIB bits in the format you
want.
See How To Convert Between Device-Dependent Bitmaps and DIBs[^]
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|