Dervish1 37 Newbie Poster

I'm trying to learn how to do some simple things with MFC - I'm not used to the toolkit. I want to load a png image from disk and display it at a chosen location in the program's window, but am getting a debug assertion error: atlimage.h
Line: 1624

Expression: hBitmap == m_hBitmap

The only initialization is:
CImage genericImage;
genericImage.Load(fName);

(it returns normally, with no errors)

Inside the WM_PAINT routine, the code is a simple:

genericImage.Draw( hdc, 0, 0);

Any ideas? It fails to paint anything if I ignore the debug error, and I can't find any suggestions in the documentation or example code, but I admit I find Microsoft's documentation pretty impenetrable.

Dervish1 37 Newbie Poster

I still consider myself a relative novice with javascript and html. However, once I finally understood the basics, I found the Dojo toolkit to be the most useful: you only load those pieces you need, its widget system is good for creating a consistent UI layer, and the way its DOM tools normalize things between browsers is a great convenience - without the obfuscatory style of several of the other toolkits.

It has a few cons, though. The ones that bite me the most are the poor documentation (especially at the intermediate level) and the relative difficulty of customizing some of the widgets (this is offset by the fact there's probably already a widget that does what you want).

Dervish1 37 Newbie Poster

Also don't forget that there's no guarantee the data written by fread doesn't have a null in it. So that's another reason that strlen is a bad way to figure out the buffer's length. (And to follow the above advice to use fread's return value).

Dervish1 37 Newbie Poster

I've used it more recently than that, but primarily when I was working on code generators for compilers - so everything else could be written in higher-level languages. In other words, there are certain environments where it's useful, but they tend to be pretty specialized, as Rubberman said.

Dervish1 37 Newbie Poster

Rather than arguing, try a web search: 'php login example' gives me several million(!) results.

Dervish1 37 Newbie Poster

I have a known good web page that works without (known) errors when it loads. However, when I try to load it using a very laggy connection (more than 6-10 seconds to load the page - when all works well, it can load in under 500 ms), my hosting provider seems to generate 503 (too many requests) messages, and of course loading fails.

The page uses several modules I've written, and uses an asynchronous loader to read them once, when they're needed, so a single page load will often generate 10-20 GET requests for assorted resources. (Actually, it's closer to 60, but the rest come from a Google CDN, without error).

The hosting provider doesn't seem to understand (or, perhaps, care) about this problem, of course. I'm curious, though: does this sound like something that could be automatically generated by Apache (e.g. using mod_security or mod_cband), and would this be something that didn't show up on the log? I am very much a novice with Apache config, but find this error is forcing me to learn it.

Also, is there something I can do, either with my javascript or some setting on my website to force a retry if this happens?

Dervish1 37 Newbie Poster

First, line 61 is a typo: '=' is not a comparison, but rather an assignment. But whether or not it's correct, are you sure your calling function is interpreting the false return correctly?

Dervish1 37 Newbie Poster

Try looking up 'javascript date convert' - the date object does all the work for you.

Dervish1 37 Newbie Poster

Since you're doing all the rendering work in your canvas, why not simply draw the squares you want on the canvas and change the rendering speed when the user moves over them?

As someone else suggested, search for 'collision detection' and write your own code to implement it. Trying to get the browser to do that work for you would require not using the canvas at all, I would think.

Dervish1 37 Newbie Poster

While that game example doesn't really make good use of jquery (it would be almost identical if written without using the jquery library -- drag and drop is built into HTML5 and doesn't require much extra work beyond what was already done there), making a game typically involves lots of customized UI elements for which jquery is probably a reasonable choice, and you won't be hurt by learning it.

Dervish1 37 Newbie Poster

Remember that everything on a web site has two parts: the part that comes to your browser (client side) and the part that stays behind on the server (server side). Client side is primarily javascript. Server-side, any general purpose programming language can work, so long as it does what you need. PHP will handle almost everything, so all those sites could have been written with PHP, but you could also write it in Perl, or even straight C (with some appropriate libraries, I suspect).

Dervish1 37 Newbie Poster

And if you wish to simply print text with a newline in it, it's \n, not /n.

Dervish1 37 Newbie Poster

I would think it's a matter of putting some code into the mouseover to modify the contents of the div. This forces a redraw, of course, which might be a bit ugly if you have a large grid that has to be redone.

Alternately, you might try assigning each item a tooltip with the full info you want.

Dervish1 37 Newbie Poster

I've got a web page that allows the user to create a canvas that can be as much as 50,000 pixels on a side (they're maps).

I draw everything on a canvas, scaled to the user's viewport. Unfortunately, you can't print a canvas; you have to convert it to an image and print that (at least, that's what I understand). I'd like to print something the size of the user's paper, but am at a loss to how to figure out that size, or even proportions so I can create a scaled view.

So, to print a map, I have to draw a new canvas, convert that to an image, and pop up a print window with that image as the sole contents. How do I set the dimensions of this new canvas to those of the printer? What are the dimensions of the printable area of a page for the user, and how can I create a window with those proportions?

Thanks for any thoughts.

Dervish1 37 Newbie Poster

You can also use some combination of server-side technologies with your code. For example, Javascript's xmlhttprequest (or however that's spelled) and something on the server-side to take its data and store it in your file.

Dervish1 37 Newbie Poster

This ends up being several different items, some of which I believe require javascript. HTML supports a text box, and you can put preloaded text into it. Using CSS you can make it a fixed height and scrolling. I don't know how, but I suspect CSS can let you auto highlight an entire line when you click.

But if you want to pop up a window, that will involve some (relatively simple) javascript. You would need to find out which line the user clicked on, and then select what image to load.

All of these you should be able to find online - try doing each one, one at a time.

If you don't have quite so much time, you might look at some of the various javascript toolkits out there. dojo (the one I'm most familiar with, not necessarily the best) supports several types of text box and might make the automation easier, if you can get past their sometimes-impenetrable documentation.

scarletfire commented: Thanks! +1
Dervish1 37 Newbie Poster

Even with multiple variants on the print style sheet, print preview and print both generate a blank page. Print Screen, on the other hand, isn't exactly acceptable for a user (but it works!). Yes, it is a dojo borderContainer, as LastMitch pointed out. (And changing the table to use a div container was unfortunately no better).

For those who might be interested in seeing details, a minimally-functional version is at androhil.com/docs/cgi/mapedit/mapedit.php - wait a moment for the page to load, and hit print preview; the problem is obvious.

I'm beginning to think Dojo's styling of the containing divs is what's at fault. This suggests I'll need to open a separate 'print ready' window and just copy the table there. It'll take a little while, just given the amount of free time I've got.

Dervish1 37 Newbie Poster

At present, it's just a very simplified style sheet. Nothing specific to printing. The page is based on a simple BorderContainer, which seemed to be the problem.

I'll give the print style sheet a try. I had been thinking I needed to make a 'printer ready' page.

Dervish1 37 Newbie Poster

I'm working on my first web app, and have a simple version of the application working. It allows the user to create and edit a fantasy map from a set of terrain tile images - but I can't figure out how to make it print. A print preview (and an attempted print) shows just a blank page (or a blank page with the background image), but no sign of the existing map. The map is generated as a simple HTML table with each tile being an <img>.

The application uses the dojo toolkit for organization and several utilities, so I suppose it /might/ be related to that, but I seem to get the same problem without using Dojo. Do HTML tables with no data other than a background image print at all?

Dervish1 37 Newbie Poster

I'm assuming you need to find the maximum and minimum grade of the whole set. Since your max and min functions only compare two grades (and you never call them -- you'll get an error if you try to compile what you have above), they need to be called for every grade entered. This should get you started.

Dervish1 37 Newbie Poster

Err ... no, I don't think it /can/ be static. After all, you are creating a new array each time the function is called and returning a pointer to it. The caller can change this array -- and should expect it to be the same on the next invocation.

GCC may well implement this in the way you want, but you can't rely on that to be the behavior used tomorrow, or with some other compiler.

Caveat: I haven't looked at the standard in some time. I *could* be wrong about the behavior of a string literal like that, but I know it's a great way to create bugs.

Dervish1 37 Newbie Poster

The pointer is invalid after the return. Exactly how it's implemented depends on the compiler. If you want to access it, you'll need to give it a scope that's permanent -- the most common way to do this is to make it a static or global variable.

In any case, yes, your string will always be in RAM. If you release the memory so other code can use it, then you can't guarantee that your pointer is pointing to anything useful. In the best of circumstances, using a pointer after release will cause your program to crash.

A more useful way to access a binary string like this without using up a large portion of available memory would be to access it from some other medium (such as a data file), using the file I/O functions. Access it a small chunk at a time, and you won't tie up 'several megabytes' holding the entire string.

Dervish1 37 Newbie Poster

I would suggest that your DLL return an appropriate pointer to these structures? I'm not familiar with the DLL environment, but it should be possible to mark said pointer as read-only, at the least.

Dervish1 37 Newbie Poster

Sorry, no, you can't get past this, whatever method you might want to use. Any files on the disk that don't already completely fill their last block can still be expanded to that point.

Dervish1 37 Newbie Poster

Thank you.
But it's working fast only on NTFS.
On my FAT32 stick/key I get these results:
your code: 22.5 sec
direct copy: about 23 sec
I think it's writing in all the clusters...

PS: I have tried also the other solutions from that thread, none of them are fast.

I'm afraid the standard libraries will all assume you actually want the file you're creating, and generally won't be significantly faster than the copy. I'm actually surprised that NTFS /doesn't/ have that problem. What would probably be quickest and most effective for your stated problem is simply to make the USB stick read-only, but if you really want to create an empty file without touching every sector included, I think you would have to write directly to your FAT file system sectors, and if something goes wrong it could render that disk unusable without a format. Exactly what sort of data you need to write is beyond what I remember, but give a search for FAT32 structure and for any direct sector I/O functions available through Delphi (or Windows). Once you know the sectors to write to and what information to write, I suspect it'll be very easy, although remember that the file directory information used by Windows is stored in more than one place, and that can cause you a lot of grief.

-- And, reading your previous messages more closely, implies that what I was suggesting is still unlikely to work. At …

Dervish1 37 Newbie Poster

As I'm reading this, what you have is an archive file that you want to copy one or more source files into. So what you want to do is copy all of the first file into your archive, then to copy all of the second file, and then the third, and so on.

Is that correct? If it is, it might explain how you want to structure your loops.

Note that when you get to extraction, you're likely to have a problem with figuring out where one file ends and the next begins. You might want to consider how you want to deal with that issue before you go too much further.

Dervish1 37 Newbie Poster

The only faster method I know of would be low-level operating system calls to allocate your disk sectors and update the directory without actually writing data to the allocated sectors.

I haven't seen any Delphi or Pascal libraries for this kind of function, but since I'm sure it's possible to write them, /some/body will have already done so. You'll have to search.

Dervish1 37 Newbie Poster

Try: http://www.freebyte.com/programming/delphi/

It gives you a selection of environments, as well as assorted libraries that might be useful. Lazarus FreePascal includes an IDE that might be familiar if you've done Windows programming.

Dervish1 37 Newbie Poster

The only problem with your year string is that it doesn't have a terminating null. It's not stored in the file as a C string, but rather as a set of four characters. The same goes for your other strings, but you are fortunate enough that they happen to be filled with nulls.

You can change the printf statements to use %c conversion instead of %s, or you can make the strings you read in one character wider and explicitly initialize them all to nulls. Since the final NULL never gets written, they will always be properly terminated.

Dervish1 37 Newbie Poster

One thing you *can* do, however, is to put some of the rendering code into a program that gets run before the web page is served. The code to draw the page still has to be available in the clear, but some of your content can be pulled up before becoming visible to the user.

For example, database code can be done via PHP or any of several other languages. All of the HTML is still visible to everybody, but the rest wouldn't be.

Dervish1 37 Newbie Poster

And, yes, I got the screen saver running. Therefore, it has already found the photos to use. It's simply deciding to show them in black and white. The problem is, it displays them in black and white, not color. That is not an option you're allowed to select in the screen saver .. so there's got to be some configuration error I've made, somewhere.

I don't see any option to select another slideshow than Windows Live Photo Gallery. I also haven't found any configuration file that might have set it up to display in some odd mode. Those seem to me to be the most likely ways to fix it.

It's certainly not important, but its annoying. The monitor also automatically shuts off fairly soon after the screen saver starts up, and that's probably more useful!

Dervish1 37 Newbie Poster

And, yes, I got the screen saver running. Therefore, it has already found the photos to use. It's simply deciding to show them in black and white. The problem is, it displays them in black and white, not color. That is not an option you're allowed to select in the screen saver .. so there's got to be some configuration error I've made, somewhere.

I don't see any option to select another slideshow than Windows Live Photo Gallery. I also haven't found any configuration file that might have set it up to display in some odd mode.

Dervish1 37 Newbie Poster

scanf is the input function in C. You'll want to ask the user for the size of the array, and then have a loop that reads their numbers. Do you know how to do a loop?

Dervish1 37 Newbie Poster

Ah ... well, that one's a math question. From a quick scan of Wikipedia, I believe your algorithm is right (except for the fencepost error at the end). You might want to check that part on a math forum...

Dervish1 37 Newbie Poster

I just got a new HP machine. It's one of those pre-built systems, and it came with Windows 7. My previous machine was an XP machine, and so I set up the new one almost exactly like the old.

However, one thing seems to work only in a very strange manner: the screen saver (slide show: display photos from my collection) works fine under XP, but under Windows 7, the Windows Live Photo Gallery only shows the images in black and white. The images are saved in full color (in fact, I have to work to display any of them in B&W), and the screen save obviously works, it just displays the files wrong, and I can't find any preferences page for it. Any ideas?

A Windows 7 newbie.

Dervish1 37 Newbie Poster

Your inner() function doesn't multiply the last set of values. On line 33, the loop termination should be j < size.

That's the only issue that comes to mind; assuming your inner product algorithm is correct.

Dervish1 37 Newbie Poster

I am far from an expert on Delphi, although I've been maintaining some inherited code that has been written in the language. I understand there are some differences, but you'll find it's almost identical to Pascal -- and there are a number of free alternatives to Pascal. Since Borland has sold TurboPascal and the new versions are far from cheap, I'm trying to port my code to FreePascal under Lazarus. I'm not sure it's the best choice, but it seems to be working; the only real issues I'm having are related to the database libraries (Units, in Pascal parlance), and it looks as if that will be a relatively easy interface issue to fix.

If you're used to the object-oriented structure as implemented in C++, FreePascal's will probably seem a bit clunky to you at first, but most of the features you can find in C++ are also available in Pascal/Delphi. Others will no doubt be able to tell you much more than I can.

Dervish1 37 Newbie Poster

I have to disagree. There's no reason a for loop should be preferred when you know the exact number of iterations -- the only difference between the three loops is when you do the test to see if it's time to stop looping: before any iterations have been run, at the start of the loop, or at the end.

In the case of a known number of iterations, it's certainly convenient to put the count at the start as well as having all of the initialization in a single statement, but there's no reason you have to do it that way other than convenience -- and for loops are preferred for many cases where the exact number of iterations is NOT known (such as list or tree traversal).

Dervish1 37 Newbie Poster

Assuming you're really wanting to find files that have a line beginning with that string, and not with any other characters in front of your SearcText, you might want to consider using strncmp, instead of strcmp. That will also cure your problem with any trailing text (such as a newline or a comment).

Dervish1 37 Newbie Poster

I would add that loop unrolling is a technique that is now best left to your compiler. As are optimizations such as moving the test to the beginning or end of the loop -- today's compilers will almost always produce better, faster, code than you will if you use the language constructs in a natural manner and avoid trying to tweak them for better speed -- in fact, many of those speed improvements get in the way of final optimization.

Optimization tends to be not quite as good with some older (>10 years old) compilers, as well as some vendor-specific ones. So this advice may not apply if you're working on an embedded system, for example.

Dervish1 37 Newbie Poster

I've always said that the best IDE for any project is the one you're most accustomed to. Assuming the one I've been using doesn't meet my needs in some way, then I look for newer versions of whatever I've been using before branching out.

I expect any change of development environment to slow me down for a while. It may only cost me a few hours, but it can cost days if I have to learn new coding habits before I can make best use of the tools.

In other words, the final choice really depends on what you need to do. VC is pretty comprehensive under Windows.

Dervish1 37 Newbie Poster

The short answer is that you are getting lucky. According to the standard, if the size of the data requested in malloc is 0, the result is implementation-defined. In your case, it appears to be allocating a small block of memory -- it's also legal for the compiler to return NULL, or to crash your computer (although that last is probably not very desirable!).

It's entirely possible, by the way, that you're writing over other memory that has been allocated to your program; this kind of error can be very hard to detect in more complex cases. At the very least, you should check the return value of malloc and do something different if it's NULL. I wouldn't expect this code to work in all environments.

Ancient Dragon commented: Good explaination :) +28
tux4life commented: Nice :) +8
Dervish1 37 Newbie Poster

First, the 'break' statement in find_index_of_max is probably not what you want. Instead, it returns the index of the first element greater than arr[0]. You'll need to examine all the elements of your array to find the largest. I would think it works with your example array, but if you swapped array[1] and array[2], it would still return 1.

You also need to call the function with actual values: find_index_of_max(arr,10,??) -- you need to declare a float to hold that number.