|
emmmatty1 wrote: The hook is installed in the InitDialog of this dialog.
How will it work then? You are expecting to install a global keyboard hook - So, the hook should be installed from within a system-wide DLL, so that it could continue to process the hook messages. If it were installed from within a dialog which is not system-wide, and would work only when the dialog thread is active.
Try this:
Step 1. Create a DLL and write the hook procedure in the DLL.
#pragma data_seg(".SHARED")
static HHOOK hKeyBD=NULL;
#pragma data_seg()
#define DLLEXPORT __declspec(dllexport)__stdcall
HINSTANCE hInst;
LRESULT DLLEXPORT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (((DWORD)lParam & 0x40000000) && (HC_ACTION==nCode))
{
}
return CallNextHookEx(hKeyBD, nCode, wParam, lParam);
}
BOOL DLLEXPORT StartHook()
{
hKeyBD=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc, hInst, 0);
return TRUE;
}
BOOL DLLEXPORT StopHook()
{
BOOL bStatus = UnhookWindowsHookEx(hKeyBD);
return bStatus;
}
BOOL CHodllApp::InitInstance()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
hInst=AfxGetInstanceHandle();
return TRUE;
}
Step 2. Start the hook from an external module and stop it when you're done. Write back if you have troubles doing this.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
For the life of me I can't work this out.
In the "apps" InitInstance I seed the random number generator by calling srand(time(NULL));
Then in a thread whenever I invoke rand() and print it out via cout it always has the value of 18467. Now rand() is invoked every minute or two so it's not like it's in a tight loop or anything like that. I never call srand again either. Just the once in the apps InitInstance function.
Anyone experienced this problem before? Currently using Visual Studio 2008. I even went so far as to apply SP1 to it just incase something was fixed. Such a simple thing not working is really annoying me.
Just to add if I print out rand() a few times in the apps InitInstance it works as expected. However once I call it from a UI thread it's always the same number.
modified on Monday, September 1, 2008 3:30 PM
|
|
|
|
|
jbem wrote: In the "apps" InitInstance I seed the random number generator by calling srand(time(NULL));
jbem wrote: Then in a thread whenever I invoke rand()
srand() is thread specific. You need to seed (call srand())
on every thread that will call rand().
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks. That did the trick.
|
|
|
|
|
Hi i am new to the concepts of vc++.
In my application i used a dropdown box where the user cab either pick the value from the dropdown or enter his own choice,after entering the value if the user is hitting the enter button my application is closing
i used the follwoing code in my pretranslate msg it is woking fine for all other controls except this dropdown box
if (pMsg->wParam == VK_RETURN)
{
//Call events on enter
PostMessage(WM_COMMAND, (BN_CLICKED << 16) | GetFocus()->GetDlgCtrlID(),(ULONG)GetDlgItem(GetFocus()->GetDlgCtrlID())->m_hWnd);
}
Can anybody suggest me the right approcah for doing this....
Thanks in advance..
|
|
|
|
|
|
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == 13)
{
return TRUE;
}
}
|
|
|
|
|
Hello. I have worked on some 2D development but now I am heading into 3D development and was wanting to create a virtual world but I really dont know how to. I would be grateful if someone could help me. If you want more information about the project I will be happy to tell you.
Thank you very much.
Andrew
|
|
|
|
|
That's not a trivial task. The easiest solution is to use an existing 3D engine: Irrlicht, Ogre3D, OpenSceneGraph, ...
The first two ones are targeted specifically for games. So I would suggest the last one (see here[^]). I never used it myself but I heard good things about it.
You could of course develop the 3D engine yourself but looking at your question, it will probably be very difficult.
|
|
|
|
|
Thanks for the quick reply. I have decided not to use a 3D engine for different reasons. I have already scripted a lot of files but now its the stage of scripting the source code. I have used the 3d engine for other projects but now I want to build it using my own source code with some help.
|
|
|
|
|
Well, then you will need to learn either OpenGL or DirectX, then learn how to render 3D scene (I suggest a good book on that because you will spend probably too much time if you have to search for that on the web) and also probably some math. Anyway, this can't simply be answered on a forum because it is really big.
MrMcIntyre wrote: I have already scripted a lot of files but now its the stage of scripting the source code.
What do you mean by 'scripting'
|
|
|
|
|
See when I have finished learning OpenGL or DirectX what will be the next stage.
|
|
|
|
|
MrMcIntyre wrote: See when I have finished learning OpenGL or DirectX what will be the next stage.
learn what a scene graph is, and how to write your own. I use open scene graph for a lot. One advantage is that I have written my own "back in the day." I understand the desire to learn from the inside out and I commend you for the desire. Study how the various scene graphs work, their advantages and disadvantages and how you want to style your own. In the end it helps you understand why the various groups made the decisions they did. It may help you keep your own, or choose one of the existing groups and support them. In the end I chose OSG, but I can do more with it because I understand it internally.
Good luck!
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
|
|
|
|
|
I meant programming sorry about that.
|
|
|
|
|
I have download OpenSceneGraph and had a look around the website and I am really amazed at what you can use the software for game, virtual reality and more. Now I have the enviournement maker, is it now down to the source code.
|
|
|
|
|
Hi guys,
I have a dialog box on mfc and put a picture control onto it.
Now it is no problem to load images from a path of my harddisk, they are shown well.
But i dont know, how to load BITMAPS dynamically into the control.
First I create a new Bitmap with the CreateBitmap() function from a Byte-Array.
The function returns a non-zero value, so it was successfull.
But now i have somehow to copy that bitmap into a memory-hdc, and from there
i should be able to load it into the control. but i dont get it!!!
I added a variable to the control from the type CStatic.
But why is it so complicated, to get that created HBITMAP onto the Control?
I mean, there IS a CStatic-function, which lets me SetBitmap(HBITMAP hBitmap)...
But it does not work!!!
I hope someone can help me...
Best regards,
cherry
|
|
|
|
|
Hi,
I don't think there's an easy answer to your question. I do not known what is wrong in what you did with the code. But, did you had a look into these articles?
1) Chris Maunder's DIBSection wrapper[^]
2) Chris Maunder's auto-sizing bitmap control[^]
3) Troels Knakkergaard's Drawing transparent bitmaps[^]
It might give you the clue you need it to figure out where the real problem is...
Best regards,
Mihai Moga
|
|
|
|
|
cherrymotion wrote: I mean, there IS a CStatic-function, which lets me SetBitmap(HBITMAP hBitmap)...
But it does not work!!!
What if you call Invalidate() on the static control after
you set its new bitmap?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for your help.
But I didn't get further...
I have to say, that my function is called after clicking a button.
But that should make no problems I think?!
That's my Code:
CBitmap *cBitmap;
HBITMAP hBitmap;
cBitmap = new CBitmap();
PAINTSTRUCT ps;
CDC *myCdc = m_whiteboard.BeginPaint(&ps);
HDC memory = CreateCompatibleDC(NULL);
CWnd* whiteWnd = m_whiteboard.GetWindow(2);
CPaintDC paintDc(whiteWnd);
hBitmap = CreateBitmap(iWidth,iHeight,1,8,pbFrame);
bool succ = BitBlt((HDC)&paintDc,0, 0,iWidth,iHeight,memory,0,0,SRCCOPY);
SelectObject(memory,hBitmap);
Invalidate(true);
ReleaseDC(&paintDc);
m_whiteboard.EndPaint(&ps);
|
|
|
|
|
Is there another option to realize this??
I would be really happy if somebody helps me...
|
|
|
|
|
There's a bunch of things wrong there
First you NEVER use a CPaintDC except in response to
WM_PAINT (in OnPaint()). A CPaintDC is not valid in
any other place.
Second, I can't tell how you're trying to create the bitmap,
but your calls are out of order. I'm not even sure how to correct
it without knowing what you want the bitmap to be.
Third, there's no code shown that has anything to do with
setting a picture control's bitmap, which I thought was the
original problem.
What are you trying to do?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello All !
I wish to hide (not display) the GUI of an MFC Dialog Based application on first run.
When I use ShowWindow(SW_HIDE) inside OnInitialDialog() it doesn't seem to work.
What should I do ?
|
|
|
|
|
The reason is, because as stated by the documentation on MSDN, OnInitDialog() is sent to the dialog box during the Create, CreateIndirect, or DoModal calls, which occur immediately before the dialog box is displayed, therefore if you call ShowWindow(SW_HIDE) then the window will be shown after OnInitDialog() returns.
To solve this you should create your dialog without the WS_VISIBLE style.
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
OK.
But where do I turn off the WS_VISIBLE flag ?
Since it is a Dialog application there is no PreCreateWindow message.
When I try to overwrite the structure in the OnCreate() it seems that it is already turned off.
Should do it through OnInitialDialog() ?
Or elsewhere ?
Thanks,
Amit
|
|
|
|
|
Is your dialog created from a resource?
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|