|
I would agree with Maximilien in that there is a better way to go.
But first the problem you are experiencing is caused by the fact you are saving the image in photoshop as a full RGB color range of 24 bits. When you go to display it on a system that cannot support that color range, the colors are down converted to the displays setting range (16 bit in this case). The solution is to save the image in Photoshop using smaller palatte. Try using Image->Mode->Index color on the menu and save to a 256 color system palatte to get you image colors downselected.
Back to your method... I would suggest you look at an article submitted last month here in CodeProject. I can't remember the name of the author but the program name was something like "Periodic Table" or PTE table.. where the author used some very good techniques to accomplish the same task of locating the periodic table element from the mouse position.
Hope this helps.
Art
|
|
|
|
|
Art Friesz wrote:
using Image->Mode->Index color on the menu and save to a 256 color system palatte
I am using indexed colour in photoshop.
Art Friesz wrote:
would suggest you look at an article submitted last month here in CodeProject. I can't remember the name of the author but the program name was something like "Periodic Table" or PTE table
This article was written by one of the guys that was helping me before, back in september. He started that article because I was asking about it back then. Seeing as I had never done anything with colours/bmp's in my applications before, I ended up needing quite a bit of help, as i guess I still do.
|
|
|
|
|
OK, if it were me and I just wanted to get this problem solved I would do one of the following:
Option 1) Compare on a range of RGB values. Example: allow a match of the RGB color provided in the txt file if the mouse pickuped a value within say 5 of each of the RGB values. In other words Hydrogen would be matched if the mouse picked up a R value between 51-5=46 and 51+5=56 and G and B was between 0 and 5.
or Option 2) (the preferred way)
Change your text file to include the percentages of the grid they occupy in the image and then pick up the mouse position on the window and convert it to percentage of the window width and height, then match the point in the rectange:
(Element Name, Element symbol, atomic no., x1,x2,y1,y2)
Example: text file would look like this:
Hydrogen,H,1,0,6,0,8
Helium,He,2,0,6,10,18
...
When you read in the txt file use the x1, x2.. for the coordinates in a CRect. Use CRect::PtInRect()to look for a match.
Art
|
|
|
|
|
I used your idea for option 1... that fixed my problem. thank you very much!
|
|
|
|
|
Windows remaps colours to best match the available palette. 4- and 8-bit modes are palettized; you can specify the palette you want to use by calling RealizePalette. You should do this in response to a WM_QUERYNEWPALETTE or WM_PALETTECHANGED message.
In 16-bit mode, the available range of colours is typically limited to 5 bits per pixel for red and blue colour information and either 5 or 6 bits per pixel for green colour information. The colour you request is mapped onto the bits available; when you request the colour of the pixel, the value is mapped back onto the 0 to 255 range. This conversion can be subject to rounding errors.
If we say that Red is limited to 5 bits of representation, that gives us values 0 to 31. Mapping your 51 in the 0-to-255 to this range gives 6.375, rounded down to 6. When getting the pixel colour, the actual 6 in the 5 bit world now becomes 48 in the 8 bit world. I assume that Windows isn't doing a direct mathematical conversion, probably factoring gamma into the equation as well, which leads to the specified 49.
Anyway, you can't rely on the colour retrieved from GetPixel being the colour you set. It's better to work with areas of an image than with colours, if possible. Alternatively, work directly with the original bitmap, rather than the on-screen representation of it.
|
|
|
|
|
I’m trying to reset the Dialog box (CFileDialog) with the last configuration set by the user (like view menu by detail and sort by date). How can I do?
I use always the Windows 2000 CFileDialog box presentation.
Denislef
|
|
|
|
|
I am having a WinApi Application. In that WinApi application I am having
a function that when called creates a web browser like gui with
interactivity and functionality to display certain kind of documents.
Now, I add an activex project to the current workspace. I make this project
dependent on the WinApi Application. I include the headers required to call
the gui displaying function in C{}. When I make the activex project I get
the following errors
warning C4273: '_getpid' : inconsistent dll linkage. dllexport assumed.
error C2065: 'NOERROR' : undeclared identifier
Please Help
|
|
|
|
|
Hi,
Can someone write a function that reverses a string in the most optimized manner? meaning it should use as few variables, loops etc as possible.
|
|
|
|
|
Why dont you try urself....??
|
|
|
|
|
This is what I got
char *start = string;
char *left = string;
char ch;
while (*string++);
string -= 2;
while (left < string)
{
ch = *left;
*left++ = *string;
*string-- = ch;
}
return(start);
Now what do u have???
|
|
|
|
|
No temps in reverseString at all, and only one loop which goes halfway along the string. It is an in-place reverse, so it overwrites whats there.
If I was feeling really keen I could turn it into a template too
#include <iostream><br />
#include <cstdio><br />
<br />
using namespace std;<br />
<br />
void reverseString(char *str, const int &len)<br />
{<br />
for(int i=0; i<(len-1)-i; ++i)<br />
str[i] ^= str[(len-1)-i] ^= str[i] ^= str[(len-1)-i];<br />
}<br />
<br />
int main()<br />
{<br />
char str[] = "String to reverse!";<br />
int len = strlen(str);<br />
<br />
cout << str << endl;<br />
reverseString(str, len);<br />
cout << str << endl;<br />
return 0;<br />
}
--
Ian Darling
"The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky
|
|
|
|
|
So, what's wrong with std::reverse ? The compiler's supplied library is usually pretty well optimised for the task in hand.
In the general case, forget about trying to eliminate variables, loops etc in your code. The compiler can do that when it optimises - unrolling loops, enregistering variables, removing common terms.
Compile your code in release mode for a simple implementation, then see what the compiler did with it. Shortest C++ code is not necessarily shortest or fastest object code.
So, the best optimised code is probably
void ReverseString( char* sz, size_t len )
{
char ch;
for ( size_t idx = 0; idx < len / 2; ++idx )
{
ch = sz[idx];
sz[idx] = sz[len - idx - 1];
sz[len - idx - 1] = ch;
}
} The compiler hoists the division of len by 2 out of the loop (and also converts it to a right-shift by 1). It also converts the sz[len - idx - 1] terms into a pointer and moves it back down from the end.
Finally, it uses the dl register (the least significant byte of edx to store ch , which is never stored to main memory.
Stick to simple code.
|
|
|
|
|
My guess would be this is what the lecturer is looking for too
--
The Obliterator
|
|
|
|
|
Thank you for your comments.
I agree with you that code should be simple, atleast for maintenance purposes.
|
|
|
|
|
__inline char *StrRev(char *Source, char *Dest)
{
char *p = strchr(Source, '\0'), *p2 = Dest;
while( --p >= Source )
*p2++ = *p;
*p2 = '\0';
return Dest;
};
Phil
|
|
|
|
|
Nice.
Actually the initial problem required the original string to be reversed (which i forgot to mention). I have used your nice logic to modify my function
void Reverse(char *src)<br />
{<br />
char *p = strchr(src, '\0') - 1;<br />
<br />
while (src < p)<br />
{<br />
*src ^= *p ^= *src ^= *p;<br />
src++;<br />
p--;<br />
}<br />
}
-Melwyn
|
|
|
|
|
hi,
I want to start a procedure wenn my dialog has been drawn and initialiezed. Witch Windows Message Handler do i have to use?
greetz willem
|
|
|
|
|
OnInitDialog/WM_INITDIALOG
|
|
|
|
|
no it doesn't work;
BOOL CImportProcessDlg::OnInitDialog()
{
CDialog::OnInitDialog();
for (long i = 1; i < 100000; i++)
{
m_Tekst.Format("%d", i);
UpdateData(FALSE);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
if i run this the dialog just waits till i = 1000000 and then it pop's up... :S
|
|
|
|
|
Try this:- Add a hidden button to your dialog, with id
ID_RUN_LOOP .
- Write a handler for the
ID_RUN_LOOP command. The handler should execute the for loop.
- In your dialog's
OnInitDialog() handler, do this: PostMessage (WM_COMMAND, ID_RUN_LOOP); This should cause the loop to be executed after your dialog has been initialized and shown on the screen.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Another way is to use Timers.
1. Create a timer in OnInitDialog()
2. In the timer function do the for loop and then destroy the timer.
|
|
|
|
|
I have a DLL I wish to use in my app, but I have no associated header, def, lib, etc fils... just the DLL itself.
How exactly do I work with this?
I've tried creating a definition file for it but only 4 functions are generated (DllCanUnloadNow, DllGetClassObject, DllRegisterServer & DllUnregisterServer).
I'm know the DLL provides other functions but how to get to them???
I can load the library but where to go from there? I've tried using GetProcAddress() to retrieve the address of what I think the function I want is called but without success.
Cheers all
--
The Obliterator
|
|
|
|
|
You can see the exact names of the exported functions through Dependency Walker (a tool in vc++). However, u won't be able to see the no. of function parameters, their data types etc.
|
|
|
|
|
Thanks, but that lists just the same 4.
I must be missing something really obvious!
--
The Obliterator
|
|
|
|
|
Those particular functions should be a warning sign: the DLL implements some COM objects.
You could use the OLE/COM Object Viewer (supplied with VC6) to see if it's got a type library (use File > View TypeLib). From here, you can save an IDL file.
|
|
|
|