|
C++ Hacker wrote: Should it be 1) or 2) and why?
I would expect #2. I've seen other apps do this so I am already familar with it.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
2) Is confusing for the user if more than one/two/three controls are behind the tab control in tab order.
Andreas.
|
|
|
|
|
How to get the system Clock Style, I mean weather it 12 hr clock style or 24 hr clock style.
Thanks.
|
|
|
|
|
The system clock does not have a style it is merely a counter used to calculate the current time since some predefined date. However any clock displays used in Windows will access the regional settings to determine how such times should be displayed. I am not sure of the simple way to access the details but you could take a look at the HKEY_CURRENT_USER\Control Panel\International registry key.
It's time for a new signature.
|
|
|
|
|
Try it :
bool GetTimeFormattedBySystem(const SYSTEMTIME& sSomeTime,
CString& cszReceiver)
{
static const int iTimeStrLen(40);
static TCHAR szResult[iTimeStrLen];
cszReceiver.Empty();
if (GetTimeFormat(LOCALE_USER_DEFAULT,
0,
&sSomeTime,
NULL,
szResult,
iTimeStrLen)) {
cszReceiver = szResult;
}
return (0 < cszReceiver.GetLength());
}
virtual void BeHappy() = 0;
|
|
|
|
|
Have you tried GetLocaleInfo(LOCALE_ITIME) ?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
This is my post accidently put in the lounge...
>>>>
This should be pretty easy, right? I'm feeling pretty brain dead right now, though...
In CTreeCtrl the nodes have a DWORD data item and I want to make use of that as a 24 bit value and an 8 bit value. What would be a nice way of getting and setting the DWORD from two other variables?
Thanks,
Ben.
<<<<
Anyway I'm thinking something like (in pseudocode...)
getting...
8bitVal = DWordVal mod 2**24
32bitVal = DWordVal / 2**24
setting...
DWordVal = 24bitVal * 2**24 + 8bitVal
I haven't tried this so is probably wrong and I have a feeling that that there is a nicer way of doing it?
|
|
|
|
|
How about
DWORD dwData = <value>;
DWORD dwEightBit = (dwData & 0x000000FF);
DWORD dwTwentyFourBit = (dwData & 0xFFFFFF00) >> 8;
and
DWORD dwEightBit = <value1>;
DWORD dwTwentyFourBit = <value2>;
DWORD dwData = (dwTwentyFourBit << 8) | dwEightBit;
This has just been typed in, not compiled or tested, you understand. The second code snippet assumes value1 <= 255 and value2 <= 16777215.
|
|
|
|
|
Thanks very much for this. I will have a good look at this later. I'm out of time now. My programming shift is 8am to 8.30am. Have to get myself to the checkouts at the supermarket for my day job now!
|
|
|
|
|
This has been very helpful to me. Thanks very much. Somehow the world of bitwise operations was eluding me that morning!
|
|
|
|
|
Oh god, I know I'm confused. Loads of mistakes. I know. Rather than edit my previous post here are my own ammendments...
If the 24 bit value are the high end bits and the 8 bit value are the low end bits...
getting...
8bitVal = 32bitVal mod 2**8
24bitVal = 32bitVal / 2**8
setting...
32bitVal = 24bitVal * 2**8 + 8bitVal
Still think there may be an easier way of doing this...
|
|
|
|
|
Ben Aldhouse wrote: Still think there may be an easier way of doing this.
Yes, don't go in for complex mathematical expressions, even though the compiler will optimise them. Reread the previous answer and adjust for whichever part is the 8-bit and whichever is the 24-bit. In either case just use simple shifts AND and OR operators thus:
DWORD dwValue = (bits8 << 24) | bits24;
DWORD dwValue = (bits24 << 8) | bits8;
And to split
bits8 = dwValue & 0xFF;
bits24 = dwValue >> 8;
bits24 = dwValue & 0xFFFFFF;
bits8 = dwValue >> 24;
It's time for a new signature.
|
|
|
|
|
Oops - I accidentally gave you a 1 vote instead of a 5. I can't see how to undo a vote!
Sorry.
(OK, looks like I fixed it. I just voted again, giving 5 - that seems to have incremented the vote count but replaced my previous vote. Good.)
|
|
|
|
|
Yep, looks OK now; many thanks for taking the trouble to vote.
It's time for a new signature.
|
|
|
|
|
Thanks for this! Your reply is very much appreciated!
|
|
|
|
|
You're welcome, good luck with your programs.
It's time for a new signature.
|
|
|
|
|
Another option (provided you don't want to transmit your packed 32 bit values to another machine) is to use a union with a set of bit-fields:
union tree_ctrl_item
{
DWORD packed_;
struct
{
DWORD bits_24_ : 24;
DWORD bits_8_ : 8;
}
unpacked_;
};
Then you can use the packed and unpacked forms as ordinary structure members and add member functions for construction and extraction of values if you feel so inclined.
There are numerous "here be dragons" caveats with this but provided you're consistent in the usage it'll be portable if not binary compatible.
Cheers,
Ash
|
|
|
|
|
hi guys, i have problem on my GDI drawing (car) when i try to add a button control or any other control, i lose the focus of my drawing.
here is the scenario,
when i press SPACE my car moves forward frm left to right.
but when i tried adding a button for colorPicker purpose, mar car won't move when i try to press SPACE on my ketborad.. tried to remove the button it worked fine.
how do i set the focus to my GDI car drawing after selecting a color of the car?
or should i say what code to use?
i tried to use
CWnd* pWnd = myCar.rec;
pWnd->SetFocus();
obviously it's error
\lg.manuel\daily quests\gdicarsample\gdicarsample\gdicarsampledlg.cpp(115) : error C2440: 'initializing' : cannot convert from 'CRect' to 'CWnd *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
since car is Crect i can't pass it to CWnd to set the focus,
thanks ahead guys,
|
|
|
|
|
How did you handle SPACE key press?
The focus may be on button and abviously it will take the SPACe key input. In OnButtonClick handler, To kill focus from button, call SetFocus() on main parent window. You may use like this->SetFocus().
|
|
|
|
|
here is my code for SPACE bar hanlder
CGDICarSampleDlg.cpp
void CGDICarSampleDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar == 8) {
myCar.Backward();
Invalidate();
}
else if (nChar == 32) {
myCar.Forward();
Invalidate();
}
else if (nChar == 80){
CColorDialog dlg;
if (dlg.DoModal() == IDOK)
{
color = dlg.GetColor();
}
red = GetRValue(color);
green = GetGValue(color);
blue = GetBValue(color);
char rr[32];
itoa(red, rr, 10);
r = rr;
char gg[32];
itoa(green, gg, 10);
g = gg;
char bb[32];
itoa(blue, bb, 10);
b = bb;
myCar.m_brCar.Detach();
myCar.m_brCar.CreateSolidBrush(RGB(red, green, blue));
WritePrivateProfileString("car", "red", r, "car.ini");
WritePrivateProfileString("car", "green", g, "car.ini");
WritePrivateProfileString("car", "blue", b, "car.ini");
myCar.PickColor();
Invalidate();
}
else {
TRACE( "others" );
}
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
and here is the command triggered
Car.cpp
void CCar::Forward()
{
m_nCarX += 5;
angleFlag = angleFlag + 1;
}
void CCar::Backward()
{
m_nCarX -= 3;
angleFlag = angleFlag - 1;
}
if i SetFocus on the Main Dlg Window, will it kill the focus of the button?
|
|
|
|
|
One option is to allow the user to trigger the colour pick button by mouse click only. On Key down events, process the movements of your car. Override PreTranslateMessage() of your window to handle all key down events.
void CGDICarSampleDlg::OnBnClickedButtonColour()
{
}
BOOL CGDICarSampleDlg::PreTranslateMessage(MSG* pMsg)
{
if(WM_KEYDOWN == pMsg->message)
{
KeyDownHandler(pMsg->wParam);
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}
void CGDICarSampleDlg::KeyDownHandler(UINT nChar)
{
if (nChar == 8)
{
}
else if (nChar == 32)
{
}
}
|
|
|
|
|
i just tried this code:
BOOL CGDICarSampleDlg::PreTranslateMessage(MSG* pMsg)
{
if(WM_KEYDOWN == pMsg->message)
{
OnKeyDown(pMsg->wParam);
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}
got an error saying
error C2660: 'CGDICarSampleDlg::OnKeyDown' : function does not take 1 arguments
maybe because OnKeyDown needs three not just one, on my code below notice that the OnKeyDown event has 3 return values,.
CGDICarSampleDlg.cpp
void CGDICarSampleDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar == 8) {
myCar.Backward();
Invalidate();
}
else if (nChar == 32) {
myCar.Forward();
Invalidate();
}
else {
TRACE( "others" );
}
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
declaration of OnKeyDown ...
CGDICarSampleDlg.h
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
|
|
|
|
|
hey that is not the WM_KEYDOWN message handler. You don't need it anymore.
BOOL CGDICarSampleDlg::PreTranslateMessage(MSG* pMsg)
{
if(WM_KEYDOWN == pMsg->message)
{
KeyDownHandler(pMsg->wParam);
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}
void CGDICarSampleDlg::KeyDownHandler(UINT nChar)
{
if (nChar == 8)
{
}
else if (nChar == 32)
{
}
}
|
|
|
|
|
yup i did that already but it seems that i still get the same error..
KeyDownHandler does not take 1 argument...
you might want to check the sample project, here's the link and take a look... i did not include the button yet.. run and see..
http://hotfile.com/dl/68100441/675ae33/GDICarSample.rar.html[^]
meybe am just too dumb to get your point, haha, sory..
take a peek at my code to understand what i want do do.. thanks for help man, appreciate it.
modified on Monday, September 13, 2010 11:56 PM
|
|
|
|
|