|
|
Well, you'r entirely welcome.
I am most happy to edify.
|
|
|
|
|
Hi,
I got one CZoomView sample file form code project.Actually i want zoom fucntion in my applcaiton for every view.In tht,initially when i set scrollposition,extra window is appearing.
For example,in OnDraw(),i set background of window as black
CRect mClientArea;
GetClientRect(&mClientArea);
pDC->FillRect(&mClientArea,&CBrush(RGB(0,0,0)));
I set scroolsize as
m_layout.cx = GetSystemMetrics( SM_CXSCREEN );
m_layout.cy = GetSystemMetrics( SM_CYSCREEN );
m_page.cx = m_layout.cx/2; m_page.cy = m_layout.cy/2;
m_line.cx = m_layout.cx/50; m_line.cy = m_layout.cy/50;
SetScrollSizes(MM_TEXT, m_layout, m_page, m_line);
What happended is after execution,when i scroll the horizonatal or vertical scrolls,the window is scrolling more than actual window rect.
More white screen is appearing apart for black background.How can i avoid that? Because while zooming,if user move the scrolls,then extra empty window will appear.i want to avoid that.
Anu
|
|
|
|
|
Anu,
Try this:
// header file: "MyScrollView.h"
#pragma once
class CDoc;
class CMyScrollView : public CScrollView
{
DECLARE_DYNCREATE(CMyScrollView)
DECLARE_MESSAGE_MAP()
public:
CMyScrollView();
virtual ~CMyScrollView();
CDoc* GetDocument();
protected:
virtual void OnDraw(CDC* pDC);
virtual void OnInitialUpdate();
private:
int Height;
int Width;
CBitmap* Bitmap;
CDC* MemDC;
};
// implementation file: "MyScrollView.cpp"
#include "stdafx.h"
#include "MyScrollView.h"
IMPLEMENT_DYNCREATE(CMyScrollView, CScrollView)
BEGIN_MESSAGE_MAP(CMyScrollView, CScrollView)
END_MESSAGE_MAP()
CMyScrollView::CMyScrollView() :
Bitmap(new CBitmap), Width(1000), Height(200), MemDC(new CDC)
{
MemDC->CreateCompatibleDC(NULL);
}
CMyScrollView::~CMyScrollView()
{
delete Bitmap;
delete MemDC;
}
CDoc* CMyScrollView::GetDocument()
{ return (CDoc*)m_pDocument; }
void CMyScrollView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
GetParentFrame()->SetWindowText("CMyScrollView");
CClientDC dc(this);
Bitmap->CreateCompatibleBitmap(&dc, Width, Height);
Bitmap->SetBitmapDimension(Width, Height);
CBitmap* OldBitmap = MemDC->SelectObject(Bitmap);
MemDC->PatBlt(0, 0, Width, Height, BLACKNESS);
CPen WhitePen(PS_SOLID, 1, RGB(255,255,255));
CPen* OldPen = MemDC->SelectObject(&WhitePen);
MemDC->MoveTo(0, 0);
MemDC->LineTo(Width, Height);
MemDC->MoveTo(Width, 0);
MemDC->LineTo(0, Height);
MemDC->SelectObject(OldPen);
CPen RedPen(PS_SOLID, 1, RGB(255,0,0));
OldPen = MemDC->SelectObject(&RedPen);
MemDC->Rectangle(0,0,10,10);
MemDC->SelectObject(OldPen);
CPen GreenPen(PS_SOLID, 1, RGB(0,255,0));
OldPen = MemDC->SelectObject(&GreenPen);
MemDC->Ellipse(Width-20, Height-20, Width, Height);
MemDC->SelectObject(OldPen);
CRect Rect(0,Height-20,20,Height);
CBrush Brush(RGB(0,0,255));
MemDC->FillRect(Rect, &Brush);
MemDC->SelectObject(OldBitmap);
SetScrollSizes(MM_TEXT, CSize(Width, Height));
ResizeParentToFit(TRUE);
}
void CMyScrollView::OnDraw(CDC* pDC)
{
if (Bitmap)
{
pDC->SetStretchBltMode( COLORONCOLOR );
CBitmap* OldBitmap = MemDC->SelectObject(Bitmap);
pDC->BitBlt(
0, 0, Width, Height,
MemDC,
0, 0,
SRCCOPY);
MemDC->SelectObject(OldBitmap);
}
}
|
|
|
|
|
I want to use std::stringstream to format data to a string like sprintf "%02d" as below:
char szWord[MAX_PATH];
int nValue=3;
sprintf(szWord,"%02d",nValue);
How do I do that by std::stringstream?
modified on Friday, April 9, 2010 5:17 AM
|
|
|
|
|
|
stringstream does not print, but iostream does. Try the cout object as follows:
int x(3);
std::cout.setfill('0');
std::cout.setw(2);
std::cout << x << endl;
stringstream is used similarly, but as I said before it writes to memory, not the console.
Edit: did not pick up on the formating earlier.
|
|
|
|
|
There is (I have been told) a way of using an entire dialog template as a resource in another dialog. This would be very usefull in organising things like a property sheet in one corner and something else in another place. Has anyone tried the mechanics of this?
Regards,
|
|
|
|
|
You don't use a dialog template as a resource in another dialog - to me this implies merging. I've never seen this done.
What is common is to:
- define the parent dialog template
- on the parent, define where a child dialog is to be placed by using a dummy control
- in the parent WM_INITDIALOG:
- call CreateDialog*() to create the child dialog from its template
- find the dummy control and it's extents
- delete the dummy and resize/position the child dialog to take its place
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
LPWSTR S = L"Hello World!";
for (n = 12; n > 0; n--)
{
if (S[n] == 'W')
{
MessageBox (hwnd, L"Found W!", L"FilePosition", NULL);
}
}
error C2446: '==' : no conversion from 'int' to 'LPWSTR'
|
|
|
|
|
'W' is supposed to be a wide character so use L'W'
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
As a side note, your loop limits are wrong, you should use
for (n=11; n>=0; n--)
or, better
for (n=wcslen(S)-1; n>=0; n--)
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
If this is your actual code, you aren't getting that error. S[n] returns a wchar_t, not a LPWSTR. 'W' doesn't need to be L'W' since it will auto-promote to wchar_t.
(Plus, for(n should be for(int n .)
|
|
|
|
|
Joe Woodbury wrote: 'W' doesn't need to be L'W' since it will auto-promote to wchar_t.
That should not be true.
It was true with old C++ version, where the wchar_t was not an independent type, and was just a typedef for "unsigned short", and "char" autopromote into "short" and become "unsigned".
In more modern versions, wchar_t can be set up as an independent type with a compiler switch and -now- it becomes a default by standard.
Autopromotion of char-s into wchar-t must not happen, since the "encoding scheme" used in strings may not fit: All negative chars (above 127) are not ASCII and hence may have different meaning if ANSI (depending on the codepage) or UTF (can be UTF-8).
That said, char to wchar_t is not a one-to-one arithmetic conversion. You may have four chars going into a single or a pair of wchar_t (think to UTF-8 to UTF-16 chinese).
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Good to know, but weird, in my opinion.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
That's was what i though when that differentiation was introduced.
But it saved me lot of time form char-type mismatching in strings!
The "werid" thing is that C++ is still taking the old C idea of "char are just numbers" and strings don't exist (there are character arrays and string manipulation functions).
Than wchar_t was introduced, and a type semantic was applied to it.
It would be more correct -nowadays- the case that even char should not have number semantic and a different type (may be byte and unsigned byte , or short short int ) should be introduced to represent small integers)
I also wander why C and C++ standard are insisting with all those sort of short , long , long long , long long long , etc. instead of simply define integers as int_x where x is the number of bits (MS does it, but it's not "standard").
Then there might be char_x , incompatible with int_x unless of explicit conversions and functions.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Well, after 'initial shock' I think you are actually right.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
This is more funny I don't know if it's related to the new standards or if not.
My program has a linked list data structure in C++.
So...
class Whatever
{
public:
LPWSTR *Info;
};
is my basic data structure.
I store info along the way from a ComboBox in a Whatever data structure.
Eventually I want to process several of Info and divide them in several Strings.
if (Test->Info[n] == L'/')
{
}
I end up getting these errors.
1>main.cpp(686): error C2446: '==' : no conversion from 'int' to 'LPWSTR'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>main.cpp(686): error C2040: '==' : 'LPWSTR' differs in levels of indirection from 'int'
However if I address LPWSTR directly not through the C++ class data structure everything goes smooth as silk.
|
|
|
|
|
Try to change:
Fareed Rizkalla wrote: class Whatever
{
public:
LPWSTR *Info;
};
...to :
class Whatever
{
public:
LPWSTR pInfo;
};
virtual void BeHappy() = 0;
|
|
|
|
|
Like I said a ComboBox adds information into Info so their is buffering problem!
So Info size has to be pointer to be sized for the ComboBox text.
|
|
|
|
|
LPWSTR* Info;
Info[n];
Info[n][m];
virtual void BeHappy() = 0;
|
|
|
|
|
But it's not a 2 dimensional array.
int **cha;
cha = new int[10];
for (int r = 0; r < 10; r++)
{
cha[r] = new int[10];
}
So how do you target a character I have to pass 2 locations to Info.
|
|
|
|
|
Yes, I was pointing out what was, not what should be and disagree with you anyway on that point.
char and wchar_t ultimately are just numbers and have no intrinsic meaning on their own--the compiler has no idea what encoding scheme you are using. Is it UTF-16BE, UTF-16LE? Even char doesn't imply what the code page is.
|
|
|
|
|
I want to use multiThread to read and write database,but I do not how how to prevent the thread from reading db again and again,
for example, I want use Thread1 to read record 1 - 100,and use Thread2 to read record 101-200,but I don`t know how to control different threads to read different data?
|
|
|
|
|
Thread synchronization is a big topic. Have a look at MSDN [^].
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|