|
union U
{
int x;
int y;
}u;
u.x=0;
u.y=200;
cout<<u.x+u.y<<endl;< b="">
Why does this code print 144?
I don't understand, please help me!
Thanks you very much!
|
|
|
|
|
ideally it should print 400.
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
Anshuman is right - it should be 400...
But I notice a coincidence... 256+144 = 400. Are you on some weird architecture? I;ve never heard of 8bit ints, but...
If you'd put in BYTE, or char, I'd be sure of the answer.
Try:
cout << sizeof (U);
u.x = 100;
cout << u.x;
u.y = 127;
cout << u.x;
u.x = 257;
cout << u.x;
cout << (double) (u.x);
This should set some light on your problem.
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
In string table im having resource ID as IDR_TEST and its string value as "test". Now i want to change the string value at runtime. I have tried with LoadString. But its not working. Anyone please tell me how to load string value at runtime?
|
|
|
|
|
You've got the basics wrong there. Entries in a string table are not meant to be modified, whatsoever.
If you need a string that needs to be modified, what's wrong with having a member variable?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
i want to change the default title of SDI window.So, I want to change the Resource ID IDR_MAINFRAME in string table.
|
|
|
|
|
Can't you just edit that particular entry in the string table? Also, there's SetWindowText()[^]
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
No.I will give that title in a ini file.So, the title will change. SetWindowText is not working.
|
|
|
|
|
Will you PLEASE read the guidelines[^] and post messages that people can understand?
Why are you using an ini file to store the Window's title? What's wrong with using a string table? What exactly are you trying to achieve?
Karthika85 wrote: SetWindowText is not working.
And what does that mean? What does your code look like?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
First,i want to change the default title of a window. I can change the default title in String table.In future,If somebody wants to change the title of my application, again they have to change the string in resource,again they need to compile the whole application.So i want to configure the title in ini file.
I added SetWindowText function inside OnCreate function.Its not working.
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
int *num,i,j=m_wndToolBar.GetToolBarCtrl().GetButtonCount();
num=new int[j+1];
memset(num,0,(j+1)*sizeof(int));
num[0]=j;
for(i=0;i<j;i++)
{
if(ID_SEPARATOR == m_wndToolBar.GetItemID( i ))
num[i+1]=1;
}
//·Ö¸ô·ûËãÊÇÒ»¸ö°´Å¥£¬¿í¶ÈÓÀԶΪ6
//ÉÏÃæµÃµ½µÄ°´Å¥¾ØÐÎÓÀÔ¶±È¹¤¾ßÀ¸±à¼Æ÷ÀïÃæÉ趨µÄ³¤¿í¸÷´ó7
//Èç¹ûΪ¹¤¾ßÀ¸ÉèÖÃÁËλͼ£¬°´Å¥µÄÐÎ×´ÓÀÔ¶Ö»Óë´´½¨Î»Í¼Áбíʱָ¶¨µÄ´óСһÖ£¬ÓëÆäËûµØ·½µÄÉèÖÃÎÞ¹Ø
m_wndToolBar.SetFullColorImage(IDB_BITMAP2, RGB(255, 0, 255), num);
delete []num;
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
SetWindowText("Test");
return 0;
}
|
|
|
|
|
try this way
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)<br />
{<br />
cs.lpszName = "Test";
<br />
return TRUE;<br />
}
maybe you need add following statement before the cs.lpszName = "Test";
cs.style &= ~FWS_ADDTOTITLE;
|
|
|
|
|
Thanks.I got it.
We should call SetWindowText inside OnInitialUpdate function.
void CToolbarView::OnInitialUpdate()
{
CView::OnInitialUpdate();
CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
pFrame->SetWindowText("title");
}
|
|
|
|
|
Hi,
im creating combobox ctrl Thru code but not from resource...and Pls let me know how can i increase the height of the ctrl based on the font...ie if the font is small ctrl should be small else if the Font is bigger Ctrl should increase....
i used SetFont() but it doesn"t help...
and even i tried using GetComboBoxInfo and obtained HWND hwndItem,HWND hwndList; handles for Editbox and drop-down list but i want to know how can i setfont for the same...
|
|
|
|
|
SetFont() will not automatically change the size of the combo box. You can use GetTextMetrics() to obtain size information about about the font, calculate the minimum size necessary to display the font in the control and then manually adjust the size and position of the combobox.
I am a lean mean ground beef machine!!!
|
|
|
|
|
I'm automating Word but some of the method calls I use can be lengthy (they show Word dialogs and the method doesn't return until the user closes the dialog from Word) during which time my GUI thread blocks, because the COM method call I've called doesn't return until the operation in Word is finished. This freezes my app's dialog.
I want to avoid blocking my main thread by making a COM call that returns immediately without waiting for results, like PostMessage vs SendMessage.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
as with most of these GUI main thread issues, it seems logical in this case to build a worker class to handle the COM interaction with Word in a seperate thread .. I dont quite see this :-
sashoalm wrote: COM call that returns immediately without waiting for results
happening as you've expressed it, but there's no reason why the worker/COM thread cant use some sort of event/messaging to let the gui know when its finished/done the Word tasks ...
'g'
|
|
|
|
|
COM's apartment model for threads causes problems with that, though I've been told that using CoInitializeEx(0, COINIT_MULTITHREADED); in both worker and main thread can solve it.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Lengthly tasks are belonging in different threads!!! So write a thread which is calling the COM.
Your problem is screaming for threading
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
I need my program sleep 1 microsecond, but Sleep() can not do this.
So, can I use select() instead Sleep() to do this?
<br />
timeout.tv_sec=0;<br />
timeout.tv_usec=1;<br />
FD_ZERO(&readfd);<br />
<br />
ret=select(0,&readfd,NULL,NULL,&timeout);<br />
It's have any problem or not?
|
|
|
|
|
Why sleep? There is also the WaitForMultipleObject()-API
"Carpe diem"
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
hanlei0000000009 wrote: I need my program sleep 1 microsecond, but Sleep() can not do this.
Neither can any other API do this (under Windows). Windows was never designed to provide this kind of functionality (it is not a real-time OS).
If you use something like Sleep(2) , your program may sleep for 2 milliseconds, may be 3, or 4, or say even 100 ms. There's no guarantee about this. The thread scheduler tries its levels best to put your thread to an 'unschedulable' state for as close as possible, to what you've asked. But, it can almost never be exact.
So, while Windows cannot even promise you the precision of milliseconds, you can forget microseconds, which is 1000 times the precision of milliseconds!
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Yeah, that's not happening...
Why 1 microsecond, FFS? What are you trying to do? BEcause there may well be a better way.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
hanlei0000000009 wrote: I need my program sleep 1 microsecond...
If you need this delay in order for the code to work, you've got an underlying problem that needs to be resolved. Adding arbitrary delays such as this is just asking for trouble later.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
|
Actually, they won't help. The OP wants resolution in terms of microseconds!
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|