|
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.
|
|
|
|
|
Perfect! Thats what I needed...
I'm not used to these new fangled ways!
Figured out I have to #import the dll into my project and used the idl file to get to various interfaces... cheers.
Seems a very complicated way to me!
--
The Obliterator
|
|
|
|
|
Obliterator wrote:
I've tried creating a definition file for it but only 4 functions are generated
How did you do this?
|
|
|
|
|
|
Hello,
Kindly help me as soon as possible.
Problem:
When i run the "Dialog Based" Application in VC++, then the focus is set currently to the BUtton or any other control.
I want, that the focus should always be set on the "Dialog" even if we press "Button" .
e.g. 1) Run the Application.
2) When i click the button, and after clicking it, the focus should be return to the Dialog.
Hoping for a positive response
EsHbAn BaHaDuR
|
|
|
|