|
when i run the following code in VC++ it gives "-1" as output.Why?
main()
{
printf("%d");
}
|
|
|
|
|
printf("%d");
You need a value associated with the format specifier:
printf("%d", x);
x would be some object in your code to be displayed in decimal format.
|
|
|
|
|
MSDN:
"The printf function formats and prints a series of characters and values to the standard output stream, stdout. If arguments follow the format string, the format string must contain specifications that determine the output format for the arguments."
Your format string is "%d" but no arguments follows that format string. so basically the printf function (knowing that it is a variable arguments function using a __cdecl calling convention) will take from the stack the parameters it needs (based on the format string "%d" you said i give you an int) and construct the string and send it as output
So the value -1 is a value the printf function is taking it from the stack.
Hope i kind of answered your question
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
If you want to output the string %d to the console then use "%%d", otherwise add the variable as someone has already suggested.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fuity and sweet. I'm jelly, what am I? - David Williams (Little Britain)
|
|
|
|
|
You hve to have a value for it to display it would look like this:
main()
{
printf("%d", 2);
}
|
|
|
|
|
I am working on a SDI project. The main window has a title in the title bar that I am trying to change. For some reason the name appears as: untitled - XXXXXX.
XXXXX represents a valid name, but I cannot get rid of "untitled."
Thanks.
Jerry
|
|
|
|
|
Check CDocument::SetTitle
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
jerry1211a wrote:
XXXXX represents a valid name, but I cannot get rid of "untitled."
In the main frame window's PreCreateWindow() method, remove the FWS_ADDTOTITLE style.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
FWS_ADDTOTITLE will actually append information to the window title. You want to remove FWS_PREFIXTITLE from the window style. Here is the code I've used below:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style = cs.style - FWS_PREFIXTITLE;
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
return TRUE;
}
Hope that helps.
Mike Ellertson
|
|
|
|
|
mellertson wrote:
FWS_ADDTOTITLE will actually append information to the window title.
Of course. Did I indicate otherwise?
mellertson wrote:
You want to remove FWS_PREFIXTITLE from the window style.
Which is why I said "...remove the FWS_ADDTOTITLE style." in my earlier post.
mellertson wrote:
cs.style = cs.style - FWS_PREFIXTITLE; // no document titles.
Which obviously will not work. You'll need to AND the style with the one's complement of FWS_PREFIXTITLE .
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Dude, don't get all huffy. The code I posted does work, I'm using in my app right now.
I wasn't trying to be rude in my correction, just a polite correction.
When you override the main frames PreCreateWindow function, the value of cs.style will already include FWS_PREFIXTITLE . That's why you can subract it out like this:
cs.style = cs.style - FWS_PREFIXTITLE;
And it will remove the "untitled -" prefix from the application.
You said:
In the main frame window's PreCreateWindow() method, remove the FWS_ADDTOTITLE style.
You were incorrect in removing the FWS_ADDTOTITLE .
See the definitions below for more clarification.
Taken from http://msdn.microsoft.com
Frame-Window Styles
FWS_ADDTOTITLE Specifies information to append to the end of a frame window title. For example, "Microsoft Draw - Drawing in Document1". You can specify the strings displayed in the Advanced Options dialog box in AppWizard. If you need to turn this option off, override the CWnd::PreCreateWindow member function.
FWS_PREFIXTITLE Shows the document name before the application name in a frame window title. For example, "Document - WordPad". You can specify the strings displayed in the Advanced Options dialog box in AppWizard. If you need to turn this option off, override the CWnd::PreCreateWindow member function.
The initial problem was trying to get rid of the prefix "untitled".
FWS_ADDTOTITLE adds information to the end of the window title, it doesn't add a prefix.
David, I really wasn't trying to be rude, just trying to make a small correction. Take it for what it's worth.
Mike Ellertson
|
|
|
|
|
mellertson wrote:
Dude, don't get all huffy.
No huffiness here!
mellertson wrote:
The code I posted does work, I'm using in my app right now.
The only reason it works is because the window already had the FWS_PREFIXTITLE style. Had it not, your method would fail, whereas mine would not.
mellertson wrote:
You were incorrect in removing the FWS_ADDTOTITLE.
I disagree (in the context of an MDI application). In order to remove "- untitled" from the frame title, the FWS_ADDTOTITLE style must be removed. Removing the FWS_PREFIXTITLE style simply changes the order of the document name and the application name in the frame's title. For an SDI application like the OP indicated, the behavior may indeed be different.
In any case, my point was how to remove the style, not what style to remove.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Dude, you're a complete idiot...
Mike Ellertson
|
|
|
|
|
Takes one to know one, I presume.
Just because you were wrong is no reason to resort to name calling, unless of course that is the mettle from which you are made.
Have a blessed day, Mike. It sounds like you need one!
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Can you suggest me a way to change dynamically the button style from bitmap to text and viceversa?
I tried with
m_BUTT_25.SetButtonStyle(BS_TEXT);<br />
m_BUTT_25.RedrawWindow();
and
m_BUTT_25.SetButtonStyle(BS_BITMAP);<br />
m_BUTT_25.RedrawWindow();
but nothing seems to happen...
I can instead change the button caption with SetWindowText : why is this?
Thanks ,
Marco.
|
|
|
|
|
Not all styles can be changed at runtime, this might very well be an example. A common method is to destroy and recreate the button.
marcomars wrote:
I can instead change the button caption with SetWindowText: why is this?
Because the text is not a style.
|
|
|
|
|
Maybe you have to "detach" your object (text, icon, bmp) from the button first?
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
How about creating two buttons, one with text and the other with a bitmap? Disable/enable them accordingly.
marcomars wrote:
I can instead change the button caption with SetWindowText: why is this?
Because that's the way it is supposed to work. Per MSDN:
The SetWindowText function changes the text of the specified window's title bar (if it has one). If the specified window is a control (e.g., button), the text of the control is changed.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I have an app which is set up as a property sheet with three pages. In OnInitDialog for the property sheet I am adding some buttons to the main property sheet in the area below the pages.
My problem is that I want to be able to control the tab order for these buttons. Right now they are inserted in the tab order between the tabs for the pages and the controls on the page. I'd prefer to have them inserted after the controls on the page.
I am adding the pages to the sheet prior to when it is displayed. Then when it is first displayed OnInitDialog is called and the buttons are added. My guess is that I need to add the buttons after the controls on the pages are created, but I'm not sure how to get control at that point.
Any hints?
Thanks,
Tom
|
|
|
|
|
The tab order is the Z-order of the controls. Use SetWindowPos to control the Z-order, and hence the tab order.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Ah, thank you. I didn't realize that could be done.
Now, why don't they document this? (No answer required!)
Tom
|
|
|
|
|
hello guys,
i'm new here;
i've problem in making serial communication between two pc
with rs232 with visual c++
the problem is how to send character/text (like chat program)to another pc
i've some source code from this site.
when i try it, the text/character didn't appear in other pc.
is there anyone that can help me?
please,
thankz for the help
|
|
|
|
|
Check
this[^] class its quite worthy
As for the rest you just have to read the file, send it on serial and then read it on the other PC then write it to disk.
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Hi,
I have an MDI application whose main frame will receive a message which should be sent to the correct view..With this message i will be having an Object ID(i.e. One of my child window has some object on which i have clicked..the ID of that object is sent to a second application which Sends a message back to the first application with ID).So is there any way i can identify the correct view with the help of this Object ID???????
Plz reply
Thanx in advance
Poorni
|
|
|
|
|
From the main frame, get the document to iterarate round all the current views (CDocument::GetFirstViewPosition & CDocument::GetNextView. Add a OwnsObject function to each view, and call it for each view. In that function, have the view check to see if it owns the supplied object ID.
|
|
|
|