|
Suppose we have a number of type DWORD and we want to extract four 6-bit number and a byte from it. Some thing like this:
(DWORD) ---> 10100101101000110100011010101001
(Result) ---> 101001 011010 001101 000110 10101001
If you want to introduce me 'Bit Field Operators', be aware! It does NOT work in this manner.
Thank you masters!
|
|
|
|
|
Just shift and mask it?
the byte: dword & 0xFF
last 6bit value: (dword >> 8) & 0x3F
next 6bit value: (dword >> 14) & 0x3F
etc?
Would that work?
|
|
|
|
|
Possibly another approach is to use union. Just check the following code snippet.
#pragma pack(1)
union DWordParser
{
DWORD DwordValue;
BYTE Bytes[4];
};
DWordParser Parser;
Parser.DwordValue = 255;
BYTE ThirdByte = Parser.Bytes[2] & 0x3F;
But you have to sacrifice performance for readability.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Can you explain why you feel that bit fields won't work for you?
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
krmed wrote: Can you explain why you feel that bit fields won't work for you?
I'm guessing it's because he didn't know how to use them properly.
|
|
|
|
|
Hi all,
I have a multithreaded application written in c++ vs6.
I try to create a new dialog within an existing dialog in that application and when i call
ShowWindow(SW_SHOW)for the new dialog it doesnt do anything.
If i put a break point there, it seems that it stops in the call to ShowWindow and doesnt continue the execution.
Can someone explain this strange behavior and suggest a way to overcome this problem?
Thanks
Simon.
|
|
|
|
|
All these dialogs are created on the same thread?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: All these dialogs are created on the same thread?
ddd_shocron wrote: I try to create a new dialog within an existing dialog
Doesn't that tell you exactly what is being done? It's created within
led mike
|
|
|
|
|
|
yes all these dialogs are created in the same thread.
To be more precise i call the create function for that dialog in the ctor of the containing dialog
and i call the ShowWindow(SW_SHOW) from within the OnInitDialog ,just before
i return true for the OnInitDialog.
dj4400 formerly known as ddd_shocron
modified on Thursday, January 1, 2009 3:14 AM
|
|
|
|
|
dj4400 wrote: i call the create function for that dialog in the ctor of the containing dialog
If the containing dialog is used as the parent for the created dialog,
then that may not work - the parent dialog window (HWND) hasn't been created yet
at that point.
Try calling create for the child dialog in the parent's OnInitDialog() (after calling
the base class' OnInitDialog()).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark, you are right - i called the create function in the OnInitDialog and then it worked properly.
|
|
|
|
|
dear all
any problem? i couldn't find. thanks a lot
void CMeiTengDlg::OnPause()
{
if(Pause)
{
m_Pause.SetWindowText("Pause");
MCIWndResume(m_Video);
Pause = FALSE;
}
else
{
m_Pause.SetWindowText("UnPause");
MCIWndPause(m_Video);
Pause = TRUE;
}
}
void CMeiTengDlg::OnBrowse()
{
m_Video = NULL;
if(m_Video == NULL)
{
CFileDialog avi(TRUE,NULL,NULL,OFN_HIDEREADONLY,"MP3 Files (*.mp3)|*.mp3|AVI Files(*.avi)|*.avi|");
if(avi.DoModal() == IDOK)
{
m_Path = avi.GetPathName();
UpdateData(FALSE);
}
}
}
the resilt of compiling:
MeiTengDLg.cpp
.\MeiTengDLg.cpp(235) : error C2664: 'CWnd::SetWindowTextW' : cannot convert parameter 1 from 'const char [6]' to 'LPCTSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\MeiTengDLg.cpp(241) : error C2664: 'CWnd::SetWindowTextW' : cannot convert parameter 1 from 'const char [8]' to 'LPCTSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\MeiTengDLg.cpp(277) : error C2664: 'CFileDialog::CFileDialog(BOOL,LPCTSTR,LPCTSTR,DWORD,LPCTSTR,CWnd *,DWORD,BOOL)' : cannot convert parameter 5 from 'const char [48]' to 'LPCTSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Build log was saved at "file://c:\Documents and Settings\ZhiYuan Li\Desktop\MeiTeng\MeiTeng\Release\BuildLog.htm"
MeiTeng - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
|
|
|
|
I think you've enabled unicode in your project settings. Enclose all your strings inside _T() macro like as follows, so that they will switch accordingly to either ansi or unicode strings.
m_Pause.SetWindowText( _T("Pause") );
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Hi,
How to delete command bar controls of excel in c++?
I know when we automate excel, there is a functin GetCommandBars().
I dont know how to use this? Anyone has idea?
|
|
|
|
|
|
Hi all,
I have a doubt regarding window graphics painting.
As we already know we can draw a rectangle in window.
Ok...
Suppose I am drawing a rectangle with values ( 0, 0, 100, 100 ).
Now my question is,
can I draw a rectangle with values (0.5, 0.75, 100.1, 100.4) or something like that.
Why I am asking because, according to my understanding pixel is the smallest possible drawing resolution.
If it is possible, could you please help to implement that?
Regards,
Krishnakumar
|
|
|
|
|
GDI primitives accept only integers. You may use GDI+ (see for instance [^]).
Krishnakumartg wrote: Why I am asking because, according to my understanding pixel is the smallest possible drawing resolution.
The above is obviously true. GDI+ just gives a level of abstraction.
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]
|
|
|
|
|
Tried the following code.
CDC* pDC = m_Window.GetDC();
Graphics graphic( pDC->GetSafeHdc());
CRect wRect;
m_Window.GetClientRect( &wRect );
wRect.DeflateRect( 0, 0, 1, 1 );
RectF rect( wRect.left, wRect.top, wRect.Width(), wRect.Height());
Color color;
color.SetFromCOLORREF( RGB( 100, 0, 0 ));
Pen pen( color );
graphic.DrawRectangle( &pen, rect );
rect.Inflate( -0.5, -0.5 );
Color color2;
color2.SetFromCOLORREF( RGB( 0, 100, 0 ));
Pen pen2( color2 );
graphic.DrawRectangle( &pen2, rect );
But the graphic.DrawRectangle( &pen2, rect ); draws the rectangle in the next pixel.
Is there anything additional to do to work the floating points?
regards,
Krishnakumar
|
|
|
|
|
Do you want to break the pixel?
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]
|
|
|
|
|
CPallini wrote: Do you want to break the pixel?
You can do it, but the stuff that oozes out will make the image blurry...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: You can do it, but the stuff that oozes out will make the image blurry..
If so, what is the change I should make in my code?
Regards,
Krishnakumar
|
|
|
|
|
Krishnakumartg wrote: If so, what is the change I should make in my code?
You'll need to include schematics in your comments on how to build a tiny hammer. Then you'll be able to break just one pixel.
|
|
|
|
|
Nah: the pixel is the atomic graphic unit and, you known, the atom is indivisible...oops
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]
|
|
|
|
|
Don't believe the physicists... You crack open a pixel it oozes GUI goodness!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|