|
Can't draw CString string with DrawString(GDI+)
CString str=_T("test string");
FontFamily fontFamily(L"Times New Roman");
Font font(&fontFamily, 24, FontStyleRegular, UnitPixel);
PointF pointF(30.0f, 10.0f);
SolidBrush solidBrush(Color(255, 0, 0, 255));
graphics.DrawString(str.GetBuffer(), -1, &font, pointF, &solidBrush);
|
|
|
|
|
DrawString will take WCHAR* as its first argument, CString::GetBuffer() won't workout. Try using WCHAR* instead str.GetBuffer()
|
|
|
|
|
There's no need to use GetBuffer , you can simply pass the CString object, if it's the right width. I suspect you're compiling without UNICODE defined, so your CString is actually a CStringA , which does not have a conversion operator to const WCHAR* . It stores byte-oriented national character set characters. GDI+ expects UTF-16 Unicode characters. You need to either store your strings in this format, or convert them when you need to use them.
Unless you want compatibility with Windows 9x, the easiest thing to do is to simply define UNICODE and _UNICODE , or select the 'Unicode' configuration if you already have one. You need to define both macros because the Windows headers use UNICODE while the C run-time uses _UNICODE . This forces all CString objects to be UTF-16 Unicode. You'll have to fix any compile errors you get here, where you've used a string not wrapped in _T() .
Slightly more difficult is to store any strings you want to display on screen in the correct format. Here you should consider using CStringW objects (I'm assuming you're using at least MFC 7.0 from Visual Studio .NET 2002, rather than MFC 6.0). You can construct a CStringW from byte-oriented national character set data (char* ). You can convert at the point of use if necessary. Using CStringW is slightly more straightforward than trying to use the MultiByteToWideChar API directly.
If explicitly using the wchar_t , WCHAR or CStringW datatypes, you should use the L"" syntax to specify your string literals, rather than _T() . Only use _T() for values that should change format depending on whether _UNICODE is defined.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
CPropertySheet properties(_T("вфыавав"), this, 0);//error C2664: 'CPropertySheet::CPropertySheet(UINT,CWnd *,UINT)' : cannot convert parameter 1 from 'const wchar_t [13]' to 'UINT'
??? but CPropertySheet have constructor with LPCTSTR as the 1st parameter
explicit CPropertySheet(
LPCTSTR pszCaption,
CWnd* pParentWnd = NULL,
UINT iSelectPage = 0
);
|
|
|
|
|
Based on your other question I'd say you probably have _UNICODE defined (which causes _T("") to become L"" ) but not UNICODE , which causes LPCTSTR to become LPCWSTR rather than LPCSTR .
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hello, I want to add a new font to my project but I dont know how?
I downloaded a program and made my font MyFont.ftw and I want to add it,how can I add it to my project and use it in the Static Text.
SnaidiS(Semion)
|
|
|
|
|
Not sure what you mean but you can change the Static font like this
CFont *pNewFont = new CFont;
LOGFONT lf = { 0 };
lf.lfHeight = -12;
lf.lfWeight = FW_LIGHT;
_tcscpy(lf.lfFaceName,_T("Tahoma"));
pNewFont->CreateFontIndirect(&lf);
//After the Static control is created
//Typically in InitDialog functions
GetDlgItem(IDC_STATIC_TEXT)->SetFont(pNewFont);
//Don't forget to Delete the font in OnDestroy
delete pNewFont;
Hope it helps
You know you're obsessed with computer graphics when you're outside and you look up at the trees and think, "Wow! That's spectacular resolution!"
Only kings, presidents, editors, and people with tapeworms have the right to use the editorial "we."
|
|
|
|
|
OK! Thank you a lot!!
SnaidiS(Semion)
|
|
|
|
|
I am facing the problem in printing document. I haev craeted the WIn32 Apllicatio and then in WM_PAINT I amdraing the ellipse. Now I want to printwhatever I see on client area.
I tried with it but was giving whole scrren aftyer printing with reduced size.
I need it in Win32.
"A winner is not one who never fails...but the one who never quits"
|
|
|
|
|
Do you want to prin your shapes did you saw PRINTDLG and StartDoc
whitesky
|
|
|
|
|
I Have seen ...
I need whatever is there in CLient area to be printed....I have written the sample code here:
<br />
void PrintMyPage(HWND hWndMain,HDC hClientDC) <br />
{ <br />
<br />
try<br />
{<br />
DOCINFO lpdi; <br />
<br />
lpdi.cbSize = sizeof( DOCINFO ); <br />
lpdi.lpszDocName = _T( "ReadMe.txt" ); <br />
lpdi.lpszOutput = NULL; <br />
lpdi.lpszDatatype = _T("RAW"); <br />
lpdi.fwType = 0;<br />
<br />
<br />
MessageBox(NULL,_T("Before CreateDC"),_T("Step by Step"),MB_OK);<br />
<br />
<br />
HDC hPrinterDC = CreateDC(_T("HP LaserJet 1020"),_T("HPLaserJ"),NULL,0); <br />
<br />
if(!hPrinterDC)<br />
{<br />
TCHAR szMessage[256];<br />
wsprintf(szMessage,_T("CreateDC Failed, Last Error:%d"),GetLastError());<br />
MessageBox(NULL,szMessage,_T("Error"),MB_OK);<br />
return;<br />
} <br />
<br />
<br />
if(!StartDoc(hPrinterDC, &lpdi))<br />
{<br />
MessageBox(NULL,_T("StartDoc Failed"),_T("Error"),MB_OK);<br />
return;<br />
}<br />
<br />
if(!StartPage(hPrinterDC))<br />
{<br />
MessageBox(NULL,_T("StartPage Failed"),_T("Error"),MB_OK);<br />
return;<br />
} <br />
<br />
int xPage,yPage;<br />
<br />
xPage = GetDeviceCaps(hPrinterDC,HORZRES);<br />
yPage = GetDeviceCaps(hPrinterDC,VERTRES); <br />
<br />
SetMapMode (hPrinterDC, MM_ISOTROPIC) ;<br />
SetWindowExtEx (hPrinterDC, 1000, 1000, NULL) ;<br />
SetViewportExtEx (hPrinterDC, xPage / 2, -yPage / 2, NULL) ;<br />
SetViewportOrgEx (hPrinterDC, xPage / 2, yPage / 2, NULL) ;<br />
<br />
<br />
HDC hCompatibleDC;<br />
<br />
hCompatibleDC = CreateCompatibleDC(hClientDC);<br />
<br />
RECT rt;<br />
GetClientRect(hWndMain,&rt);<br />
<br />
HBITMAP hbmScreen = CreateCompatibleBitmap(hClientDC,<br />
GetDeviceCaps(hClientDC,HORZRES), <br />
GetDeviceCaps(hClientDC,VERTRES)); <br />
SelectObject(hCompatibleDC, hbmScreen);<br />
<br />
<br />
HDC tempDC = CreateCompatibleDC(NULL);<br />
SelectObject(tempDC,hbmScreen);<br />
BITMAP bmp;<br />
GetObject(hbmScreen,sizeof(bmp),&bmp);<br />
<br />
<br />
<br />
if(!::BitBlt(hPrinterDC,0,0, GetDeviceCaps(hCompatibleDC,HORZRES), GetDeviceCaps(hCompatibleDC,VERTRES),hCompatibleDC,0, 0,SRCCOPY))<br />
{<br />
TCHAR szMessage[256];<br />
wsprintf(szMessage,_T("BitBlt failed, Last Error:%d"),GetLastError());<br />
MessageBox(NULL,szMessage,_T("Error"),MB_OK);<br />
return;<br />
}<br />
<br />
<br />
<br />
if(!EndPage(hPrinterDC))<br />
{<br />
MessageBox(NULL,_T("EndPage Failed"),_T("Error"),MB_OK);<br />
return;<br />
}<br />
<br />
if(!EndDoc(hPrinterDC))<br />
{<br />
MessageBox(NULL,_T("EndDoc Failed"),_T("Error"),MB_OK);<br />
return;<br />
} <br />
<br />
MessageBox(NULL,_T("Success"),_T("Success"),MB_OK);<br />
}<br />
catch(...)<br />
{<br />
MessageBox(NULL,_T("Error"),_T("Error"),MB_OK);<br />
}<br />
} <br />
Where I am going wrong......
"A winner is not one who never fails...but the one who never quits"
|
|
|
|
|
I insert lines to this code but check your code i used PrintDlg and
use from pd.hDC instead CreateDC and i cant find a ellipse in your code
but when you run this code you see a ellipse almost in center
<br />
void PrintMyPage(HWND hWndMain,HDC hClientDC) <br />
{ <br />
<br />
try<br />
{<br />
DOCINFO lpdi; <br />
<br />
lpdi.cbSize = sizeof( DOCINFO ); <br />
lpdi.lpszDocName = _T( "ReadMe.txt" ); <br />
lpdi.lpszOutput = NULL; <br />
<br />
<br />
<br />
<br />
<br />
<br />
PRINTDLG pd;<br />
memset((void *)&pd, 0,sizeof(PRINTDLG));<br />
pd.lStructSize = sizeof(PRINTDLG);<br />
pd.hwndOwner = hWndMain;<br />
pd.Flags =PD_RETURNDC|PD_ENABLESETUPTEMPLATE;<br />
pd.hInstance = NULL;<br />
pd.nMaxPage=1;<br />
pd.nMinPage=1;<br />
pd.nCopies=1;<br />
pd.hDevMode=0;<br />
pd.nFromPage=1;<br />
pd.nToPage=1;<br />
PrintDlg(&pd);<br />
HDC hPrinterDC = pd.hDC;<br />
if(!hPrinterDC)<br />
{<br />
TCHAR szMessage[256];<br />
wsprintf(szMessage,_T("CreateDC Failed, Last Error:%d"),GetLastError());<br />
MessageBox(NULL,szMessage,_T("Error"),MB_OK);<br />
return;<br />
} <br />
<br />
<br />
if(!StartDoc(hPrinterDC, &lpdi))<br />
{<br />
MessageBox(NULL,_T("StartDoc Failed"),_T("Error"),MB_OK);<br />
return;<br />
}<br />
<br />
if(!StartPage(hPrinterDC))<br />
{<br />
MessageBox(NULL,_T("StartPage Failed"),_T("Error"),MB_OK);<br />
return;<br />
} <br />
<br />
int xPage,yPage;<br />
<br />
xPage = GetDeviceCaps(pd.hDC,HORZRES);<br />
yPage = GetDeviceCaps(pd.hDC,VERTRES); <br />
<br />
SetMapMode (pd.hDC, MM_ISOTROPIC) ;<br />
SetWindowExtEx (pd.hDC, 1000, 1000, NULL) ;<br />
SetViewportExtEx (pd.hDC, xPage / 2, -yPage / 2, NULL) ;<br />
SetViewportOrgEx (pd.hDC, xPage / 2, yPage / 2, NULL) ;<br />
<br />
<br />
HDC hCompatibleDC;<br />
<br />
hCompatibleDC = CreateCompatibleDC(hClientDC);<br />
<br />
<br />
RECT rt;<br />
GetClientRect(hWndMain,&rt);<br />
<br />
HBITMAP hbmScreen = CreateCompatibleBitmap(hClientDC,GetDeviceCaps(hClientDC,HORZRES), GetDeviceCaps(hClientDC,VERTRES)); <br />
SelectObject(hCompatibleDC, hbmScreen);<br />
<br />
<br />
HDC tempDC = CreateCompatibleDC(NULL);<br />
SelectObject(tempDC,hbmScreen);<br />
BITMAP bmp;<br />
GetObject(hbmScreen,sizeof(bmp),&bmp);<br />
<br />
Ellipse(pd.hDC,100,100,400,400);<br />
<br />
<br />
<br />
<br />
<br />
if(!EndPage(pd.hDC))<br />
{<br />
MessageBox(NULL,_T("EndPage Failed"),_T("Error"),MB_OK);<br />
return;<br />
}<br />
<br />
if(!EndDoc(hPrinterDC))<br />
{<br />
MessageBox(NULL,_T("EndDoc Failed"),_T("Error"),MB_OK);<br />
return;<br />
} <br />
<br />
MessageBox(NULL,_T("Success"),_T("Success"),MB_OK);<br />
}<br />
catch(...)<br />
{<br />
MessageBox(NULL,_T("Error"),_T("Error"),MB_OK);<br />
}<br />
} <br />
whitesky
|
|
|
|
|
I have the ellipse created on WM_PAINT.
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
::Ellipse(hdc,100,100,500,500);
RECT rect;
rect.left = 200;
rect.top = 200;
rect.right = 400;
rect.bottom = 400;
::DrawText(hdc,_T("I am the best"),(int)strlen(_T("I am the best")),&rect,DT_CENTER);
EndPaint(hWnd, &ps);
break;
and on the menu click:
case IDM_MENU1:
hClientDC = GetDC(hWnd);
PrintSelected(hWnd,hClientDC);
break;
I don't want directly to draw ont print dc. First I want to take the handel of my Client DC such taht whatever is drawn on the client are shouldbe printed on page
"A winner is not one who never fails...but the one who never quits"
|
|
|
|
|
Ganesh_T wrote: I tried with it but was giving whole scrren aftyer printing with reduced size.
Thats cause the printers resolution is more than Screens resolution
heres some sample code
CDC prtDC;
CPrintInfo printInfo;
CSize size;
DOCINFO di;
CSize paper_size;
int xLogPPI = 0;
int yLogPPI = 0;
if( AfxGetApp()->GetPrinterDeviceDefaults(&printInfo.m_pPD->m_pd) )
{
HDC hDC = printInfo.m_pPD->m_pd.hDC;
if (hDC == NULL)
hDC = printInfo.m_pPD->CreatePrinterDC();
if(hDC !=NULL)
{
prtDC.Attach(hDC);
paper_size.cx = prtDC.GetDeviceCaps(HORZSIZE);
paper_size.cy = prtDC.GetDeviceCaps(VERTSIZE);
xLogPPI = prtDC.GetDeviceCaps(LOGPIXELSX);
yLogPPI = prtDC.GetDeviceCaps(LOGPIXELSY);
}
else
{
AfxMessageBox("Can not find printer. Please check installed/default printers.");
return ;
}
}
int scr_xLogPPI = pDC->GetDeviceCaps(LOGPIXELSX);
int scr_yLogPPI = pDC->GetDeviceCaps(LOGPIXELSY);
int paper_width = (int) ((double) paper_size.cx * (double) xLogPPI / 25.4);
int paper_height = (int) ((double) paper_size.cy * (double) yLogPPI / 25.4);
double ratio_x = (double) xLogPPI / (double) scr_xLogPPI;
double ratio_y = (double) yLogPPI / (double) scr_yLogPPI;
CFont *pPrnFont = new CFont();
LOGFONT lf = {0};
lf.lfHeight = -14 * ratio_x;
lf.lfWeight = FW_NORMAL;
_tcscpy(lf.lfFaceName,"Times new roman");
pPrnFont->CreateFontIndirect(&lf);
..
..
..
you need to multiply everything with ratio_x and ratio_y so that everythings printed like it is diplayed on the screen
Hope it Helps
You know you're obsessed with computer graphics when you're outside and you look up at the trees and think, "Wow! That's spectacular resolution!"
Only kings, presidents, editors, and people with tapeworms have the right to use the editorial "we."
|
|
|
|
|
I want to use only SDK. no mfc classes. I haveposted the code in my reply to whitesky
"A winner is not one who never fails...but the one who never quits"
-- modified at 4:41 Tuesday 11th July, 2006
|
|
|
|
|
Ganesh_T wrote: I want to use only SDK. no mfc classes. I haveposted the code in my reply to whitesky
Ok Ganesh listen up, The printer resolution is far more than screen's resolution.
So you need to calculate the number of times Printer resolution is greater than Screen's
So get printers Resolution use
int xPrnRes = GetDeviceCaps(hPrinterDC,LOGPIXELSX);
int yPrnRes = GetDeviceCaps(hPrinterDC,LOGPIXELSY);
Get Screens Res
int xScrnRes = GetDeviceCaps(hScreenDC,LOGPIXELSX);
int yScrnRes = GetDeviceCaps(hScreenDC,LOGPIXELSY);
Get Ratio
double ratio_x = (double)xPrnRes/(double)xScrnRes;
double ratio_y = (double)yPrnRes/(double)yScrnRes;
ok so if you have an image of say 100x100 px on screen and you want to print it the destination image will be of 100*ratio_x and 100*ratio_y
so instead of using BitBlt you have to use StretchBlt to stretch the Bitmap
You know you're obsessed with computer graphics when you're outside and you look up at the trees and think, "Wow! That's spectacular resolution!"
Only kings, presidents, editors, and people with tapeworms have the right to use the editorial "we."
|
|
|
|
|
Hi all,
can anyone tell me about how to detect the frame change in the video file?
Thanks in advance.
Regards,
Ram
|
|
|
|
|
a treectrl such as:
[-]Root1
| |_Lay1Item1
| |_Lay1Item2
| [-]Lay1Item3
| |_Lay2Item1
| |_BB
+Root2
1>.how to get the item handle by its name/string?
2>.how to know the item stay at which lay? for example: Lay1Item1 stay at lay 1, root is 0,BB is lay 2
|
|
|
|
|
(1>.) See GetNextItem(...);
whitesky
|
|
|
|
|
1>.how to get the item handle by its name/string?
->I guess you cannot, what if two nodes having same name? Instead try using GetItem and GetNextitem function.
2>.how to know the item stay at which lay? for example: Lay1Item1 stay at lay 1, root is 0,BB is lay 2
-> SetItemData may help.
Regards
Abhishake Lahare
|
|
|
|
|
thank you for your quick reply.
about 2> in fact, I'v used SetItemData for manage the handle of MDI docs.....
what I want is: aplly different doc template for different lay of item related Doc
|
|
|
|
|
hai every one
i have created one class it contains one big window
and i added some small node(it is also window) to that window.
then when i move the small node on big window
that moving part is changing the color
can any one help me
B.LakshmipathiRao
|
|
|
|
|
i'm not getting ur question, can u give some more information.
how u r moving the smaller windows by code or my mouse?
|
|
|
|
|
Silly question, had a lok in the MSDN but could not find any thing that satisfied my curiosity, how long can a command line be? I´m asking because I am passing a path to a file,plus an SQL query to an external process (using create process), so can I expect any problems regarding a very long SQL query...
Thanks in advance
Phil
bum... and I thought I´d got rid of all the bugs
|
|
|
|
|
from stdlib.h on VS.NET
/*
* Sizes for buffers used by the _makepath() and _splitpath() functions.
* note that the sizes include space for 0-terminator
*/
#define _MAX_PATH 260 /* max. length of full pathname */
#define _MAX_DRIVE 3 /* max. length of drive component */
#define _MAX_DIR 256 /* max. length of path component */
#define _MAX_FNAME 256 /* max. length of file name component */
#define _MAX_EXT 256 /* max. length of extension component */
Hope these help
Regards
Abhishake Lahare
|
|
|
|
|