|
Nish, Nish, why on earth would you do it this way ?
File.WriteString (LogConvert.GetBuffer(LogConvert.GetLength());
LogConvert.ReleaseBuffer;
This is precisely the sort of ad hoc 'create something big enough to always work' stuff that C++ does away with needing. strcpy is a C function.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
I guess I still have my bad habits from C left inside me
Nish
The posting stats are now in PDF:-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
Updated - May 04th, Saturday
|
|
|
|
|
Christian Graus wrote:
File.WriteString (LogConvert.GetBuffer(LogConvert.GetLength());
LogConvert.ReleaseBuffer;
Using GetBuffer( ) has to call ReleaseBuffer( ). If I code this way:
File.WriteString(LogConvert.operator LPCTSTR());
Is there any difference between GetBuffer() and operator LPCTSTR() ?
Maxwell Chen
People say "No news is good news". Then, no code is good code!?
|
|
|
|
|
operator LPCTSTR() is the same as casting to LPCTSTR, which is less ugly IMO
(LPCTSTR) LogConvert
The fact that they provide the operator leaves me confused as the why they have GetBuffer as well. I'll have to check.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
The reason that they have the operator LPCTSTR() and GetBuffer() is that the first converts a CString to an LPCTSTR, while the second returns a pointer to the buffer of the CString as an LPTSTR. The LPCTSTR is a const TCHAR*, which doesn't allow the buffer to be modified, while the LPTSTR allows the contents of the buffer to be modified.
The operator LPCTSTR() from CString allows a CString to be used anywhere that you need an LPCTSTR. This means that you can simply write:
CStdioFile File; // assume that this file is already open for write...
CString LogConvert; // assume that this string is filled in...
File.WriteString( LogConvert ); // since WriteString takes an LPCTSTR, this is all that is needed.
This is one of the things about CString that I prefer over std::string. For std::string, you would need to explicitly convert the string:
std::string LogConvert;
File.WriteString( LogConvert.c_str() );
Some people prefer the method used by std::string, as you are in control of when the conversion is made, but I prefer the simplicity of just passing the string. This is particularly useful when interfacing with legacy code. For new code, I probably would just pass the string object.
Best regards,
John
|
|
|
|
|
Howdy all,
Does anyone have any suggestions for an API function similar to DrawDibDraw(), which can handle a negative height bitmap, aka an inverted bitmap?
MSDN explicitly states that DrawDibDraw can't handle a negative height parameter, but I can't find a useful alternative.
Please don't tell me I have to flip the bitmap by hand
TIA,
Pete
|
|
|
|
|
By definition, a "negative height" is impossible. It has a height. The problem seems to be that you've got a DIB (that is "just" upside-down) and you want to draw it.
If that's the case, and it's not a DIB, I don't think you have much of a choice.
I however fail to see why you are so reluctant to "flip the bitmap by hand", it's after all just nothing more than memcpy'ing a line at a time from your used format to the format Win32 expects it to be.
Perhaps you can even use that memory as-is if it's layout is compatible with a DIB, and just tell a DIB to use it?
Short of you explaining your problem a little more, and my suggestions don't work for you, I think you're out of luck.
|
|
|
|
|
I'm afraid my previous post was rather cryptic, let me explain this a bit better
By negative height, I meant that the DIBs BITMAPINFOHEADER.biHeight is a negative value. I believe this means that the 1st scanline of data refers to the bottom line of the image, rather than the top line, and the second scanline of data refers to the second-from-bottom image line, rather than the second-from-top image line. This is a documented feature of the DIB format, it's just that DrawDibDraw() can't handle it. From MSDN:
...and the biHeight member must be a positive value; DrawDibDraw will not draw inverted DIBs...
I agree that flipping the DIB by hand wouldn't be too tricky, but the issue here is speed. I would like to be displaying around 60 bitmaps a second (I'm trying to display an avi stream), and I think the overhead of manually 'un-inverting' the DIBs would be too high.
There's also an element of me being stubborn about Win32 not supporting a documented feature of the DIB format
I have actually been able to use StretchDIBits()successfully since my first post, but unfortunately it appears to use a different image-scaling algorithm which can produce a rather ugly bitmap. And it's also a bit slower than DrawDibDraw(), which is obviously an issue in my case.
Thanks for your help,
Pete
|
|
|
|
|
moredip wrote:
60 bitmaps a second (I'm trying to display an avi stream)
OK. I suggest you have a look at the VirtualDub (www.virtualdub.org) source code. I think he's using the WFV API.
|
|
|
|
|
Hi Mike,
I considered virtualdub, but my boss it concerned about the legal aspects of GPL, and would rather I didn't browse the source, lest I become 'contaminated' by that sneaky viral license
It turns out that VFW is no use anyway, as it can't deal with AVI files larger than 2GB (a throwback to when everyone M$ cared about was using FAT32, with it's 2GB file size limit).
So now I have the joy of learning DirectShow.
Thanks anyway!
Pete
|
|
|
|
|
Hello.
In one of my programs, I created view derived from CListView. Everything works great. I implemented a double click feature where if the user double clicks an item, the program instantiates a dialog box, allowing the user the edit the text belonging to that item.
I used the exact code Jeff Prosise presents in his book. There is one thing I would like to change. Current, the user has to click exact a spot inside the text belong to each item of the CListView. For example:
---------------
item 1
---------------
item 2
---------------
item 3
---------------
In the above sample, the user would have to click *on* one of the item text to be considered a valid double click. I would like to have it such that the user only needs to click a point inside the *item box*. So for example, the user can click any point as long as it is inside a specific *item box*.
Prosise uses this funtion to validate the point.
// GetListCtrl()->HitTest(point);
I believe HitTest(...) check a specific text, not the item box in general. Is there a way to check using a broader item box area instead of specific item text?
Thanks,
Kuphryn
|
|
|
|
|
kuphryn wrote:
I used the exact code Jeff Prosise presents in his book
Actually I cover this in my MFC book :P
Seriously, I don't have Jeff's book, but I'm sure it's very good. Here's what you need to do:
- Implement a handler for WM_LBUTTONDBLCLICK
- Modify the handler like this
void CListViewDemoView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
CListView::OnLButtonDblClk(nFlags, point);
CListCtrl& list = GetListCtrl();
int iIndex;
point.x = 2;
if ((iIndex = list.HitTest(point, NULL)) != -1)
{
list.SetItemState(iIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
int index = list.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
CString str = list.GetItemText(index, 0);
AfxMessageBox(str);
}
}
Cheers,
Tom Archer
Author - Inside C#, Visual C++.NET Bible
|
|
|
|
|
Nice! Thanks.
I will try out your code later today. I am late for class right now.
Kuphryn
|
|
|
|
|
I hear ya'. I'm late turning in a chapter! Don't you hate when things like school and work get in the way of thing we really want to do?
Let me know if you have any questions.
Cheers,
Tom Archer
Author - Inside C#, Visual C++.NET Bible
|
|
|
|
|
Recently I downloaded the libnetNT package from eeye.com. I copied all the libs and header files to my directories in msvc, but when I try to build my project I get tons of linker errors.
Compiling...
arp.cpp
Linking...
arp : error LNK2001: unresolved external symbol _gethostbyname@4
arp : error LNK2001: unresolved external symbol "int __cdecl libnet_destroy_packet(unsigned char * *)" (?libnet_destroy_packet@@YAHPAPAE@Z)
arp : error LNK2001: unresolved external symbol "int __cdecl libnet_close_link_interface(struct libnet_link_int *)" (?libnet_close_link_interface@@YAHPAUlibnet_link_int@@@Z)
arp : error LNK2001: unresolved external symbol "int __cdecl libnet_write_link_layer(struct libnet_link_int *,unsigned char const *,unsigned char *,int)" (?libnet_write_link_layer@@YAHPAUlibnet_link_int@@PBEPAEH@Z)
arp : error LNK2001: unresolved external symbol "int __cdecl libnet_build_arp(unsigned short,unsigned short,unsigned char,unsigned char,unsigned short,unsigned char *,unsigned char *,unsigned char *,unsigned char *,unsigned char const *,in
t,unsigned char *)" (?libnet_build_arp@@YAHGGEEGPAE000PBEH0@Z)
arp : error LNK2001: unresolved external symbol "int __cdecl libnet_build_ethernet(unsigned char *,unsigned char *,unsigned short,unsigned char const *,int,unsigned char *)" (?libnet_build_ethernet@@YAHPAE0GPBEH0@Z)
arp : error LNK2001: unresolved external symbol "struct libnet_link_int * __cdecl libnet_open_link_interface(char *,char *)" (?libnet_open_link_interface@@YAPAUlibnet_link_int@@PAD0@Z)
arp : error LNK2001: unresolved external symbol "int __cdecl libnet_select_device(struct sockaddr_in *,unsigned char * *,unsigned char *)" (?libnet_select_device@@YAHPAUsockaddr_in@@PAPAEPAE@Z)
arp : error LNK2001: unresolved external symbol "int __cdecl libnet_init_packet(int,unsigned char * *)" (?libnet_init_packet@@YAHHPAPAE@Z)
arp : error LNK2001: unresolved external symbol "unsigned char * __cdecl libnet_win32_get_remote_mac(unsigned long)" (?libnet_win32_get_remote_mac@@YAPAEK@Z)
arp : error LNK2001: unresolved external symbol _inet_addr@4
Debug/arp.exe : fatal error LNK1120: 11 unresolved externals
Error executing link.exe.
arp.exe - 12 error(s), 0 warning(s)
|
|
|
|
|
You don't have to copy the libs to any MSVC directory, instead locate them in the project directory and have them linked with "Add to project".
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
ok, I just added it to the project and I still get the errors.
|
|
|
|
|
Still the same number of errors, or at least some of the unresolved symbols went away?
Also, you forgot to link with Winsock.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
You must (obviously) link with e.g. the socket library you intend to use, and all the other libraries.
1. Check in the MSDN help what library implements "gethostbyname".
2. Add this to the "Link" tab. You'll have to look up what drop-list tab you need to find for the "libraries" edit box.
3. To that same edit box, add the name (possibly including path) to the library or libraries inplementing e.g. libnet_init_packet.
|
|
|
|
|
ok I just linked with winsock and that reduced the # of errors to ten instead of twelve.
Linking...
arp.obj : error LNK2001: unresolved external symbol "int __cdecl libnet_destroy_packet(unsigned char * *)" (?libnet_destroy_packet@@YAHPAPAE@Z)
arp.obj : error LNK2001: unresolved external symbol "int __cdecl libnet_close_link_interface(struct libnet_link_int *)" (?libnet_close_link_interface@@YAHPAUlibnet_link_int@@@Z)
arp.obj : error LNK2001: unresolved external symbol "int __cdecl libnet_write_link_layer(struct libnet_link_int *,unsigned char const *,unsigned char *,int)" (?libnet_write_link_layer@@YAHPAUlibnet_link_int@@PBEPAEH@Z)
arp.obj : error LNK2001: unresolved external symbol "int __cdecl libnet_build_arp(unsigned short,unsigned short,unsigned char,unsigned char,unsigned short,unsigned char *,unsigned char *,unsigned char *,unsigned char *,unsigned char const *,in
t,unsigned char *)" (?libnet_build_arp@@YAHGGEEGPAE000PBEH0@Z)
arp.obj : error LNK2001: unresolved external symbol "int __cdecl libnet_build_ethernet(unsigned char *,unsigned char *,unsigned short,unsigned char const *,int,unsigned char *)" (?libnet_build_ethernet@@YAHPAE0GPBEH0@Z)
arp.obj : error LNK2001: unresolved external symbol "struct libnet_link_int * __cdecl libnet_open_link_interface(char *,char *)" (?libnet_open_link_interface@@YAPAUlibnet_link_int@@PAD0@Z)
arp.obj : error LNK2001: unresolved external symbol "int __cdecl libnet_select_device(struct sockaddr_in *,unsigned char * *,unsigned char *)" (?libnet_select_device@@YAHPAUsockaddr_in@@PAPAEPAE@Z)
arp.obj : error LNK2001: unresolved external symbol "int __cdecl libnet_init_packet(int,unsigned char * *)" (?libnet_init_packet@@YAHHPAPAE@Z)
arp.obj : error LNK2001: unresolved external symbol "unsigned char * __cdecl libnet_win32_get_remote_mac(unsigned long)" (?libnet_win32_get_remote_mac@@YAPAEK@Z)
Debug/arp.exe : fatal error LNK1120: 9 unresolved externals
Error executing link.exe.
arp.exe - 10 error(s), 0 warning(s)
|
|
|
|
|
I don't understand what's going wrong. I even linked all the libs that Libnet was compiled from.
|
|
|
|
|
Some windows flash (messenger programs does that often to get attention) How can I detect which window is flashing. Maybe with a system wide hook or something?
Does anybody knows this?
-------------------------------
Greetz,
MG
|
|
|
|
|
Short of hooking the kernel (undocumented) and see what windows are told to "flash"? I don't think you can do this.
|
|
|
|
|
Hi.
I have always wondered about having push-buttons at any specific place around the frame in a SDI architecture. I will explain as best I can about how the program might look like. Here is a typical SDI core GUI.
-----
Menu/Toolbar
-----
View
-----
Statusbar
-----
I would like to have something like this:
-----
Menu/Toolbar
-----
View
-----
Two Push-Buttons (Open | Exit) // open and exit is arbitrary
-----
Statusbar
-----
What is the best way to implement something like the GUI above? It is easy to add buttons and such inside a dialog box, but I have never be able to add push-buttons anywhere in the main frame.
I have one idea, but I am not completely sure on how to add the click mesages if the user clicks the button. Three weeks ago I posted a thread asking about added a progress bar insde the status bar. A member at CodeGuru posted a very unique technique that basically enable/disable the default status bar and enable/disable a CControlBar. It was such a cool technique. I am still using it.
I was thinking maybe I can implement the same setup, but this time, enable the CControlbar througout the program's lifetime. However, how will I be able to process messages if the user clicks a button? the use of CControlbar does not require deriving a class to encapsulate the dialog box. Thus, I have no way of processing messages cooresponding to the buttons inside the dialog box.
Do you have a better technique?
Thanks,
Kuphryn
|
|
|
|
|
How about: just another dockable toolbar that contains the buttons, and have the buttons mapped to command IDs (easy handling of the clicks).
Peace!
-=- James.
"Fat people are hard to kidnap."
(Try Check Favorites Sometime!)
|
|
|
|
|