|
See if you can use CPrintDialog::GetPrinterDC
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Thanks to your reply.
I don't want to use MFC, I need a solution with windows API.
DMASTER
|
|
|
|
|
|
|
HDC hDC;
CDC PrinterDC;
hDC = CreateDC( NULL, "YOUR PRINTERNAME", NULL, NULL );
PrinterDC.Attach( hDC );
DOCINFO stDocInfo;
memset( &stDocInfo, 0, sizeof( DOCINFO ));
stDocInfo.cbSize = sizeof( DOCINFO );
stDocInfo.lpszDocName = _T( "TEST" ); // Document name
StartDoc( hDC, &stDocInfo );
CPen DrawPen( PS_DASH, 5, RGB( 0, 0, 0 ));
CBrush DrawBrush( HS_BDIAGONAL, RGB( 0, 0, 255 ));
PrinterDC.SelectObject( &DrawPen );
//PrinterDC.SelectObject( &DrawBrush ) ;
PrinterDC.SetBkMode( TRANSPARENT );
StartPage( hDC );
CRect Rect( 0, 0, 100, 100 );
PrinterDC.Rectangle( &Rect );
PrinterDC.MoveTo( 0, 0 );
PrinterDC.LineTo( 100, 100 );
CString csText( _T( "Orientation" ));
TextOut( hDC, 50, 50, csText.operator LPCTSTR(), csText.GetLength());
EndPage( hDC );
EndDoc( hDC );
PrinterDC.Detach();
|
|
|
|
|
|
I have Help button in property sheet,when i click on it the associated help gets invoke.Similarly when i click F1 it does the same.
When i do it both one after the other,the focus is no more when i try to press F1.
Can anyone help me out from this situation
|
|
|
|
|
Hi,
InitThunk((TMFP) &CExtBox::HookProc, this);
m_hHook = SetWindowsHookEx(WH_CBT, (HOOKPROC) GetThunk(), NULL,GetCurrentThreadId());
ASSERT(m_hHook);
nRes = MessageBoxIndirect(&mp);
if(m_hHook)
UnhookWindowsHookEx(m_hHook);
This is the code part i am using and it was crashing when it calls MessageBoxIndirect().
This code was running from a long time now in fresh version of release this is giving problem. If i use MessageBox( ) then it is working but the function that i am calling is used in somany places so i cannot avoid it.
It is giving the following Application error
Event Type: Error
Event Source: Application Error
Event Category: (100)
Event ID: 1000
Date: 3/13/2008
Time: 7:14:39 AM
User: N/A
Computer: SILT06-FERG
Description:
Faulting application Acp.exe, version 5.2.1002.21, faulting module unknown, version 0.0.0.0, fault address 0x01f5f968.
Data:
0000: 41 70 70 6c 69 63 61 74 Applicat
0008: 69 6f 6e 20 46 61 69 6c ion Fail
0010: 75 72 65 20 20 41 63 70 ure Acp
0018: 2e 65 78 65 20 35 2e 32 .exe 5.2
0020: 2e 31 30 30 32 2e 32 31 .1002.21
0028: 20 69 6e 20 75 6e 6b 6e in unkn
0030: 6f 77 6e 20 30 2e 30 2e own 0.0.
0038: 30 2e 30 20 61 74 20 6f 0.0 at o
0040: 66 66 73 65 74 20 30 31 ffset 01
0048: 66 35 66 39 36 38 f5f968
I do not know how to check the callstack so please suggest me, now what can i do? This is a customer issue i need a solution badly please help me.
Yes everything is fine it was working from a long time and recently it is causing this problem and only with some systems.
So i dont think it is the problem with coding, it might be the problem with PC because it varies from PC to PC.
Thanks & Regards,
Ramarao.
|
|
|
|
|
Have you initialized properly the MSGBOXPARAMS struct?
For instance, missing mp.cbSize = sizeof(mp); is a common pitfall.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Yes everything is fine it was working from a long time and recently it is causing this problem and only with some systems.
So i dont think it is the problem with coding, it might be the problem with PC because it varies from PC to PC.
Thanks & Regards,
Ramarao.
|
|
|
|
|
RamaraoPV wrote: So i dont think it is the problem with coding, it might be the problem with PC
You are kidding, right ?
|
|
|
|
|
RamaraoPV wrote: So i dont think it is the problem with coding, it might be the problem with PC because it varies from PC to PC.
the problem is between the chair and the keyboard.
|
|
|
|
|
RamaraoPV wrote: nRes = MessageBoxIndirect(&mp);
How is mp initialized?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello
I need to write an application to recognize which USB HID Mouse is using at the moment. At least two mice are connected to the PC at one time. It should work in background and show in the background window or write to file movement positions of currently moving mouse in the system.
My way of thinking is to:
1) create main application (exe or DLL) with window which will:
- detects all Raw Input HID mouses but not regist them yet
- recieve messages from its window and from hooking DLL
- detects in seperate thread which window is currently on top (Foreground)
- if new window is on top call first RegisterRawInputDevices with Handle to new window then call "CreateHook" from DLL to reset Hooks to new thread
Below the code for the thread detecting top most window:
<br />
while (Running) {<br />
Sleep(1000); <br />
hWnd_curr = GetForegroundWindow();<br />
if(hWnd_curr != hWnd_old) {<br />
hWnd_old = hWnd_curr;<br />
GetWindowText(hWnd_curr,window_name,sizeof(window_name));<br />
<br />
Rid[0].hwndTarget = hWnd_curr;
<br />
if(!RegisterRawInputDevices(Rid, 1, sizeof (Rid[0]))) {<br />
_snprintf(logevent,sizeof(logevent),"Register Raw Input Devices FAILED");<br />
Write2File(logevent);<br />
continue;<br />
}<br />
<br />
if(pCreateHook != NULL && (dwThreadId = GetWindowThreadProcessId(hWnd_curr,&dwProcessId))!=0) <br />
msgHook = pCreateHook(WH_CALLWNDPROC,hwndMain,dwThreadId);<br />
<br />
}<br />
}
Unfortunately I cannot register raw input devices to the other window than the one I created in main program.
2) create a DLL that that be using Global Hooks for all messages from the window that is on top. DLL will contains one external function:
- CreateHook - clears old hook if not NULL and sets new hook for given threadID
in the DLL there is a callback function for collecting hooked messages which are directly sent to main application
static LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam) {<br />
<br />
if(nCode < 0) {<br />
CallNextHookEx(hook, nCode, wParam, lParam);<br />
return 0;<br />
}<br />
<br />
INFO f; <br />
f.code=nCode; <br />
f.hhook=hook; <br />
f.lParam=lParam;<br />
<br />
cwpMessageParams = (PMSG)lParam;<br />
<br />
if(cwpMessageParams->message == WM_INPUT) <br />
SendMessage(mForm, messageCode, (WPARAM)(cwpMessageParams->message), (LPARAM)&f);<br />
<br />
return CallNextHookEx(hook, nCode, wParam, lParam);<br />
}
The second problem with is that this callback never gets WM_INPUT even if raw inputs are register to the window created in main application.
I'm using Win32 in VC++.
Any suggestions? Or maybe my way of thinking is wrong??
How is it possible to get at least the name of currently working mouse??
Thanks for any help
Maciek
modified on Wednesday, April 2, 2008 6:10 AM
|
|
|
|
|
I do not believe you can reliably detect which mouse has produced the input from usermode... ring-3. RegisterRawInputDevices does not work like you are suggesting. You will need to write a filter driver. You need to create a mouse filter driver which is connected to \\Device\\PointerClass0 and \\Device\\PointerClass1 all other pointerclass input devices on the device chain.
You would need to implement some shared memory protected by KeAcquireSpinLock/KeReleaseSemaphore and each time the mouse moves, the filter driver would set this information in the shared memory each time it recieves input. You would need to also write a windows service which polls the driver IOCTL interface at regular intervals and retrieves the mouse currently/last in use. When multiple pointing devices are moving at the same time the resolution will be equal to your polling rate.
Its not a simple task.
Good luck,
-David Delaune
|
|
|
|
|
Hi,
How can I pass switches in a exe?
|
|
|
|
|
What do you mean ? You mean command line arguments ? If yes, then simply open the command prompt and add them after the executable name. If that's not what you are looking for, then you should explain more in details.
|
|
|
|
|
Also, from within the Visual Studio IDE, you can go to the project properties in the "Debugging" section
and put your commandline arguments in the "Command Arguments" setting.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Can you more explain,plese?
|
|
|
|
|
I want to enumerate files on specific drive to get total count of files on that drive. Currently i am using only one thread for this but i want to use multiple thread for this so that job get divided into these thread.
Can anyone help me for my problem?
|
|
|
|
|
Member 3420509 wrote: Currently i am using only one thread for this but i want to use multiple thread for this so that job get divided into these thread.
Is there a particular reason to do that ? If your program is not running on a multicore, then this will probably slow down the procedure, as you will incur the cost of thread switching and you'll need to protect some part of it for multi-threaded access (which will also slow down).
|
|
|
|
|
Some people think multi-threading would make it run faster ...
Maxwell Chen
|
|
|
|
|
Yeah, but some people might be wrong
|
|
|
|
|
make this multithread is leading into headache, because you'll have to synchronize your threads, so that each thread don't count the same file twice...
synchronized them is certainly going to make your multithread solution slower than a single threaded one...
|
|
|
|
|
yes that is the question that how can i assign the equal task to each thread.
|
|
|
|