|
|
Hello everyone,
Im creating an MFC app ( an SDI one ) that uses an explorer style User Interface. There are 3 "panes" in the Child View. All 3 of these "panes" are sized programmatically and are laid horizontally inside the Child View of the Main Frame. The "panes" are literally CWnd objects and are not CDialogs.
What I want is to have a splitter functionality that is quite similar to Visual Studio 2005 where the cursor icon changes to a "splitter sizing icon" when the mouse pointer hovers above the edges of two adjacent panes. And once you click on the edge of one of these panes, it should let the user drag and size up the panes dynamically.... jus like what happens in Visual Studio 2005.
How do I achieve this functionality without using a CSplitterWindow ? Cos I heard from one of ma colleagues say that u dont always need a CSplitterWindow to implement a Splitter functionality. Is it possible ? Please do give me some hints or advice and I will follow up your suggestions on MSDN and the like...
thanx a lot..
wishing u all a happy new year with loads of fun coding !
Eraj
-- modified at 0:39 Sunday 31st December, 2006
|
|
|
|
|
technojay wrote: Cos I heard from one of ma colleagues say that u dont always need a CSplitterWindow to implement a Splitter functionality.
You don't need to use anyone else's code to implement any functionality.
If you want it to look like VS splitters then you'll need to handle drawing the bars,
responding when the mouse is over the bars, dragging the bars for resizing, etc...all the
things that CSplitterWnd does for you.
You could also just use regular sizeable windows and anytime they are resized by the user then
you'd resize the other windows appropriately. it wouldn't look like VS splitters though
What part are you having trouble with?
Mark
|
|
|
|
|
Hey Mark,
Im quite new to MFC and this is kinda my first serious app that I was asked to do to get myself acquainted with it. So right now, although I understand the technique that you are suggesting, I am pretty clueless as to how Im gonna implement it ( for example : how to draw bars between adjacent windows, enabling them to be user dragged etc ).
I am not askin for code snippets or anything like that... All I need is jus a brief description of what type of controls would be needed, what MFC classes Ill have to bring in and any specific events that I mite need to handle. If you could give me that I can reference the MSDN and try it out.
hopin to hear from you soon.
Eraj
|
|
|
|
|
What I did myself:
- implement a separate window class; do the following:
- decides if is a vertical or horizontal splitter bar, and depending on it, registers window class using LoadCursor with IDC_SIZEWE or IDC_SIZENS (I don't remember the exact names, but should be ok)
- manages the draw part similar with MFC splitter (use an erase/redraw new pos. technique - study splitter code)
- maintains the distance from a border (say left border if is a vert. splitter)
- collaborate with parent window (read: send and receive size messages)
- handles mouse messages for left button down and up, mouse move and perform the necessary painting code.
|
|
|
|
|
for (int i = length - 1; i > -1 ; i--)
{
}
for (int i = length - 1; i >= 0; i--)
{
}
I always used to think the bottom way was slower then the top because i saw "i >= 0" as being two different checks being done on i.
For this reason I thought doing "i > -1" was better cause it was just one comparison... but today i just noticed that -1 might be an additional operation being done in each iteration of the for-loop like "...is i greater then (what is the negative of 1)".
So which is the faster way? :P
EDIT: Hmm maybe it still is the first way that is faster cause the negative number might be evaluated at compile-time?
|
|
|
|
|
The difference between those two, if there is any, will never be noticeable by people. Write whichever way makes sense. Assuming that code is looping over an array or other collection, I would always write i >= 0 because i is the array index and 0 is the logical stopping point.
|
|
|
|
|
FocusedWolf wrote: So which is the faster way?
So which is the faster way?
for (int i = length - 1; i >= 0; i--)
The processor has a comparison instruction that performs >= 0 in one step.
Either way there is not a lot of reason to optimize this type of code anymore as on modern processors most integer instructions (like compares) effectively take only 1 clock tick unless a branch mis prediction causes the pipeline to be emptied. In that case it depends on how long the pipeline is. Athlons/Athlon64 have pipelines of around 22 steps while Pentium IV chips have around 30 steps.
John
|
|
|
|
|
|
How to get a dialog size by ID?
|
|
|
|
|
I want to create a view by CFormView::Create(), set the Client area is in the function's fourth parameter, so I must know the view size.
|
|
|
|
|
Do mean size of dialog ? What about GetClientRect() ?
|
|
|
|
|
Basically what I'm trying to do is add the functionality to let the user select a JPEG background image for my game, as eye candy. MFC has functions for handling bitmaps but nothing for JPEGs or other image formats. I'd like to load a JPEG and convert it to a bitmap so that I can blit it as necessary. What is the best way to do this? I'd rather do it without tacking on a huge library to my program, if possible.
|
|
|
|
|
Look at the GDI+ library.
If you are aiming only at Windows XP, it ships with the DLL.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
You can use of CImage class for load jpg file.
|
|
|
|
|
CoffeeAddict19 wrote: I'd like to load a JPEG and convert it to a bitmap so that I can blit it as necessary.
If you use GDI+ it's pretty simple...
Gdiplus::Bitmap SrcBitmap(L"C:\\Images\\MyJPEG.jpg", FALSE);
HBITMAP hBitmap;
SrcBitmap.GetHBITMAP(Gdiplus::Color(0xFF,0xFF,0xFF), &hBitmap);
|
|
|
|
|
|
CoffeeAddict19 wrote: I'd like to load a JPEG and convert it to a bitmap so that I can blit it as necessary. What is the best way to do this? I'd rather do it without tacking on a huge library to my program, if possible.
http://www.codeproject.com/bitmap/extendedbitmap2.asp
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Re
|
|
|
|
|
Hello,
I need to write a simple program that does the following:
- Accept voice from microphone
- Determine the volume of the voice (programatically)
- Increase or decrease a variable based on the volume of the voice from the microphone.
I will appreciate any help in this regard. Please a source code supplied with it will also be very good.
Thanks alot.
Commickey
|
|
|
|
|
OK, you have some demo's in the msdn, you have to search for SAPI (Speech API).
I don't remember where I saw that exactly, but searching for SAPI must help you. if you don't find it, pleaqse tell it to me, I suppose that in a couple of days I'll be able to send something that I must have stored in some backups at home.
Hope this helps.
|
|
|
|
|
Hello Stuart,
I still cannot find it... can you help again as you said?
Greetings,
Commickey
|
|
|
|
|
You could search here on CP for "record sound" for some source code.
Mark
|
|
|
|
|
hello,
pls find me out why code is not work for solitaire game...
Thanks in advance.pls..
here is code:
#include<iostream>
using namespace std;
/*****CLASS PLAYING CARD*****/
class PlayingCard
{
private:
int rank;//integer 1-13
int suit;//integer0-3
char color;//red('r') or black('b')
public:
PlayingCard(int,int);
PlayingCard();
void display();
~PlayingCard();
const static int diamond;
const static int heart;
const static int spade;
const static int club;
};
/***** CLASS MAKING PILE OF CARDS*****/
class PileofCards
{
private:
PlayingCard *pile;//pointer to array of playing cards
int top;//last element added to array
int size;//no. of cards in pile
int position;//position of pile amongst others
public:
PileofCards(int,int);
~PileofCards();
PlayingCard Peek();
PlayingCard Remove();
void display();
void Add(PlayingCard);
bool IsEmpty();
bool IsFull();
};
/***** CLASS DECK OF CARDS*****/
class Deck
{
private:
PlayingCard *deck[52];
int size;
public:
Deck();
int getSize();
bool IsEmpty();
PlayingCard getCard(int i);
void Display();
PlayingCard removeCard(int i);
~Deck();
};
/*****CLASS SOLITIRE*****/
class Solitire{
private:
Deck deckofCards;
PileofCards shuffled;
public:
Solitire();
void shuffle();
void display();
};
Solitire::Solitire():shuffled(52,1)
{}
/*****INITIALIZING*****/
const int PlayingCard::diamond=0;
const int PlayingCard::heart=1;
const int PlayingCard::spade=2;
const int PlayingCard::club=3;
/*****CONSTRUCTOR PLAYING CARD*****/
PlayingCard::PlayingCard(int X,int Y)
{
rank=X;
suit=Y;
if(Y==0 || Y==1)
{
color='r';
}
else if(Y==2 || Y==3)
{
color='b';
}
else
{
cout<<"invalid suit,object not created"<<endl;
}
}
*****constructor="" overloaded*****=""
playingcard::playingcard()
{
}
="" *****destructor*****=""
playingcard::~playingcard()
{
}
="" pile="" of="" cards*****=""
pileofcards::pileofcards(int="" x,int="" y)
{
size="X;
position=Y;
pile=" new="" playingcard[size];
top="-1;//empty" array
}
=""
pileofcards::~pileofcards()
{
delete="" []="" pile;
}
="" *****is="" empty*****=""
bool="" pileofcards::isempty()
{
if(top="=-1)
{
cout<<"pile" empty"<<endl;
return="" true;
}
else
{
return="" false;
}
}
="" full*****="" pileofcards::isfull()
{
if(top="=size-1)
{
cout<<"sorry" cannot="" add="" since="" is="" full"<<endl;
return="" true;
}
else=""
{
return="" false;
}
}
="" *****adding="" playing="" card="" to="" the="" pile*****=""
void="" pileofcards::add(playingcard="" x)
{
if(!isfull())
{
pile[top+1]="X;
top++;
}
}
/*****REMOVING" from=""
playingcard="" pileofcards::remove()
{
if(!isempty())
{
top--;
}
return="" pile[top+1];
}
="" *****peeking="" top="" pileofcards::peek()
{
return="" [top];
}
="" *****display....playing="" card*****="" playingcard::display()
{
cout<<rank<<"="" "<<suit<<"="" "<<color<<endl;
}
="" deck*****=""
deck::deck()
{=""
int="" j="0;
for(int" i="1;i<=13;i++)
{
deck[j]=new" playingcard(i,playingcard::spade);
j++;
}
for(int="" k="1;k<=13;k++)
{
deck[j]=new" playingcard(k,playingcard::diamond);
j++;
}
for(int="" l="1;l<=13;l++)
{
deck[j]=new" playingcard(l,playingcard::heart);
j++;
}
for(int="" m="1;m<=13;m++)
{
deck[j]=new" playingcard(m,playingcard::club);
j++;
}
int="" size="52;
}
/*****DESTRUCTOR"
deck::~deck()
{
if(!isempty())
{
for(int="" deck[i];
}
}
}
else=""
{
delete="" deck;
}
}
="" *****get="" size*****="" deck::getsize()
{
return="" size;
}
="" empty....deck*****="" deck::isempty()
{
if(getsize()="=0)
{
return"
return="" false;
}
="" *****getcard*****="" deck::getcard(int="" j)
{
return="" *deck[j];
}
="" *****display....deck*****="" deck:display()
{
for(int="">display();
}
}
/*****REMOVE...DECK*****/
PlayingCard Deck::removeCard(int i)
{
PlayingCard temp;
temp=getCard(i);
delete deck[i];
if(!IsEmpty())
{
for(int j=i;j<size;j++)
{
deck[j]=deck[j+1];
}
}
size--;
return temp;
}
="" *****shuffle*****=""
void="" solitire::shuffle()
{
int="" i;=""
while="" (!deckofcards.isempty())
{
i="rand()%deckofCards.getSize();"
="" cout<<"remove="" card="" \n";
shuffled.add(deckofcards.removecard(i));
}
}
="" *****display...solitire*****="" solitire::display()
{
if(!shuffled.isempty())
{
shuffled.display();
}
}
="" *****display...pile="" of="" cards*****="" pileofcards::display()
{=""
int="" i="0;
while(i<=top)
{
pile-">display();
i++;
pile++;
}
cout<
|
|
|
|
|
|
Sorry for that.. Thanks for remind me..
when I ran that code .. I got three error.. might be it from Deck..
Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error 2 error C2063: 'Deck::deck' : not a function
Warning 3 warning C4154: deletion of an array expression; conversion to pointer supplied
|
|
|
|