|
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
|
|
|
|
|
Mark Salsbery wrote: 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.
Its because i don't know how to convert from a 32 bit bitmap to a less depth bitmap.
Mark Salsbery wrote: See How To Convert Between Device-Dependent Bitmaps and DIBs[^]
Thank you for the article, i will go through it and give it a go.
I am gratefull for your valuable assistance .
llp00na
|
|
|
|
|
Here's another link: Converting DDB to DIB[^]
In that code, the BITMAPINFOHEADER biPlanes, biBitCount, and biCompression members are initialized
to match the source DDB.
To change the type, set those members to the actual format you want before making the first
call to GetDIBits.
Remember, for 1, 4, and 8 bit formats you'll need to deal with a color table in the DIB.
For 24-bit, there's no color table. See the documentation for BITMAPINFOHEADER for details.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark Salsbery wrote: Remember, for 1, 4, and 8 bit formats you'll need to deal with a color table in the DIB.
For 24-bit, there's no color table. See the documentation for BITMAPINFOHEADER for details.
Alright then, i will convert it to a 16 or 24 bit bitmap then. I dont want to run into complications.
Mark Salsbery wrote: Here's another link: Converting DDB to DIB[^]
Many thanx, I am once again very grateful
llp00na
|
|
|
|
|
He will need to deal with CPalette too
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
what are the basic functionality difference between this two header files???
can any one explain me in detail ???
Thanks in advance.
"Success lies not in the result , But in the efforts !!!!!"
Amit Mistry - petlad -Gujarat-India
|
|
|
|
|
I don't know about detail, but ...
wininet.h is the header file for the WinINet APIs:
"The Windows Internet (WinINet) application programming interface (API) enables applications to
interact with Gopher, FTP, and HTTP protocols to access Internet resources. "
winsock.h is the header file for the Windows Sockets 2 APIs:
"Windows Sockets 2 (Winsock) enables programmers to create advanced Internet, intranet, and other
network-capable applications to transmit application data across the wire, independent of the
network protocol being used."
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|