|
I need some programming advice to a specific problem I am having in my app. I have a bunch of owner-drawn buttons on the main window, all of which work with a tooltip through a hook. I have subclassed the windows to receive the WM_LBUTTONDOWN and WM_LBUTTONUP messages. When the user clicks on the button a "push" is simulated through InvalidateRect and through BitBlt in WM_DRAWITEM a new bitmap is painted when the mouse button is pressed down and then the button is repainted upon WM_LBUTTONUP. All this works fine expect when the tooltip is showing. I am thinking it has something to do with the hook. Does someone have a workaround for this. Here is the code to the hook procedure:
<br />
LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)<br />
{ <br />
if (nCode < 0) <br />
return CallNextHookEx(cSkinObject.hMsgHook, nCode, wParam, lParam); <br />
<br />
switch ( ((MSG*)lParam)->message ) <br />
{ <br />
case WM_MOUSEMOVE:<br />
case WM_LBUTTONDOWN:<br />
SendMessage(hwndTool, TTM_RELAYEVENT, 0, lParam);<br />
<br />
break;<br />
<br />
default: <br />
<br />
break; <br />
} <br />
return CallNextHookEx(cSkinObject.hMsgHook, nCode, wParam, lParam); <br />
}<br />
<br />
Thanks in advance.<br />
|
|
|
|
|
SendMessage?
Try to use Postmessage.
The problem might be, that SendMessage does not return, until the message is processed.
G. Steudtel
|
|
|
|
|
Hello Im very new to windows proramming. I have a very basic question and thank you in advance for spending time to answer it.
I created a standard Dialog Box thru Appwizard (VC++ 6.0).
I need to use a function that needs the boxs' handle as the first parameter
where can I find this? I look on InitInstance and the construcor but I cant seem to find where the member variable is.
please help.
Thank you again
|
|
|
|
|
|
|
I've been looking at the documentation of GetSafeHwnd()
it was attached to a member variable of a window.
ex. m_csEdit.GetSafeHwnd(param1,param2) ;
It can make it work for controls within my Dialog box but
not with a Dialog box itself.
Would someone be able to show me a skeleton code?
I need to get a handle of the only Dialog box I have
created by Appwizard(my program is Dialog Based).
Thanks everyone
|
|
|
|
|
Hiya I have a string in a file e.g
char buffer[] = "mike,jones,28,accountant";
and 4 variables: char FirstName[30],Surname[30],Age[30],Occupation[30];
What I am trying to do is split up the string and store each field in its relevant variable i.e store mike into FirstName and so on.
I have actually done this and it works fine but it is a very long winded approch. e.g
pDest = strchr( buffer,ch );
position = (int)( pDest - buffer );
for( i=0;i
|
|
|
|
|
If you use MFC, you may try AfxExtractSubString (the undocumented function declared in afxwin.h ).
If you don't, it would be wise to write a parser class instead of putting clumsy inline code into your application itself.
Regards,
BB
|
|
|
|
|
|
hello
i creat a vector in class named foufou vector< foufou * > fou_caracter; and in an other class i store in the vector a random position that i generat
by rand
void creatfoufou::creatfou(int amount)<br />
{<br />
foufou *newfoufouPtr;<br />
<br />
int speed,steer;<br />
<br />
for(int index=0;index<amount;index++)<br />
{<br />
<br />
<br />
ptrfoufou->initPosX =( ( 1 + rand( ) % 100 ) - 50 );<br />
ptrfoufou->initPosY =( ( 1 + rand( ) % 100 ) - 50 );<br />
ptrfoufou->initPosZ =( ( 1 + rand( ) % 100) - 50);<br />
<br />
newfoufouPtr = new foufou();<br />
fou_caracter.push_back( newfoufouPtr );<br />
<br />
<br />
<br />
<br />
}<br />
}<br />
<br />
and in an other function i want read the vector but i don't can
void creatfoufou::iteratorVector()<br />
{<br />
<br />
creatfou(5);<br />
int vectorIndex;<br />
vectorIndex = fou_caracter.size();<br />
<br />
for (int i=0;i<vectorIndex ;i++)<br />
{<br />
<br />
ptrfoufou->RePaint(<br />
fou_caracter[i]->initPosX,<br />
fou_caracter[i]->initPosY,<br />
fou_caracter[i]->initPosZ);<br />
}<br />
<br />
<br />
}
what is the error with this???
|
|
|
|
|
Your loop is not correct!
for( int i=0; i < vectorIndex; i++ ) and do not use (->) to access fou_caracter!
|
|
|
|
|
sorry
can you precise i don't understand very well what i must use to access to fou_caracter,because it my first time to use the vector
|
|
|
|
|
Hi,
I use the msdn code for getting multiple lines in a CEdit to a CString and it works great. But my problem is when a line have only 1 character the CString value return by the code below do not have the corresponding character but a \0 (i think, well it's like a \t or \r or \n in the debug, it's a square)
This is the code I use (line is return in strText)
int n = TempEditM->GetLineCount(); // Récupère le nombre de lignes
for (int i=0;i<n;i++)
{
int="" len="TempEditM-">LineLength(TempEditM->LineIndex(i));
TempEditM->GetLine(i, strText.GetBuffer(len), len);
strText.ReleaseBuffer(len);
}
Can you help me please ?? Thanks you very much
|
|
|
|
|
I think what you are seeing is the 'soft line-break' character but I could be wrong.
You can view the memory:
LPTSTR szBuffer = strText.GetBuffer(len);
TempEditM->GetLine(i, szBuffer, len);
strText.ReleaseBuffer();
ÿFor the bread of God is he who comes down from heaven and gives life to the world. - John 6:33
|
|
|
|
|
hi,
The value of the character is 0x01... But i'd like to have the right character. For exemple, if my edit box ahve the lines :
abcdefghijklmnop
q
The first return is strText is : "abcdefghijklmnop"
and the second is : char(0x01) but not "q"
Do you know why i get this 0x01 instead of the "q" ??
Thank you .
|
|
|
|
|
well, I had some check in my code :
int n = TempEditM->GetLineCount(); // Récupère le nombre de lignes
for (int i=0;i<n;i++)
{
="" int="" len="TempEditM-">LineLength(TempEditM->LineIndex(i));
if (len!=1)
{
TempEditM->GetLine(i, strText.GetBuffer(len), len);
strText.ReleaseBuffer(len);
}
else
{
TempEditM->GetLine(i, strText.GetBuffer(len+1), len+1);
strText.ReleaseBuffer(len+1);
}
}
and it work
thanks you, bye
|
|
|
|
|
Hi!
I'm using the new HTMLEdit classes introduced in VS.Net. I'm writing a Html Edit programm that allows the user to create tables.
I've a question about the selection of the cells: is it possible de change a property (or add some extra code) so that the user can select cell by cell like on a spreadsheet? (ie extend the selection). For now, when a user try to select cells, all the row is selected......
Thks in advance!
Appstmd
http://www.appstmd.com
|
|
|
|
|
I'm experimenting with hooking, but when I do the following:
hWndsHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc, NULL, NULL);
I expect it to run:
LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HCBT_CREATEWND)
{
HWND hWnd = reinterpret_cast<HWND>(wParam);
LPCBT_CREATEWND lpcw = (LPCBT_CREATEWND)lParam;
LONG lpCreateParams = (LONG)lpcw->lpcs->lpCreateParams;
::SetWindowLong(hWnd, GWL_USERDATA, lpCreateParams);
}
return CallNextHookEx(hWndsHook, nCode, wParam, lParam);
}
But it doesn't. There are no compile warnings or whatsoever. I tried to debug it, but when marking it with a breakpoint (at CallNextHookEx) for example, it doesn't break, and it sure doesn't do what I want it to do. And I really am creating windows with CreateWindow, which does do what it needs to do (The MessageLoops work).
LPCTSTR Dutch = TEXT("Double Dutch ");
|
|
|
|
|
Did you check the return value of SetWindowsHookEx ?
If you specify a thread id NULL, you handle must be valid, and it must be inside of a DLL. If you want to hook your own application, than you must call GetCurrentThreadId() . By the way, hook are pretty difficult to debug. That's the reason for WH_DEBUG !
Hope that helps, Good luck!
ÿFor the bread of God is he who comes down from heaven and gives life to the world. - John 6:33
|
|
|
|
|
Well, when I wrote the thing and uploaded it, in a minute I knew the solution, It works great.
The function looks like:
static LRESULT CALLBACK CBTProc(int nCode,
WPARAM wParam,
LPARAM lParam)
{
if (nCode == HCBT_CREATEWND)
{
LONG counter = 0;
HWND hWnd = reinterpret_cast<HWND>(wParam);
LPCBT_CREATEWND lpcw = (LPCBT_CREATEWND)lParam;
LONG lpCreateParams = (LONG)lpcw->lpcs->lpCreateParams;
if (lpCreateParams != 0 && lpcw->lpcs->hInstance == __hInstance__)
{
for (iIterator = arrUnboxedClasses.begin(); iIterator != arrUnboxedClasses.end(); iIterator++, counter++)
{
if (arrUnboxedClasses.at(counter) == lpCreateParams)
{
::SetWindowLong(hWnd, GWL_USERDATA, lpCreateParams);
goto end;
}
}
}
}
end:
return CallNextHookEx(__hWndsHook__, nCode, wParam, lParam);
}
I still think that another application may not crash because I install a hook, this is not a really good design, I think.
LPCTSTR Dutch = TEXT("Double Dutch ");
|
|
|
|
|
Friends i need to know about the overhead involved in a function call w.r.t Visual C++ compiler.
Actually i am writing a server based aplication in which speed and efficiency are the primary requirements. There is a function in my program which makes some complex calculations. This function is called by a for loop about 150 times. I also make this function inline function, but i've read in number of C++ docs that making a function inline is of no guarantee that compiler really makes it inline and it depends on a compiler to decide whether to "paste" the code or to keep it a separate function.
So i am in confusion that in my application, a loop is calling the function 150 times and if too many clients send request and i call this function 150 times for each request then there will be lots of CPU cycles required which decreases the efficiency of my application.
So what do you people suggest me to do? Please also tell me the cost involved in calling a function and also tell me how can i judge that the compiler really makes my function inline or not ??
Thanks
|
|
|
|
|
Don't worry about it. From your description, the process of setting up a new stack and calling a subroutine isn't the bottleneck. Removing those steps would not gain any significant time compared to the big complex function.
--Mike--
Eh! Steve!
Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
A function call will take up CPU time, however it is very minimal as compared to what you are doing inside the function.
Bringing the function inline could actually make the operation slower under certain circumstances since it could change the optimization.
All this is mostly irrelevant since optimizations shouldn't be based on theory but on measurable results always keeping in mind the adage that 90% of your time is spent in 10% of your code. Also, the algorithm itself is more important than the implementation.
(By chance I was doing some optimizing this morning. So I modified the test a little and found that making an intermediate function call added about 8 CPU cycles per call on a Celeron 900. The result with the new algorithm was still 4x faster than the original algorithm.)
PS. You could use the keyword __forceinline if your test show that this will improve performance.
|
|
|
|
|
Well, I know someone who makes a 3D-graphics engine, it really does matter pushing things on the stack or not. So I think a compiler should just inline when you want it to inline. Which doesn't gain much over complex calculations, but simple calculations, at the other hand, do matter.
LPCTSTR Dutch = TEXT("Double Dutch ");
|
|
|
|
|
S van Leent wrote:
it really does matter pushing things on the stack or not
It MAY matter, performance wise. If speed is of most importance, a developer may choose to use the __fastcall modifier on functions. However, if speed is that important, you should always test your code, not simply presume it is faster one way over the other.
S van Leent wrote:
So I think a compiler should just inline when you want it to inline.
I totally disagree. The standard is quite correct in this regard. For convenience, or when using templates, developers may implement a member function in the header, either explicitly inline or within the body of the class definition. If all of those are automatically inlined, it will result in bloated code and may very well result in slower code. (Beyond CPU cycle counts, bloated code will result in more paging which will have a devastating effect on performance.)
In general, unless you really understand the CPU architecture, you should just write clean C/C++ code and let the compiler do it's thing.
Again, most performance bottlenecks are in a tiny part of the code and can often be fixed by using a better algorithm and in understanding and leveraging the OS better.
|
|
|
|