|
ODS_HOTLIGHT 's not work with CListBox. Why? How to solve this?
|
|
|
|
|
I don't think the list box control has "hot track" features (correct me if i am wrong). Try using a list view (CListCtrl / SysListView32) instead, or use WM_MOUSEMOVE and TrackMouseEvent[^] to add this feature yourself. Shouldn't be that complicated.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
I'm sorry, but i have no idea about this. This's ListBox. How to get the item that mouse 's hover with TrackMouseEvent()?
|
|
|
|
|
Well, you don't get that item with TrackMouseEvent, what you can do is handling WM_MOUSEMOVE, you can find the item the mouse is over using ItemFromPoint[^], and you use TrackMouseEvent to know when the mouse leaves since by default you get no message whatsoever about that. But to save yourself all the trouble figuring this out, you should really consider CListCtrl[^] instead, just like Iain suggested too.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
|
Hello,
I would like to emit the lable addresses from a bit of inline assembly code into a branch table but I could not figure out how to do it.
I would say it should look something like this. At least the compiler emits something like this for a switch statement. I am using visual studio 2005.
__asm
{
mov eax,BRANCHTABLE
mov ecx,"Number between 0 and N"
jmp [eax+ecx*4]
BRANCHTABLE
&LABLE0
&LABLE1
&LABLE2
...
&LABLEN
LABLE0:
...
LABLE1:
...
LABLE2:
...
...
LABLEN
}
Thanks
|
|
|
|
|
In MASM, possibly - but in inline assembly, you can't use operators such as & and you can't declare initialised data (which is what you're doing). I really don't know how you'd go about that. Maybe replace hte branchtable by a switch statement with interspersed inline assembly?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi Remco,
I created this little inline assembly sample for you. It loads the addresses of code labels into a jump table and allows you to jump to the offset based on a user choice. I commented each line.
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
#pragma pack (1)
unsigned long table[3] = {0};
#pragma pack(pop)
char szError[] = "Invalid choice.\n";
char szPrompt[] = "Enter a number between 1 and 3:\n";
char szNotify[] = "You entered jump number: %d";
char szFmt[] = "%d";
int iChoice =0;
int iSizeArray = (sizeof(table) / sizeof(table[0]));
__asm
{
lea esi, table ;Load address of table into esi
mov edx, DWORD PTR jump1 ;Move address of jump1 into edx
mov [esi], edx ;Move edx into table[0]
add esi, 4 ;Increment esi by size of unsigned long
mov edx, DWORD PTR jump2 ;Move address of jump2 into edx
mov [esi], edx ;Move edx into table[1]
add esi, 4 ;Increment esi by size of unsigned long
mov edx, DWORD PTR jump3 ;Move address of jump3 into edx
mov [esi], edx ;Move edx into table[2]
lea eax, szPrompt ;Load effective address of prompt
push eax ;push eax onto stack
#ifdef _DLL ;Are we dynamically linked to C runtime?
call DWORD PTR printf ;Call dynamic linked printf
#else
call printf ;Call static linked printf
#endif
add esp, 4 ;adjust stack pointer because we pushed eax
lea eax, iChoice ;Load effective address of iChoice
push eax ;Push it onto the stack
lea ebx, szFmt ;Load effective address of fmt
push ebx ;Push it on the stack
#ifdef _DLL ;Are we dynamically linked to C runtime?
call DWORD PTR scanf ;Call dynamic linked scanf
#else
call scanf ;Call static linked scanf
#endif
add esp, 8 ;adjust stack pointer because we pushed eax and ebx
mov eax, iChoice ;Move iChoice value into eax
mov ebx, iSizeArray ;Move the size of our array into ebx
cmp eax, ebx ;compare
ja error ;Jump to the error lable if iChoice is larger than table array
dec eax ;Decrement iChoice by 1 because the table is zero based array
lea esi, table ;Load address of table into esi
mov eax,[esi + 4*eax] ;Move value of table array onto eax by calculating offset
jmp eax ;Jump to address stored in eax
jump1:
mov eax, 1 ;Move number 1 into eax
jmp notify ;Absolute jump to notify label
jump2:
mov eax, 2 ;Move number 1 into eax
jmp notify ;Absolute jump to notify label
jump3:
mov eax, 3 ;Move number 1 into eax
jmp notify ;Absolute jump to notify label
error:
lea eax, szError ;Load effective address of error
push eax ;push eax onto stack
#ifdef _DLL ;Are we dynamically linked to C runtime?
call DWORD PTR printf ;Call dynamic linked printf
#else
call printf ;Call static linked printf
#endif
add esp, 4 ;adjust stack pointer because we pushed eax
jmp end ;Absolute jump to end label
notify:
push eax
lea ebx, szNotify ;Load effective address of notify
push ebx
#ifdef _DLL ;Are we dynamically linked to C runtime?
call DWORD PTR printf ;Call dynamic linked printf
#else
call scanf ;Call static linked printf
#endif
add esp, 8 ;adjust stack pointer because we pushed eax and ebx
end:
}
return 0;
}
Best Wishes,
-David Delaune
|
|
|
|
|
Oooh - nice. I'd wondered if there was a way to create the jump table as a C variable, but hadn't thought of initialising it in assembly code.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello Stuart and David,
Thank you for your replies. Both solutions given are practical I think. I intended to use the branch table inside a time ciritcal part of my ray-tracer (ray vs axis aligned bounding box intersection test). I am building a stream ray-tracer using the sse ALU processing four rays in parallel. But the number of rays to process is not always a multiple of four to process the last 1,2 or 3 rays I thought to use a branch table. But I think I will make a funciton one for each case and use a switch statement ouside of the filter functions making the code easier to read and the c++ compiler does emit the code I would like.
Thank you for your help!!
|
|
|
|
|
A lot of jumps, and certainly those through a jump table, introduce a hickup in the instruction flow, as they are not predictable at all; so I'd rather avoid them.
assuming lots of rays I would take a different approach: if not a multiple of four, calculate one of the rays multiple times, e.g. duplicate the last ray one to three times so the number always is a multiple of 4. That probably will be simpler and may be faster.
|
|
|
|
|
Yes conditional branches can be expensive causing pipeline stalls. But in my implementation using streams of rays there is only one hard to predict branch and that branch is only taken once per processed stream so it is not really that important. But a c++/assembly mix looks alittle bit messy. Thats why I removed the branch table from my inline assembly function to improve code readability at the expense of code size. Expanding the number of rays per stream to a multiple of four is for me not an option because rays are partitioned in place. Meaning that the filtered stream or output stream should be of the same length compared to the input stream.
Thanks
|
|
|
|
|
I forgot to mention one technique I often use in cases like this, where the expensive jump is taken only once (upon entry); I'll describe it in pseudo-code, it basically is a loop unroll by 4:
switch(count%4) {
case 0:
goto case1;
case 1:
goto case2;
case 2:
goto case3;
case 3:
count-=4;
if (count>0) goto case0;
}
You can do this in any language, with a switch or with labels and jumps (and if the language allows fall-through, you may skip most of the goto's). In assembly, you would still need labels.
|
|
|
|
|
Hello,
I placed a break in the function OnKeyDown() of a class derived from CRichEditCtrl. But when I press F5 and debug the code the code doesnt proceed further but when I remove the break in the fucntion the code goes ahead . Ith this I am not able debug the OnKeyDown.
What should be done ?
Pritha
|
|
|
|
|
prithaa wrote: But when I press F5 and debug the code the code doesnt proceed further
Any further than what?
A breakpoint is meant to stop the code - you then have the option of what to do to make the execution progress.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for your reply
But when I press F5 the code goes further that is the cursor moves ahead but the the action doesnt reflect in the execution like suppose after pressing a right arrow key I want the cursor to move further on the dialog then the cursor doesnt move on the dialog. whereas if I remove the break in the OnkeyDown then cursor moves in the dialog.
I hope the question is clear.
Pritha
|
|
|
|
|
Well, if I've understood you correctly, that's because the breakpoint keeps on breaking - every time you hit OnKeyDown
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello,
Thanks
What is the meaning of the breakpoint keeps breaking ?
Pritha
|
|
|
|
|
Every time you reach the OnKeyDown handler, it'll break at the breakpoint.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks
so I should not be using breaks in OnKeyDown() is it? .It is wrong to use it like that ?
Pritha
|
|
|
|
|
Well - what's the bug you're trying to find?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Like all console input (keyboard, mouse events, windows focus and caret management) it's better to debug with writing debug messages to some (console or file). We either practice use Beep 's.
|
|
|
|
|
OK... I see two scenarios you are describing:
1/ With breakpoint.
a) App is running.
b) Focus is in a window.
c) You press f5.
d) This is a key going down, so the CSomeControl::OnKeyDown handler is called.
e) You have a breakpoint there, so it, erm, breaks and goes into the debugger, allowing you to debug you OnKeyDown handler.
This is a good thing.
2/ With no breakpoint.
a) App is running.
b) Focus is in a window.
c) You press f5.
d) This is a key going down, so the CSomeControl::OnKeyDown handler is called.
e) You have no breakpoint there, so the application carries on happily.
This is a good thing.
This may be a language problem (don't apologise for that!), but I can maybe see a 3rd scenario:
1/ With breakpoint.
a) App is running.
b) Focus is in a window.
c) You press some key.
d) This is a key going down, so the CSomeControl::OnKeyDown handler is called.
e) You have a breakpoint there, so it, erm, breaks and goes into the debugger, allowing you to debug you OnKeyDown handler.
f) You press f5 to carry on with the program, and it no longer works
If #3 is true, then I bet you're forgetting to hold down the original key before continuing execution. You application may be thinking "so, when is he releasing that key!? It's been down for a long time...".
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/[ ^]
|
|
|
|
|
Thank you
I think the scenario is very much possible but then debugging OnKeyDown is pretty much difficult or not possible.
Thanks
|
|
|
|
|
I want to call any class from unmanaged dll. How can i do?
class __declspec(dllexport) foo{
public:
foo();
~foo();
void sum(int a, int b);
};
[...].class Foo{
[...]
void sum(int a, int b);
}
|
|
|
|
|