|
Can someone tell me how I can rotate some text i am putting on a CDC?
Im currently creating the font, then using TextOut() to draw the text when displaying and printing, is there a way to rotate the text 45 degrees?
thanks in advance for any suggestions!
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
I believe you can specify the text rotation when you create your font. Check out CFont in MSDN for more info... then it's just a matter of selecting that font, and then calling TextOut as normal.
If you aren't using MFC, I think this item is also in the LOGFONT structure.
Even a broken clock is right twice a day.
|
|
|
|
|
In the LOGFONT structure there is a data member called lfEscapement. Before you pass the LOGFONT structure to a CreateFont call, assign some value to this member and that should rotate the text. Below is some code I use in a view that makes use of rotated text.
BOOL CRedsView::CreateFont(CFont& Target, LPCSTR Name, int PointSize, int Weight, BYTE bItalic, BYTE bUnderline, long nEscapement)
{
LOGFONT LogFont;
LogFont.lfHeight = PointSize;
LogFont.lfWidth = NULL;
LogFont.lfEscapement = nEscapement;
LogFont.lfOrientation = NULL;
LogFont.lfWeight = Weight;
LogFont.lfItalic = bItalic;
LogFont.lfUnderline = bUnderline;
LogFont.lfStrikeOut = NULL;
LogFont.lfCharSet = ANSI_CHARSET;
LogFont.lfOutPrecision = OUT_TT_PRECIS;
LogFont.lfClipPrecision = CLIP_TT_ALWAYS;
LogFont.lfQuality = PROOF_QUALITY;
LogFont.lfPitchAndFamily = TMPF_TRUETYPE|FF_SWISS;
strcpy(LogFont.lfFaceName, Name);
return ( Target.CreateFontIndirect(&LogFont) );
}
void CRedsView::CreateAllFonts(double dZoomFactor)
{
CString FontFaceName("Arial");
if ( !CreateFont(m_fHeading, (LPCSTR)FontFaceName, (int)(m_nFontSize*1.75*dZoomFactor), FW_BOLD, 0, 1) )
TRACE("A call to the CreateFont method has returned FALSE.\n");
if ( !CreateFont(m_fSubTitle, (LPCSTR)FontFaceName, (int)(m_nFontSize*1.5*dZoomFactor)) )
TRACE("A call to the CreateFont method has returned FALSE.\n");
if ( !CreateFont(m_fSubTitle1, (LPCSTR)FontFaceName, (int)(m_nFontSize*1.5*dZoomFactor), FW_BOLD) )
TRACE("A call to the CreateFont method has returned FALSE.\n");
if ( !CreateFont(m_fSubHeading, (LPCSTR)FontFaceName, (int)(m_nFontSize*1.5*dZoomFactor), FW_BOLD, 1) )
TRACE("A call to the CreateFont method has returned FALSE.\n");
if ( !CreateFont(m_fSubHeading1, (LPCSTR)FontFaceName, (int)(m_nFontSize*1.5*dZoomFactor), FW_BOLD, 0, 1) )
TRACE("A call to the CreateFont method has returned FALSE.\n");
if ( !CreateFont(m_fNormal, (LPCSTR)FontFaceName, (int)(m_nFontSize*dZoomFactor)) )
TRACE("A call to the CreateFont method has returned FALSE.\n");
if ( !CreateFont(m_fNormal10, (LPCSTR)FontFaceName, (int)(m_nFontSize*1.25*dZoomFactor)) )
TRACE("A call to the CreateFont method has returned FALSE.\n");
if ( !CreateFont(m_fAngled, (LPCSTR)FontFaceName, (int)(m_nFontSize*1.5*dZoomFactor), FW_NORMAL, 0, 0, -750) )
TRACE("A call to the CreateFont method has returned FALSE.\n");
}
Chris Meech
"what makes CP different is the people and sense of community, things people will only discover if they join up and join in." Christian Graus Nov 14, 2002.
"AAAAAAAAAHHHHHH!!!!! Those leaks are driving me crazy! How does one finds a memory leak in a garbage collected environment ??! Daniel Turini Nov. 2, 2002.
|
|
|
|
|
Set the nOrientation LOGFONT member variable to 450 for a 45 degree shift, 900 for 90 etc when creating your font.
Roger Allen
Sonork 100.10016
This is a multiple choice question, choose wisely
Why did the hedgehog cross the road?
A: To show he had guts?
B: To see his flat mate?
|
|
|
|
|
thanks a ton for everyone's help
i had tried adjusting the nOrientation on the CreateFont() call, but it wasn't doing anything.. i ended up changing the nEscapement to 450 and that worked.. turned out i was using too small of units.. i had been trying 45 hehe
anyways it seems it is nEscapement, as it didn't work for nOrientation, however the descriptions in msdn makes it sound like you could do it either way..
thanks
CFont fnDemo;
fnDemo.CreateFont(
1200,
0,
450,
0,
FW_BOLD,
TRUE,
TRUE,
0,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH | FF_SWISS,
"Courier New");
CFont* pOldFont = pDC->SelectObject(&fnDemo);
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
dazinith wrote:
anyways it seems it is nEscapement, as it didn't work for nOrientation, however the descriptions in msdn makes it sound like you could do it either way..
It's one of those confusing things in GDI where the authors felt it should work a certain way, but didn't bother actually implementing on systems where it mattered. nOrientation *will* actually take effect if you've called SetGraphicsMode(GM_ADVANCED), but only on WinNT or greater. To be on the safe side, set nOrientation to the same value as nEscapement - it's usually gonna be what you want anyway.
---
Shog9
The siren sings a lonely song - of all the wants and hungers
The lust of love a brute desire - the ledge of life goes under
|
|
|
|
|
I have a Davis Instrument Weather station and it comes with software that downloads the data from the station and writes it to binary data files. One file per month is created. The only documentation (see below) I could find for the data file format seems to indicate it is a C++ created binary file. Davis Instruments tech support was unwilling to provied any additional information. I want to use Visual C++ .net to read the data out of the files and load it into a SQL database. The problem is I am a C++ novice and cannot seem to find any good examples of dealing with files like this. Deserialization was something I was looking at but if I understand correctly you can only store and thus read one object in one file. Can anyone tell me what would be the best approach to extracting the data contained in these files?
Thanks,
Frank Kloskowski
Data File Structure
// Data is stored in monthly files. Each file has the following header.
struct DayIndex
{
int recordsInDay;
long startPos; // The index (starting at 0) of the first record for the day.
};
// Header for each monthly file.
class HeaderBlock
{
char idCode [16]; // = {'W', 'D', 'A', 'T', '1', '.', '0', 0, 0, 0, 0, 0, 0, 0, 1, 0}
int daysInMonth; // this field is no longer used.
long totalRecords;
DayIndex dayIndex [31];
};
// After the Header are one or more records with the following format
class WeatherRecord
{
int packedTime;
int hiOutsideTemp;
int lowOutsideTemp;
int insideTemp;
int outsideTemp;
int barometer;
unsigned char insideHum;
unsigned char outsideHum;
int dewPoint;
int rain;
unsigned char windSpeed;
unsigned char hiWindSpeed;
int windChill;
unsigned char windDirection;
unsigned char archiveInterval;
};
|
|
|
|
|
Hi Frank,
Serialization is of little interest here. What matters is the information about the exact layout of the data. Assuming the classes you provide are accurate with respect to layout, reading could be done like this (pseudocode follows):
#pragma pack(push,8)
#pragma pack(pop)
...
FILE *fp=fopen("inputfile","rb");
...
WeatherRecord wr;
fread(&wr,sizeof(wr),1,fp);
... Play with this until you're sure you've gotten it right (for instance, after reading a header block the idCode should have been put into place, etc.) Another subject you might have to take into account is endian-ness (whether numbers are stored from least significant to most significant byte or the other way around). Check if the numbers are consistent --if they are too large some endian-ness change might be needed.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks Joaquin. I will give it a try.
Frank Kloskowski
|
|
|
|
|
I have a requirement (in a dialog based application) to show the system menu on click of a button, placed somewhere in the middle of client area.
So I tried this code.
void CMenuTestDlg::OnMenuButton()
{
CMenu * sysMenu = GetSystemMenu(FALSE);
if(sysMenu != NULL){
sysMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, 40,40, this);
}
}
Using this, the menu appears but it doesnt function, i.e, I select minimize or close menu item nothing happens.
Am I missing anything here? Gurus Please help me..
Thanks in advance,
Subrahmanyam
|
|
|
|
|
TrackPopupMenu seems not to work well with system menus. Try this workaround:
void CMenuTestDlg::OnMenuButton()
{
CMenu * sysMenu = GetSystemMenu(FALSE);
if(sysMenu != NULL){
int menuID=sysMenu->
TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON |TPM_RIGHTBUTTON |
TPM_NONOTIFY | TPM_RETURNCMD, 40,40, this);
if(menuID){
SendMessage(WM_SYSCOMMAND,menuID,0);
}
}
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Man,
You rock!!
Thanks for the help. Its working great.
regards,
Subrahmanyam.
|
|
|
|
|
When user selects command from system menu opent by usual way, your dialog gets WM_SYSCOMMAND message. When command is selected from the menu created by OnMenuButton(), dialog gets WM_COMMAND message. Play with Spy++ to find the way to handle this.
|
|
|
|
|
Alex,
Thanks for your reply and the pointer to solution.
Joaquín has posted code and made my day
Thanks to both of you,
Subrahmanyam.
|
|
|
|
|
Can somebody help me.
What is the most elegant way to get a uniq filename under windows.
|
|
|
|
|
GetTempFileName is customarily used for that purpose.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks a lot this must be the solution.
Jørgen Granborg
DK
|
|
|
|
|
Hi , i am working on a project where i will be needing this plugin kinda library support , so if any one of u have worked or does know the place from where i can get any kinda help then please do let me know.
thanks
gracias
gracias carol
|
|
|
|
|
What's the politically (and standards) correct method these days?
[geek]
I have strings that look like this: "d20", "5d6", etc. I need to suck out the optional prefix number, and the suffix number.
[/geek]
I will be using std::string and the rest of the standard library, and will be avoiding MFC entirely.
Any suggestions? istringstream?
J
May the bear never have cause to eat you.
|
|
|
|
|
Regular expressions seem to be called for here. Take a look at Boost.Regex++[^].
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
If the pattern was more complicated, I would agree. But since it's just [0-9]?d[0-9] I figured I could do it manually and save the hassle of figuring out Boost.
Would you recommend using Boost for something so simple?
J
May the bear never have cause to eat you.
|
|
|
|
|
Well, maybe regexps are a little overkill for this task, but it depends on how confident you are about this format not changing in the future. Anyway, if you're sure this won't change and don't want to mess with regexps, I think sscanf is your best ally here:
#include <stdio.h>
#include <stdlib.h>
bool my_precious_parser(const char* str,int& prefix,int& suffix)
{
char str_prefix[1024]="0",str_suffix[1024];
if(
sscanf(
str,
"%[012345689]d%[0123456789]",
str_prefix,str_suffix)!=2 &&
sscanf(
str,
"d%[0123456789]",
str_suffix)!=1){
return false;
}
prefix=atoi(str_prefix);
suffix=atoi(str_suffix);
return true;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hello all,
(In a MDI-project) I've a statusbar defined in ChildFrm and I want to be able to set its text in the Doc or View. I've tried some ways (ending in using SetPaneText), but I keep getting assert errors. The code is based on the starting point as delivered from the Wizard, and then use the MainFrm statusbar code in the ChildFrm.
If I'm using the 'general' statusbar (in MainFrm) I succeed, but thats not what I want.
So: How to I access the statusbar in the childframe via xxxDoc.cpp or xxxView.cpp?
Thanks in advance,
EiSl
|
|
|
|
|
You could create a public function in your CMainFrame to do the changes and call that function from your doc or view..
Rob
|
|
|
|
|
Hello
I am quite new to the CMonthCalControl (I am working with VC7). Is there a simple way to give it a 'multirow' (multi columns) 'shape', i mean a simple way in order to show not only one 'calendar box' but, say, 3x4 month boxes all at once?
I suppose i could get that result creating an array of controls, right?
Thanks in advance for any help/tip/info!
best regards
|
|
|
|
|