|
We are all familiar with the sizeof operator, but is there an operator to get the offset of a structure member within the structure?
Example:
struct SampleStruct
{
DWORD Member1;
DWORD Member2;
}
DWORD Result = offset(SampleStruct.Member2)
I need something that would work with bit fields as well.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
How about:
DWORD Result = &SampleStruct.Member2 - &SampleStruct.Member1;
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Yeah, that would work with most types, but not bit fields. It gives an error if you try to take the address of a bit field.
I was hoping that there might be an operator.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Pretty sure there's no simple operator for what you want, you're going to have to make your own.
|
|
|
|
|
Try offsetof[^].
Since bits are not addressable I don't think you will find anything for them.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Richard MacCutchan wrote: Try offsetof[^].
Hooray!! Thanks for that.
I'll have to compute bit fields myself.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard Andrew x64 wrote: I'll have to compute bit fields myself.
Emphasizing what was already said - you cannot address a bit field.
The syntax that does that in the language uses an address AND bit manipulation.
|
|
|
|
|
Yup, that was understood.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
re bit fields:
The standards (C and C++) explicitly state that the address-of & operator cannot be applied to bit fields, and consequently there are no pointers to bit fields.
Given that the layout of bit fields within some integral type is implementation-dependent, that all makes a lot of sense.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Not really anything to do with the language, more the fact that the hardware cannot do it.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I'm not really sure this deserves the joke icon.
What a surprise! Language standards reflecting hardware reality!
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
No, I think the joke icon is well deserved.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
#define EA {B11110000,B01001000,B01001000,B01111000,B01001000,B11001000}
#define EB {B11110000,B01001000,B01001000,B01111000,B01001000,B11110000}
#define EC {B11110000,B10010000,B10111000,B10000000,B10010000,B11110000}
#define ES {B11111000,B10011000,B10000000,B11111000,B00001000,B11111000} // END1
#define UA {B01110000,B11001000,B11001000,B11111000,B11001000,B11001000}
#define UB {B11110000,B11001000,B11001000,B11111000,B11001000,B11110000}
#define UC {B01110000,B11001000,B11000000,B11001000,B11001000,B01110000}
#define UD {B11110000,B11001000,B11001000,B11001000,B11001000,B11110000}
#define UE {B11111000,B11111000,B11000000,B11111000,B11000000,B11111000}
#define UF {B11111000,B11000000,B11000000,B11111000,B11000000,B11000000}
#define UG {B11111000,B11001000,B11000000,B11011000,B11001000,B11111000}
#define UH {B11001000,B11001000,B11001000,B11111000,B11001000,B11001000}
#define UI {B11111000,B01110000,B01110000,B01110000,B01110000,B11111000}
#define UJ {B11111000,B00110000,B00110000,B10110000,B10110000,B11110000}
#define UK {B11001000,B11010000,B11100000,B11100000,B11010000,B11001000}
#define UL {B11000000,B11000000,B11000000,B11000000,B11000000,B11111000}
#define UM {B11011000,B11111000,B10101000,B10101000,B10001000,B10001000}
#define UN {B10001000,B11001000,B11101000,B11111000,B11011000,B11001000}
#define UO {B11111000,B11001000,B11001000,B11001000,B11001000,B11111000}
#define UP {B11110000,B11001000,B11001000,B11110000,B11000000,B11000000}
#define UQ {B11111000,B11111000,B10001000,B10101000,B10010000,B11101000}
#define UR {B11110000,B11001000,B11001000,B11110000,B11010000,B11001000}
#define US {B11111000,B11001000,B11000000,B11111000,B00011000,B11111000}
#define UT {B11111000,B10101000,B00100000,B00100000,B00100000,B01110000}
#define UU {B11001000,B11001000,B11001000,B11001000,B11001000,B11111000}
#define UV {B11001000,B11001000,B11001000,B11011000,B01110000,B00100000}
#define UW {B10001000,B10001000,B10101000,B10101000,B11011000,B10001000}
#define UX {B10001000,B11011000,B00100000,B00100000,B11011000,B10001000}
#define UY {B10001000,B11011000,B01010000,B00100000,B00100000,B01110000}
#define UZ {B11111000,B10001000,B00010000,B00100000,B01001000,B11111000} // ends here
#define BA {B01110000,B10001000,B10001000,B11111000,B10001000,B10001000}
#define BB {B11110000,B10001000,B10001000,B11110000,B10001000,B11111000}
#define BC {B11111000,B10000000,B10000000,B10000000,B10000000,B11111000}
#define BD {B11110000,B10001000,B10001000,B10001000,B10001000,B11110000}
#define BE {B11111000,B10000000,B10000000,B11110000,B10000000,B11111000}
#define BF {B11111000,B10000000,B10000000,B11110000,B10000000,B10000000}
#define BG {B01110000,B10001000,B10000000,B10011000,B10001000,B01110000}
#define BH {B10001000,B10001000,B11111000,B10001000,B10001000,B10001000}
#define BI {B11111000,B00100000,B00100000,B00100000,B00100000,B11111000}
#define BJ {B00111000,B00010000,B00010000,B00010000,B10010000,B01100000}
#define BM {B10001000,B11011000,B10101000,B10101000,B10001000,B10001000}
#define BN {B10001000,B11001000,B10101000,B10101000,B10011000,B10001000}
#define BL {B10000000,B10000000,B10000000,B10000000,B10000000,B11111000}
#define BO {B01110000,B10001000,B10001000,B10001000,B10001000,B01110000}
#define BP {B11110000,B10001000,B10001000,B11110000,B10000000,B10000000}
#define BQ {B01110000,B10001000,B10101000,B10011000,B01111000,B00001000}
#define BR {B11110000,B10001000,B10001000,B11110000,B10001000,B10001000}
#define BS {B01110000,B10001000,B01100000,B00010000,B10001000,B01110000}
#define BK {B10001000,B10010000,B11100000,B11100000,B10010000,B10001000}
#define BT {B11111000,B00100000,B00100000,B00100000,B00100000,B00100000}
#define BU {B10001000,B10001000,B10001000,B10001000,B10001000,B01110000}
#define BV {B10001000,B10001000,B10001000,B10001000,B01010000,B00100000}
#define BW {B10001000,B10001000,B10101000,B10101000,B10101000,B01010000}
#define BX {B10001000,B01010000,B00100000,B00100000,B01010000,B10001000}
#define BY {B10001000,B01010000,B00100000,B00100000,B00100000,B00100000}
#define BZ {B11111000,B00001000,B00110000,B01100000,B10000000,B11111000}
#define LA{B00000000,B01110000,B00001000,B01111000,B10001000,B01111000}
#define LB{B10000000,B10000000,B10110000,B11001000,B10001000,B11110000}
#define LC{B00000000,B01110000,B10000000,B10000000,B10001000,B01110000}
#define LD{B00001000,B00001000,B01111000,B10001000,B10001000,B01111000}
#define LE{B00000000,B01110000,B10001000,B11111000,B10000000,B01110000}
#define LF{B00110000,B01001000,B01000000,B11100000,B01000000,B01000000}
#define LG{B00000000,B01111000,B10001000,B01111000,B00001000,B01110000}
#define LH{B10000000,B10000000,B10110000,B11001000,B10001000,B10001000}
#define LI{B00100000,B00000000,B01100000,B00100000,B00100000,B01111000}
#define LJ{B00010000,B00000000,B00111000,B00010000,B10010000,B01100000}
#define LK{B10000000,B10010000,B10100000,B11000000,B10100000,B10010000}
#define LL{B01100000,B00100000,B00100000,B00100000,B00100000,B01111000}
#define LM{B00000000,B00000000,B11010000,B10101000,B10101000,B10001000}
#define LN{B00000000,B00000000,B10110000,B11001000,B10001000,B10001000}
#define LO{B00000000,B01110000,B10001000,B10001000,B10001000,B01110000}
#define LP{B00000000,B11110000,B10001000,B11110000,B10000000,B10000000}
#define LQ{B00000000,B01101000,B10011000,B01111000,B00001000,B00001000}
#define LR{B00000000,B00000000,B10110000,B11001000,B10000000,B10000000}
#define LS{B00000000,B01110000,B10000000,B01110000,B00001000,B11110000}
#define LT{B01000000,B01000000,B11100000,B01000000,B01001000,B00110000}
#define LU{B00000000,B00000000,B10001000,B10001000,B10011000,B01101000}
#define LV{B00000000,B00000000,B10001000,B10001000,B01010000,B00100000}
#define LW{B00000000,B00000000,B10001000,B10101000,B10101000,B01010000}
#define LX{B00000000,B10001000,B01010000,B00100000,B01010000,B10001000}
#define LY{B00000000,B10001000,B10001000,B01111000,B00001000,B01110000}
#define LZ{B00000000,B11111000,B00010000,B00100000,B01000000,B11111000}
#define SPACE{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000}
#define NUM0{B01110000,B10011000,B10101000,B10101000,B11001000,B01110000}
#define NUM1{B00100000,B01100000,B10100000,B00100000,B00100000,B01110000}
#define NUM2{B01110000,B10001000,B00001000,B01110000,B10000000,B11111000}
#define NUM3{B11110000,B00001000,B00001000,B01111000,B00001000,B11110000}
#define NUM4{B10001000,B10001000,B10001000,B11111000,B00001000,B00001000}
#define NUM5{B11111000,B10000000,B11110000,B00001000,B10001000,B01110000}
#define NUM6{B11111000,B10000000,B11111000,B10001000,B10001000,B11111000}
#define NUM7{B11111000,B00001000,B00001000,B01111000,B00001000,B00001000}
#define NUM8{B11111000,B10001000,B11111000,B10001000,B10001000,B11111000}
#define NUM9{B11111000,B10001000,B11111000,B00001000,B00001000,B11111000}
#define DEVIDE{B00001000,B00010000,B00100000,B00100000,B01000000,B10000000}
#define TWODOTS{B01100000,B01100000,B00000000,B00000000,B01100000,B01100000}
#define DOT{B00000000,B00000000,B00000000,B00000000,B01100000,B01100000}
#define COMA{B00000000,B00000000,B00000000,B00110000,B00110000,B01100000}
#define LINE{B00000000,B00000000,B11111000,B11111000,B00000000,B00000000}
#define QUASTION{B01110000,B10001000,B00010000,B00100000,B00000000,B00100000}
#define MARK{B00100000,B01110000,B01110000,B00100000,B00000000,B00100000}
int latchPin = 10;
int clockPin = 13;
int dataPin = 11;
int clock = 9;
int Reset = 8;
int latchPinPORTB = latchPin - 8;
int clockPinPORTB = clockPin - 8;
int dataPinPORTB = dataPin - 8;
int i = 0;
long scrolling_word[6];
int array_turn=0;
byte your_text[24][6]={BW,BE,BL,BC,BO,BM,BE,SPACE,BH,BA,BV,BE,SPACE,BA,SPACE,BN,BI,BC,BE,SPACE,BD,BA,BY};//PUT YOU TEXT HERE
void setup(){
Serial.begin(9600);
pinMode(dataPin,OUTPUT);
pinMode(clockPin,OUTPUT);
pinMode(latchPin,OUTPUT);
pinMode(clock,OUTPUT);
pinMode(Reset,OUTPUT);
digitalWrite(Reset,HIGH);
digitalWrite(Reset,LOW);
setupSPI();
}
void display_word(int loops,byte word_print[][6],int num_patterns,int delay_langth){// this function displays your symbols
i = 0;// resets the counter fot the 4017
for(int g=0;g<6;g++)//resets the the long int where your word goes
scrolling_word[g] = 0;
for(int x=0;x
|
|
|
|
|
|
Hi,
I have a dialog box. I have created a static box on that dialog box. I want that static box should be movable after user run the application. After the dialog box displays, user should be able to move the static box.
Is it possible in a dialog based application in MFC.?
Anybody have any idea.?
Regards,
mbatra
|
|
|
|
|
it's not going to be simple, but it's totally possible.
it's going to look something like this:
void CMyDialog::OnLButtonDown(UINT nFlags, CPoint point)
{
m_bButtonDown = true;
m_startPoint = point;
CDialog::OnLButtonDown(nFlags, point);
}
void CMyDialog::OnLButtonUp(UINT nFlags, CPoint point)
{
m_bButtonDown = false;
m_endPoint = point;
ReleaseCapture();
CDialog::OnLButtonUp(nFlags, point);
}
void CMyDialog::OnMouseMove(UINT nFlags, CPoint point)
{
if (m_bButtonDown)
{
SetCapture();
m_staticControl.MoveWindow(...whatever);
}
CDialog::OnMouseMove(nFlags, point);
}
|
|
|
|
|
Hi Chris,
Thanx for your reply.
I am facing one issue. In my application, I have one edit control and one static box control. While user types some text in edit box, I am displaying the same text character by character in the static box control. But after adding the code for making static box control movable, when I run the application, its not displaying the text in static control. If I remove the code for moving static control, it works fine.
Actually what I want is that after user types the text in the edit box, at the same time text will be entered in the static control also. User should be able to move the static box with the text.
Can you help me with this issue if you have any idea that either the text entered in the static box or edit box, user should be able to drag/move that contorl along with the text.
If u have any sample code for this, will be helpful.
Thanx in advance.
Regards,
Mbatra
|
|
|
|
|
i can't think of any reason why code to move a control via mouse would affect the text it displays...
1) does the text display work until you move the control, or does it not work even if you don't move it?
2) what are you using to update the text in the static control?
|
|
|
|
|
Hi Chris,
I am using OnChange event notificaTION OF Edit control. In that I am updating the text simultaneously in static control as user types in. If I don't use the moving code, I can see text being updated in static control. If I am using the code to move the static control, when I run the application, I can't see the text being updated in the static control as user types in. Given below is the sample code which I am using to update the text in the static control.
<br />
void ChageTextDyn::OnChangeInputtext()<br />
{<br />
<br />
CString inText;<br />
m_InputEditText.GetWindowTextW(inText);<br />
m_OutputStaticText.SetWindowTextW(inText);<br />
}<br />
Regards,
Mbatra
|
|
|
|
|
what does your OnMouseMove code look like?
|
|
|
|
|
Hi Chris,
Given below is the code I am using for moving the static control.
void ChageTextDyn::OnLButtonDown(UINT nFlags, CPoint point)
{
m_bButtonDown = true;
m_StartPoint = point.x;
m_endPoint = point.y;
CDialogEx::OnLButtonDown(nFlags, point);
}
void ChageTextDyn::OnLButtonUp(UINT nFlags, CPoint point)
{
m_bButtonDown = false;
//m_endPoint = point;
ReleaseCapture();
CDialogEx::OnLButtonUp(nFlags, point);
}
void ChageTextDyn::OnMouseMove(UINT nFlags, CPoint point)
{
CRect rc;
m_OutputStaticText.GetWindowRect(&rc);
if( m_bButtonDown )
{
int newX = rc.left + point.x - m_StartPoint;
int newY = rc.top + point.y - m_endPoint;
int width = rc.right - rc.left;
int height = rc.bottom - rc.top;
SetCapture();
m_OutputStaticText.MoveWindow(newX, newY, width, height);
}
CDialogEx::OnMouseMove(nFlags, point);
}
Regards,
Mbatra
|
|
|
|
|
that all looks reasonable.
are you initializing m_bButtonDown to false somewhere ?
|
|
|
|
|
Hi Chris,
No, Except in OnLButtonUp, Nowhere I am initializing m_bButtonDown to false;
I don't If I comment out OnLButtonDown, OnLButtonUp, OnMouseMove code, it works fine, text will be entered in static text box.
But if I uncomment the code for these three handlers, It will not even display the text being updated in the static control as user types in the edit control.
Regards,
Mbatra
|
|
|
|
|
Hi Chris,
Below is the complete code in the file.
// ChageTextDyn.cpp : implementation file
//
#include "stdafx.h"
#include "MBFirst.h"
#include "ChageTextDyn.h"
#include "afxdialogex.h"
// ChageTextDyn dialog
IMPLEMENT_DYNAMIC(ChageTextDyn, CDialogEx)
ChageTextDyn::ChageTextDyn(CWnd* pParent /*=NULL*/)
: CDialogEx(ChageTextDyn::IDD, pParent)
{
}
ChageTextDyn::~ChageTextDyn()
{
}
void ChageTextDyn::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_INPUTTEXT, m_InputEditText);
DDX_Control(pDX, IDC_OUTPUTTEXT, m_OutputStaticText);
}
BEGIN_MESSAGE_MAP(ChageTextDyn, CDialogEx)
ON_BN_CLICKED(IDTEXTEXIT, &ChageTextDyn::OnBnClickedTextexit)
ON_EN_CHANGE(IDC_INPUTTEXT, &ChageTextDyn::OnChangeInputtext)
ON_BN_CLICKED(IDCREATETEXTBOX, &ChageTextDyn::OnBnClickedCreatetextbox)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
// ChageTextDyn message handlers
void ChageTextDyn::OnBnClickedTextexit()
{
ChageTextDyn::DestroyWindow();
}
void ChageTextDyn::OnChangeInputtext()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialogEx::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
CString inText;
m_InputEditText.GetWindowTextW(inText);
m_OutputStaticText.SetWindowTextW(inText);
}
void ChageTextDyn::OnBnClickedCreatetextbox()
{
pStatic = new CStatic();
pStatic->Create(_T(""), WS_CHILD | WS_VISIBLE | SS_RIGHT,CRect(30,130,130,150), this);
}
void ChageTextDyn::OnLButtonDown(UINT nFlags, CPoint point)
{
m_bButtonDown = true;
m_StartPoint = point.x;
m_endPoint = point.y;
CDialogEx::OnLButtonDown(nFlags, point);
}
void ChageTextDyn::OnLButtonUp(UINT nFlags, CPoint point)
{
m_bButtonDown = false;
//m_endPoint = point;
ReleaseCapture();
CDialogEx::OnLButtonUp(nFlags, point);
}
void ChageTextDyn::OnMouseMove(UINT nFlags, CPoint point)
{
CRect rc;
m_OutputStaticText.GetWindowRect(&rc);
if( m_bButtonDown )
{
int newX = rc.left + point.x - m_StartPoint;
int newY = rc.top + point.y - m_endPoint;
int width = rc.right - rc.left;
int height = rc.bottom - rc.top;
SetCapture();
m_OutputStaticText.MoveWindow(newX, newY, width, height);
}
CDialogEx::OnMouseMove(nFlags, point);
}
BOOL ChageTextDyn::OnInitDialog()
{
CDialogEx::OnInitDialog();
m_InputEditText.SetFocus();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
Regards,
Mbatra
|
|
|
|
|
1. you should initialize m_bButtonDown to false, in the ChageTextDyn constructor
2. what happens if you just comment-out the MoveWindow call?
|
|
|
|
|