|
Hi,
cdpace wrote: that keeps reading charachter until the EOF (End of File) Charachter is read.
is not accurate. The end-of-file is not stored as some special character; the file or directory has a length stored somewhere, and getchar() returns characters as long as the file length has not been exceeded; when all data has been returned, the special value "EOF" is returned.
So EOF is NOT a character, it is a special integer value outside the regular character range [0,255], and that is exactly why the return type of getchar() isn't char. Usually EOF equals -1.
But that really is an implementation thing, other platforms might use a different special value; the C specification mandates that the symbol EOF works as documented, without fixing a specific value.
|
|
|
|
|
Something I like to add here.
In the DOS/WINDOWS character set, character 26 (^Z)(Control + Z) is assigned as the end of file character for text files.
When we issue the copy con command at the dos prompt, we type text and to terminate we press ^Z.
Take this case.
Consider a binary file of XXX bytes length having the 5th byte as character 26 (Hex: 1A).
Now open the file in text mode - fopen("file", "r");
When you try to read XXX bytes using fread , it will read only 4 characters. (Till character 26).
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
«_Superman_» wrote: In the DOS/WINDOWS character set, character 26 (^Z)(Control + Z) is assigned as the end of file character for text files.
Ctrl+Z is not stored in the file.
«_Superman_» wrote: When we issue the copy con command at the dos prompt, we type text and to terminate we press ^Z.
Ctrl+Z was a special key combination used by copy (and other things borrowed from DEC) to know when to end copying from the console.
"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
|
|
|
|
|
DavidCrow wrote: Ctrl+Z is not stored in the file.
Agreed. But if it does exist in a file, many command will consider that as EOF.
Assume the following file contents -
A B C D E F ^Z G H I J K L
Executing a type command will only output till F.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
I want to have the user click on a MDIchild window frame to resize it, but when you set the frame to WS_THICKFRAME, to get the resizable frame, then the OnNcLButtonDown() event is not seen. I just want to capture the mouse up so I know when the resize should stop. There must be a way to do this.
|
|
|
|
|
In the OnSize handler, check if the left mouse button is down - GetKeyState(VK_LBUTTON)
Now do a SetCapture .
You should now be able to get a WM_LBUTTONUP .
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hi, thanks for the response. I tried this and it does detect the WM_LBUTTONUP, but somehow it lost the ability to stretch the frame. After clicking on the frame dragging the mouse doesn't move the frame.
|
|
|
|
|
You're probably not calling the base class implementation of OnSize .
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Yes, I am calling the base class too. See code below:
void CImagrView::OnSize(UINT nType, int cx, int cy)
{
static bool cap = false;
ATLTRACE2("*****"__FUNCTION__"\n");
if (m_resizing && GetKeyState(VK_LBUTTON) && !cap) {
SetCapture();
cap = true;
}
CScrollView::OnSize(nType, cx, cy);
}
The call to SetCapture is stopping the frame from being stretched. I put in a static flag to only call SetCapture the first time. Then the frame stretch works again, after you release the mouse, but then the ButtonUp is back to not being detected again.
If I change the window to not have WS_THICKFRAME, then it can detect the NcLButtonDown and Up.
|
|
|
|
|
Hi,
I try to implement a combobox where it is possible to delete items in expanded state (listbox portion of combobox is dropped down). Here what I have done: I added a keyboard handler and call DeleteString(GetCurSel()) . Unfortunately the height of the listbox is never updated after items are removed. I tried to call ShowDropDown(FALSE); ShowDropDown(TRUE); as a workaround, which will update the listbox size... but it comes with an animation on Windows XP (Common Controls 6).
1) Is there a way to disable animations for a specific control?
2) Alternatively, can I get access to the listbox portion of a combobox in order to manually update its size?
Thanks for help!
/M
|
|
|
|
|
Apparently CComboBox::GetComboBoxInfo[^] can give you a handle to the list control. Aside i would try to use GetItemHeight/SetItemHeight to see if it triggers any size recalculation in the control or not, maybe you get lucky. Another thing you could try experimenting with is CWnd::SetRedraw, you could try to disabe redrawing of the whole window, do your ShowDropDown routine and then re-enable redrawing and have the list get redrawn. I might be reinventing the wheel here but i think you can't disable animating for a single control, only for the whole system.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Code-o-mat wrote: Apparently CComboBox::GetComboBoxInfo[^] can give you a handle to the list control.
Thanks that helped! A more detailed answer in the post below.
/M
|
|
|
|
|
Hei Moak,
See if this works:
COMBOBOXINFO cbi = {sizeof(COMBOBOXINFO)};
if(GetComboBoxInfo(&cbi))
{
HWND hwndListBox = cbi.hwndList;
LRESULT lNum = SendMessage(CB_GETCOUNT,0,0);
LRESULT lWidth = SendMessage(CB_GETDROPPEDWIDTH,0,0);
LRESULT lHeight = SendMessage(CB_GETITEMHEIGHT,0,0);
::SetWindowPos(cbi.hwndList,0,0,0,lWidth,lNum+1 * lHeight,SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
}
|
|
|
|
|
Great this works! I changed the code slightly, CB_GETDROPPEDWIDTH returned zero.
COMBOBOXINFO cbi = { sizeof(COMBOBOXINFO) };
if(GetComboBoxInfo(GetComboBoxCtrl()->GetSafeHwnd(), &cbi))
{
CRect rect;
::GetWindowRect(cbi.hwndList, &rect);
rect.bottom = rect.top + GetCount()*GetItemHeight(0) + 2;
::SetWindowPos(cbi.hwndList, 0, 0, 0, rect.Width(), rect.Height(), SWP_NOMOVE | SWP_NOZORDER);
}
There are two thing I am not sure about and I would like to ask: In the height calculation I needed to add 2 pixels for the border, is there a better alternative than using a magic value? About the flags for SetWindowPos() , I didn't understand from MSDN what SWP_NOOWNERZORDER [^] is for? I replaced it with SWP_NOZORDER , hope this is okay.
Thanks, M
|
|
|
|
|
Moak wrote: There are two thing I am not sure about and I would like to ask: In the height calculation I needed to add 2 pixels for the border, is there a better alternative than using a magic value?
I am actually not sure about this. I do not know if the GetSystemMetrics Function[^] will return anything meaningful for the ListBox border. You can check if SM_CYFIXEDFRAME returns the correct value. Interestingly enough I did not have this problem... Hmmmm GetCount() returns a zero based index... shouldn't you be adding 1 before multiplying by height?
Moak wrote: I didn't understand from MSDN what SWP_NOOWNERZORDER [^] is for? I replaced it with SWP_NOZORDER, hope this is okay.
Oops, yes... SWP_NOZORDER is correct...
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: You can check if SM_CYFIXEDFRAME returns the correct value. Interestingly enough I did not have this problem
Okay, I will check it tomorrow. Btw, GetCount()[^] returns not a zero based index.
Thanks again... time to get some sleep.
|
|
|
|
|
Moak wrote: Btw, GetCount()[^] returns not a zero based index.
Ahhh yes you are correct again.
Its the CB_GETCOUNT Message[^] that returns the zero based index.
Best Wishes,
-David Delaune
|
|
|
|
|
To know the size of the border you could try this trick:
CRect Outer, Inner;
list.GetWindowRect(&Outer);
list.GetClientRect(&Inner);
list.ClientToScreen(&Inner);
int LeftBorder = Inner.left - Outer.left;
int TopBorder = Inner.top - Outer.top;
int RightBorder = Outer.right - Inner.right;
int BottomBorder = Outer.bottom - Inner.bottom;
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
A window called GetCapture() first, then calls ReleaseCapture() when mouse-down (on WM_LBUTTONDOWN message).
If mouse-down is not clicking on the window, how do we dispatch WM_LBUTTONDOWN message to that window clicked?
The question is similar to Window's menu - WM_LBUTTONDOWN is correctly dispatched if clicking outside of menu, acturally the window I asked is similar to menu for displying some information.
|
|
|
|
|
Convert the position given in the WM_LBUTTONDOWN message to screen co-ordinates. Use GetWindowFromPoint to get the window at that position. Post the WM_LBUTTONDOWN message to that window, remembering to convert the screen co-ordinates to client co-ordinates for that window.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks, all are fine now.
the function is WindowFromPoint(...) - first time I use it.
|
|
|
|
|
I am a major newbie to window API and coding in C C++. I'm having a major problem with character variables. In other languages you can just say
variable char x = "Hello"
variable char y = "I'm stupid"
x="No, I'm really not stupid"
x=y
but in c a char is basically a number from the ASCII table
and if you define char x[112] you then can't say x="Hello" because I guess x must be 112 chacters. But you can say x[]="Hello" which is ok if you just want a variable for "Hello" but if you want use a variable and assign it to different values and/or concatenat different values to it what do you do.
Anyone have any simple answers as to how to use character variables in c c++?
What I want to do is create a text file that's 112 characters on each line.
1-2= a two digit code
3-12=yyyy/mm//dd
13-20=hh:mm:ss
21-40=a barcode retrieved from an editbox
41-60=blank
61-80=blank
81-81=a single digit code
82-92=a decimal 10,2 retrieved from an editbox
92-102=a number retrieved from an edit box
103-112=a number
if numbers / values are less than allowed their padded with spaces
something like this is easy in other languages but in windows api c c++ seems to be very difficult
thanks for any help
|
|
|
|
|
There's not going to be all that simple an answer for you. What you are asking for is the stuff you learn in a lesson, or from a book - not from a quick post.
But here's a start.
char means char acter. In those other languages, "Hello" is a string, not a char either.
Another work for character is letter. So, 'H' is a char, "Hello" is a string, or bunch of characters one after another.
char message [] = "Hello";
That means that the message variable is an arrach of characters - or an array of letters. In this case, 'H' followed by 'e', 'l', 'l', 'o', and lastly a char value of 0, to denote the end of a string.
And that's all I'll reply - otherwise I'll write a book for you - and other people have already done that.
But hopefully ot will get you started on your journey.
I learned from Kernigan & Richie - small language, small book.
Now, if you want to *pay* me to write you a book...
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/[ ^]
|
|
|
|
|
egerving wrote: if you define char x[112] you then can't say x="Hello" because I guess x must be 112 chacters
No - it's because a C string, when referred to by name, is a pointer, not an array. You can use strcpy and strcat (and many other functions) to build strings.
For your situation, I'd probably use fprintf to write each record to the file, using width specifications - something like:
fprintf(fileHandle, "%-2d%-4d/%-2d/%-2d%-2d%-2d:%-2d%-20s %-1d%-11.2f%-11d%%-10d\n", firstCode, year, month, day, hour, minute, second, barcode, secondCode, decimal, firstNumber, secondNumber);
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|