|
Hi,
I'm just looking for some advice on where to start.. I have a list control and with in the control I have "n" numbers of items, each item has a different value of time.. eg (140 seconds, 300 seconds etc..). I need to use a timer to count down each item until it reaches 0.. The problem is I never know how many items will be in the list so I can't pre-define all my variables.. any ideas on where to start?
Thanks,
B0neHead
|
|
|
|
|
Never mind i figured it out.
B0neHead
|
|
|
|
|
OK, here's my situation...
I'm creating a bitmap keypad, where the color of the buttons change as the user moves their mouse over. The image doesn't appear to change. Can anyone see what I'm missing here. Sorry this is so long.
Thanks in advance for any help...
==============================================================
I store the two BMP's as CBitmap's member variables... also I have their respective DC's
class CKeypadView : public CView
{
....
CBitmap m_kpBitmap; // scratchpad bmp
CBitmap m_kpEnabled; // all keys w/no mouseover (blue)
CBitmap m_kpMouseOver; // all keys w/mouseover (yellow)
CDC m_kpBitmapDC;
CDC m_kpEnabledDC;
CDC m_kpMouseOverDC;
CRgn m_rgnKey[18]; // stores the key regions
....
}
In the constructor, I define the key regions and load the BMPs...
CKeypadView::CKeypadView()
{
m_rgnKey[OES_KEY_01].CreateRectRgn( 3, 102, 48, 132);
m_rgnKey[OES_KEY_02].CreateRectRgn( 51, 102, 96, 132);
m_rgnKey[OES_KEY_03].CreateRectRgn( 99, 102, 144, 132);
m_rgnKey[OES_KEY_04].CreateRectRgn( 3, 69, 48, 99);
.......
m_kpEnabled.LoadBitmap(IDR_KEYPAD_MOUSENORM);
m_kpMouseOver.LoadBitmap(IDR_KEYPAD_MOUSEOVER);
}
In OnCreate, I set up the utulity bmp, and associate the DCs...
int CKeypadView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
CClientDC dc(this);
// get the size and pallete for the utility bitmap
BITMAP bits;
m_kpEnabled.GetObject( sizeof(BITMAP), &bits );
CRect rcKP(0,0,bits.bmWidth,bits.bmHeight);
// setup the utility bitmap
m_kpBitmap.CreateCompatibleBitmap( &dc, rcKP.Width(), rcKP.Height() );
m_kpEnabledDC.CreateCompatibleDC(&dc);
m_kpMouseOverDC.CreateCompatibleDC(&dc);
m_kpBitmapDC.CreateCompatibleDC(&dc);
m_kpEnabledDC.SelectObject( &m_kpEnabled);
m_kpMouseOverDC.SelectObject( &m_kpMouseOver);
m_kpBitmapDC.SelectObject( &m_kpEnabled);
return 0;
}
When the user moves the cursor over a key on the bmp keypad, I want that key to be BitBlt'd with the key of the "mouseover" bmp....
// ==================================================================
void CKeypadView::OnMouseMove(UINT nFlags, CPoint point)
{
CRect rctKeyRgn; // stores the region of the mouse cursor
CClientDC dc(this);
CRect rect;
GetClientRect( &rect );
// find which key it is over (if any)
for( int iKey=OES_KEY_01; iKey<=OES_KEY_ALL; iKey++)
{
if( m_rgnKey[iKey].PtInRegion(point) )
{
int nRgnBoxResult = m_rgnKey[iKey].GetRgnBox( &rctKeyRgn );
ASSERT( nRgnBoxResult != ERROR || nRgnBoxResult != NULLREGION );
// copy the normal keypad to the utility bmp
m_kpBitmapDC.BitBlt( 0,
0,
rect.Width(),
rect.Height(),
&m_kpEnabledDC,
0,
0,
SRCCOPY );
// copy only the region that the mouse is over
m_kpBitmapDC.BitBlt( rctKeyRgn.left,
rctKeyRgn.top,
rctKeyRgn.Width(),
rctKeyRgn.Height(),
&m_kpMouseOverDC,
rctKeyRgn.left,
rctKeyRgn.top,
SRCCOPY );
CRect rect;
GetClientRect( &rect );
// output the bmp to the view
dc.BitBlt( 0,
0,
rect.Width(),
rect.Height(),
&m_kpBitmapDC,
0,
0,
SRCCOPY );
continue; // break out of loop
}
}
CView::OnMouseMove(nFlags, point);
}
------------------------------------------------
I am not discouraged because every wrong attempt discarded is another step forward
-- Thomas Edison --
|
|
|
|
|
What I would is rearrange your code a bit. Place all drawing code in the OnDraw handler. Use a state variable for each key to signify whether it is up, down, or under the cursor. The OnMouseMove and OnLButtonDown functions are then used to determine the state of the key. This could help you untangle your problem.
|
|
|
|
|
You know what... I like your structure muuuuch better. Thanks for untangling this web.
Mark
------------------------------------------------
I am not discouraged because every wrong attempt discarded is another step forward
-- Thomas Edison --
|
|
|
|
|
I am glad I could help.
PS: remember to Invalidate the key's rectangle when it changes state.
|
|
|
|
|
Here's what I think:
1) I assumed that all coordinates are in client coordinates not screen.
m_rgnKey[OES_KEY_01].CreateRectRgn( 3, 102, 48, 132); and etc.
thus, this line is reached:
int nRgnBoxResult = m_rgnKey[iKey].GetRgnBox( &rctKeyRgn );
2) I am not sure that your bitmap has the same size than the screen. Use StretchBlt function
when source and destination rectangle are different size
3) Note: You have twice "CRect rect" in your code
4) continue; // break - does not break, the loop continue...
5) Do not select the same bitmap to two different device context
6) What your OnDraw look like?
good luck
|
|
|
|
|
Ernest,
I'm going to follow your items here...
1) The code that I used to determine the region appears to work fine.
2) I don't think I need the StretchBlt function, because the source and destination (almost) the same size.
3) As you can see, this was a bit of a copy paste. It's now fixed.
4) You're right on the 'continue' statement oversight... thanks.
5) As for the OnDraw code it doesn't look like much yet.
Thanks for the help. If you want, stay posted to this thread. I'm bound to run into something else.
Mark
------------------------------------------------
I am not discouraged because every wrong attempt discarded is another step forward
-- Thomas Edison --
|
|
|
|
|
I am new to C, and I have some questions about data types that I would really like answered.
What is the difference between using "const" and not using it, e.g. "const char" versus "char"?
What is the difference between "const" and "static"?
What is the difference between using "const" and "#define"?
|
|
|
|
|
'const' tells the compiler that you won't change the value. if you try to, the compiler will complain.
in C, static, when applied to variables means the item is only visible in the current module (source file) and that the value will persist between function calls.
when applied to functions, static means the function is only visible within the current module. in C++, static takes on the job of declaring member functions that can be used outside of an instance of the class ('extern' would've been a better word for this, IMO).
#define is a preprocessor thing, const is a compiler thing. #define is an alias for some text which the preprocessor will swap out before the compiler gets to it. const is just a way to make a variable 'constant' (an oxymoron).
-c
Smaller Animals Software, Inc.
|
|
|
|
|
Thanks for the reply. I have a couple of followup questions though to help me clarify things.
Chris Losinger wrote:
in C, static, when applied to variables means the item is only visible in the current module (source file) and that the value will persist between function calls.
Isn't this normally true anyway (at least the first part) unless "extern" is used?
Chris Losinger wrote:
#define is a preprocessor thing, const is a compiler thing. #define is an alias for some text which the preprocessor will swap out before the compiler gets to it. const is just a way to make a variable 'constant' (an oxymoron).
So, when would one use something like
#define CPUSTRING "Intel - x86"
versus
const char CPUSTRING[] = "Intel - x86";
? CPUSTRING is a const char in either case, right?
|
|
|
|
|
Stu Pedful wrote:
CPUSTRING is a const char in either case, right?
CPUSTRING is not a const char, just a bunch of text. if you have a small program:
#define CPUSTRING "Intel - x96"
#define SQUARE(x) x*x
main()
{
CallTextFunction(CPUSTRING);
CallNumberFunction(SQUARE(3+4));
}
The precompiler will change your program into this before compiling:
main()
{
CallTextFunction("Intel - x96");
CallNumberFunction(3+4*3+4);
}
Note that defines just replaces text, it is not typechecked, and might give some odd results as SQUARE did above. If you want a working version of SQUARE, it could be defined as:
#define SQUARE(x) ((x)*(x))
/moliate
|
|
|
|
|
Ah, I undertand. Thanks for the terrific example.
|
|
|
|
|
Stu Pedful wrote:
Isn't this normally true anyway (at least the first part) unless "extern" is used?
No.
Say you declare a variable or function at file scope inside A.cpp:
int nTest = 0;
void foo()
{
}
Then you go to file B.cpp and do the same thing:
int nTest = 0;
void foo()
{
}
When you go link these two files to create the final executable, the linker will complain that you've multiply defined the same variable and function. Thus, the variable and function in A.cpp are treated as "global" by the linker. When it then sees them also defined in B.cpp, it errors out.
This is different than going to B.cpp and declaring the variable and function extern.
extern int nTest;
extern void foo();
In that case, the linker uses the ones defined globally in A.cpp.
To finish my point, by making the variable and function "static", the linker ties them to the files themselves and does not treat them as globals.
static int nTest = 0;
static void foo()
{
}
This allows them to be redefined in multiple files without duplicity.
Regards,
Alvaro
|
|
|
|
|
Thanks for the reply. I would like you to clarify a couple of points though.
Alvaro Mendez wrote:
extern int nTest; extern void foo();
In that case, the linker uses the ones defined globally in A.cpp.
To finish my point, by making the variable and function "static", the linker ties them to the files themselves and does not treat them as globals.
If all variables and functions that are not declared as "static" are automatically treated as global, then what is the purpose of "extern"? I was under the impression that extern was necessary for the value of a variable or function to persist across multiple source files. Is this true or no? And, how and when is "extern" used? If I wanted a variable or function to persist across multiple source files, would I just declare and define it in one of the source files and then put "extern <datatype> <variable name="">" in one of the common header files included at the top of each source files? Or is "extern" unnecessary in that case?
|
|
|
|
|
Remember that everything in C must be declared. If you want to use a variable defined in another file, you need to declare it in yours as extern. That's what extern is for: to tell the current file that you're using a variable defined somewhere else. If you don't use the extern keyword, the compiler thinks that you're defining it in that file.
Note that the extern keyword is only necessary for global variables. Functions don't really need it since the compiler can tell that you're not defining them by the fact it's a prototype with no body.
So, to sum it up, the extern keyword is necessary for a variable (not just its value) to be made visible across multile files.
Regards,
Alvaro
|
|
|
|
|
What's the easiest way to build an application with the look and feel of an MMC? I don't need any snap-ins. I need the look and feel plus the treeview on the left hand side and listview on the right hand side.
|
|
|
|
|
|
I have created a project a while back.. anyway, I selected not to have active x objects in my project.. now a few weeks later I decided that I need to put an active x object into my dialog project.. but when I put the object into the project the dialog box will no longer appear when its launched.. any ideas?
If I remove the object the dialog box will appear.. its a Microsoft web browser active x object.
Thanks
Rob
|
|
|
|
|
Or The activex is not registered or you forgot to add AfxOleInit() in the InitInstance of your project....
Best Regards
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
Hi, veterans, how can I delete a character in CRichEditView?
|
|
|
|
|
First you need to use CRichEditCtrl::SetSel and select the text or character that you need to delete, then CRichEditCtrl::ReplaceSel replazing your selection for "" and ready
Best Regards!!
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
Thanks, Carl, this is great.
|
|
|
|
|
i have a dialog that looks like this:
+-------------+
| +---------+ |
| | A | |
| +---------+ |
| |
| +---------+ |
| | B | |
| +---------+ |
+-------------+
A and B are static frames that may hold other controls.
i want to be able to dynamically resize it so that it is either just big enough to hold the "A" rectangle or big enough to hold both A and B. to keep it easy, the width never changes.
so, what's the secret to getting the height correct? i'm doing this:
CRect dispRect;
m_dispBox.GetWindowRect(dispRect);
ScreenToClient(dispRect);
dispRect.NormalizeRect();
CRect normalRect;
m_normalFrame.GetWindowRect(normalRect);
ScreenToClient(normalRect);
normalRect.NormalizeRect();
int w = normalRect.left + normalRect.Width() + GetSystemMetrics(SM_CXDLGFRAME) * 2;
int h = normalRect.top + normalRect.Height() + GetSystemMetrics(SM_CYDLGFRAME) * 2;
if (bShow)
{
h += dispRect.Height();
h += (dispRect.top - normalRect.bottom);
}
SetWindowPos(&wndTop, 0,0, w, h, SWP_NOMOVE | SWP_NOZORDER);
but the dialog is just a little bit too small to hold the bottom frame. - the bottom frame's bottom is clipped.
-c
Smaller Animals Software, Inc.
|
|
|
|
|
I prefer to use GetWindowPlacement and SetWindowPlacement when I work with resize of controls...
Best Regards
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|