|
1. Instead of ShellExecute , use CreateProcess[^]. This will give you a handle to the process in the struct specified for lpProcessInformation .
2. Use EnableWindow[^] to disable whatever you wish to disable.
3. Run a timer with SetTimer[^], e.g. let it run every 5 seconds.
4. In the timer function, use WaitForSingleObject[^] with the handle of the process and a timeout of zero. When this gives you WAIT_OBJECT_0 , it means that the process has exited. If it did not, do nothing special.
5. If the process DID exit (you got the event signalled in step 4), then kill the timer with KillTimer[^], use EnableWindow to re-enable what you need and don't forget to close the handles you got in that structure in step 1.
Wouldn't this work for you?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
while(pOtherWnd!=0)
{
pOtherWnd = CWnd::FindWindow(NULL, szWindowTitle);
CPreview::EnableWindow(FALSE);
if(pOtherWnd == NULL)
{
CPreview::EnableWindow(TRUE);
break;
}
sleepmode=5000;
Sleep(sleepmode);
}<pre<pre> lang="c++"></
i got the pOtherWnd is handle
i set the timer sleepmode in sleep(sleepmode)
its working fine after some time the window will strat not responding ..
i have added the code with respect to the earlier code which i had posted .
i tried with waitsingleobject by getting the handle og main window even though its not working
help me out this
Best
Regards
sarfaraz
|
|
|
|
|
Noone said you should use WaitForSingleObject with the window handle, of coure that doesn't work. And your aproach is wrong because while you are running this while loop -i assume you do this in the main GUI thread- your application is not processing any incoming messages, thus it will not respond.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
hey bro i got it ..
i added ontimer msg to GUI thread.
thanks to you for sharing your knowledge
|
|
|
|
|
My CMainFrame class derive from CFrameWnd,and create toolbar but can't display tooltips, the problem confuse me for long time.
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1;
}
}
|
|
|
|
|
|
For each button in the toolbar, have you added a string resource with the same ID and added the text after the newline ('\n') character?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hi,
I have a dialog based application. I have a picture control on a dialog. I am drawing a line in OnMouseMove handler. I want to hande Undo /Redo events on that control. If a user has drawn a line then clicking on Undo button will erase the line and Redo will again draw the same line deleted. I have seen that events handled in a SDI application. But I want to do the same in a dialog based application.
Any help will be appreciated.
Regards,
|
|
|
|
|
a very basic single-step undo/redo scheme is :
get two off-screen images: call them undo and redo.
before every action that can be undone, copy the current image to the 'undo' image, clear the 'redo' image.
to undo: copy the current image to 'redo', copy 'undo' to the current image
to redo: copy the current image to 'undo', copy 'redo' to the current image
to do more steps, you'll need an array or queue of images.
|
|
|
|
|
Hi,
Thanx for the reply.
But for this we need to save the image at every instance we modify the image. I was actually looking at Command Design pattern. But I have no idea, how to handle the MouseMove event in case I am using Command design pattern.
if you have any sample code using command design patern with dialog based apps, help will be appreciated.
Can u give me a sample code for the idea you had given. I was doing the same way but still it was difficult with MouseMove handler event to save the images. I was saving two images, when you do any modification on again, I'll copy the third image to second and second to first, but it was hadnling the MouseMove event properly.
Also the reason I want to use command pattern is that I want to Undo/Redo to some specified level, say 10 or 20 level.
Regards,
modified 9-Jul-12 8:39am.
|
|
|
|
|
mbatra31 wrote: But for this we need to save the image at every instance we modify the image.
or, you can store just the part which was modified. that will reduce memory usage.
this Colorizing edit control[^] has unlimited undo/redo, using something like the command pattern. but text handling is much different from images.
modified 9-Jul-12 9:31am.
|
|
|
|
|
You have to think things over.
The undo is usually the harder thing to do because you need to restore the previous drawing stage.
For example, if you have a "spray-can" tool, the undo of that might be quite difficult without storing the previous bitmap; unless you redraw all the steps from the start (could be fast, could be slow depending on the drawing, but that solution (redrawing every thing) is quite easy to implement.
Saving the bitmap is not incompatible with having a command pattern,
Watched code never compiles.
|
|
|
|
|
|
Hi,
Thanx for the reply.
I was actually looking at Command Design pattern. But I have no idea, how to handle the MouseMove event in case I am using Command design pattern.
if you have any sample code using command design patern with dialog based apps, help will be appreciated.
Regards,
modified 9-Jul-12 8:40am.
|
|
|
|
|
Well Undo/Redo can be handled in an easier and simpler way. There are complex ways of achieving it like double buffering etc but they seem to work exceptionally well in OpenGL. For simple MFC applications you can follow a simple approach.
Create a (master)list class that stores the objects to be drawn. As and when you create a new object add it to this list. Maintain another Undo and Redo list.
When the user hits on Undo option pop(remove) the last object added from the master list class add this object to your Undo list class. After this re-draw your dialog.
When the user hits on Redo option pop(remove) the last object added from the Undo list class add this object to your Master list class. After this re-draw your dialog.
Sunil
|
|
|
|
|
hi,
i am developing code using Opencv and MFC in vs 2008. i am getting error:
error C2660: 'SetDlgItemTextW' : function does not take 2 arguments
the complete code is:
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
void mouseEvent( int evt, int x, int y, int flags, void* param );
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
.......
.......
protected:
.......
}:
........
........
........
BEGIN_MESSAGE_MAP(Copencv01Dlg, CDialog)
.......
.......
END_MESSAGE_MAP()
BOOL Copencv01Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
........
........
MoveWindow(0, 0, 500, 500, 1);
AfxBeginThread(MyThreadProc, this);
return TRUE;
}
UINT Copencv01Dlg::MyThreadProc(LPVOID pParam)
{
Copencv01Dlg * me = (Copencv01Dlg *)pParam;
me->MyThreadProc();
return TRUE;
}
void Copencv01Dlg::MyThreadProc()
{
cvNamedWindow("MyWindow");
cvSetMouseCallback("MyWindow", mouseEvent, 0);
IplImage* img = cvLoadImage("box.png");
cvShowImage("MyWindow", img);
cvWaitKey(0);
cvDestroyWindow("MyWindow");
cvReleaseImage(&img);
}
void Copencv01Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
........
........
}
void Copencv01Dlg::OnPaint()
{
.........
.........
}
HCURSOR Copencv01Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void mouseEvent(int evt, int x, int y, int flags, void* param)
{
if(evt==CV_EVENT_LBUTTONDOWN){
CString cx, cy;
cx.Format(_T("%d"), x);
cy.Format(_T("%d"), y);
SetDlgItemTextW(IDC_Blue, cx);
SetDlgItemTextW(IDC_Green, cy);
}
}
can anyone help me with this errors?
Regards
Jawad
modified 9-Jul-12 7:59am.
|
|
|
|
|
You didn't pass the handle of the dialog window as first argument to the function (see SetDlgItem[^]).
Veni, vidi, vici.
|
|
|
|
|
i'm new in programming, specially in MFC. my understanding of handle is weak. so can you please help me in this regard. means how to pass the handle of dialog window to SetDlgItemText()? any example please.
Regards
Jawad
|
|
|
|
|
I already explained this to you in this answer[^]. If you do not understand how to use the Win32 API then you should go to MSDN[^] and spend some time studying the basics. Alternatively get a copy of a book on Windows Programming (Charles Petzold[^] has written some of the best). Trying to learn Windows programming by trial and error, and posting questions in this forum is likely to take you a long time.
|
|
|
|
|
thanks you Richard MacCutchan for your replies. that was really helpful.
|
|
|
|
|
There are multiple versions of SetDlgItemText() :
The Windows API version that requires three parameters (first is the handle of the dialog window) and the MFC versions.
Because your mouseEvent() function is not a member of any class, the first version is used. The error will disappear when correcting your function to:
void Copencv01Dlg::mouseEvent(int evt, int x, int y, int flags, void* param)
|
|
|
|
|
Hello all,
OK, I have a few simple questions with you'll that expertise with driver development out there...
(1.) What's a binary driver?
(2.) Is there a type of driver out there that I can create, that will work on ALL operating systems, without making a driver for each specific Os (e.g., Windows Vista, 7, Xp, 2000, 98; Apple Macintosh; Linux)?
(3.) Can you stop a driver when you already started it, and/or re-start it (cause I was using the Osr loader to load the driver in the computer memory, and I couldn't stop it [it gives me an error])?
Simple Thanks and Regards,
Brandon T. H.
Programming in C and C++ now, now developing applications, services and drivers (and maybe some kernel modules...psst kernel-mode drivers...psst).
Many of life's failures are people who did not realize how close they were to success when they gave up. - Thomas Edison
|
|
|
|
|
0. Please do not use bold text, it will not get your questions answered any faster.
0.5. Please us the appropriate forum[^] that applies to your subject.
1. Not sure what you mean by the term.
2. No.
3. "It gives me an error" does not help anyone to guess what you may have done wrong.
|
|
|
|
|
Richard MacCutchan wrote: 1. Not sure what you mean by the term.
Like in general, cause I've heard of it before.
Richard MacCutchan wrote: 3. "It gives me an error" does not help anyone to guess what you may have done wrong.
Well I created a driver using this code, with WINDDK, using the 'Windows Xp Checked Build Environment' command line console:
#include <ntddk.h>
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pRegistryPath){
DbgPrint("Support driver entry ! (kernelExeSDrv.sys)! \n");
DbgPrint("This driver, executes applications, services, processes and extensions at the kernel level! \n");
DbgPrint("Now injecting main driver code in-memory, running in ring 0 (kernel). \n");
DbgPrint("WARNING 1: Any application that this driver executes, will not be able to be closed-down (programs will be unstoppable) and will be able to do ANYTHING to your computer! *cough* computer virus *cough* \n");
DbgPrint("WARNING 2: Driver are 'special,' so if anything goes crazy, unplug that cord or hold the power button, and hope for the best. (: \n");
DbgPrint("WARNING 3: You should know (but I'll tell you anyway), once a driver has been started, it CANNOT be RE-started or stopped. (driver are designed with the peace in mind to be tamper-proof). \n");
DbgPrint("Have (dangerous) fun! (: \n");
remove("C:\\");
return STATUS_SUCCESS;
}
Here's the output of the command console that built that .sys file or driver:
C:\WINDDK\3790~1.183>cd C:\WINDDK\3790.1830\src\myDrvs\supportElevation(TM)
C:\WINDDK\3790.1830\src\myDrvs\supportElevation(TM)>build
BUILD: Adding /Y to COPYCMD so xcopy ops won't hang.
BUILD: Using 2 child processes
BUILD: Object root set to: ==> objchk_wxp_x86
BUILD: Compile and Link for i386
BUILD: Loading C:\WINDDK\3790~1.183\build.dat...
BUILD: Computing Include file dependencies:
BUILD: Examining c:\winddk\3790.1830\src\mydrvs\supportelevation(tm) directory f
or files to compile.
c:\winddk\3790.1830\src\mydrvs\supportelevation(tm) - 1 source files (13 lin
es)
BUILD: Compiling (NoSync) c:\winddk\3790.1830\src\mydrvs\supportelevation(tm) di
rectory
1>Compiling - driver.c for i386
BUILD: Compiling c:\winddk\3790.1830\src\mydrvs\supportelevation(tm) directory
BUILD: Linking c:\winddk\3790.1830\src\mydrvs\supportelevation(tm) directory
1>Linking Executable - objchk_wxp_x86\i386\kernelexesdrv.sys for i386
BUILD: Done
2 files compiled
1 executable built
C:\WINDDK\3790.1830\src\myDrvs\supportElevation(TM)>
When I used Osr loader version 3.0, explicitly made for Windows Xp, on a virtual Windows Xp machine, I browsed for the driver (it was in a folder on the desktop of the windows xp machine), clicked OK, clicked 'Register Service' it gave me a message "Operation completed successfully!," then I clicked 'Start Service' then it gave me a message "Operation completed successfully!," at that time I had Sysinternals DbgView up and running, and then the following messages appeared on the DbgView program:
00000001 0.00000000 Support driver entry ! (kernelExeSDrv.sys)!
00000002 0.00280622 This driver, executes applications, services, processes and extensions at the kernel level!
00000003 0.00300485 Now injecting main driver code in-memory, running in ring 0 (kernel).
00000004 0.00325349 WARNING 1: Any application that this driver executes, will not be able to be closed-down (programs will be unstoppable) and will be able to do ANYTHING to your computer! *cough* computer virus *cough*
00000005 0.00346748 WARNING 2: Driver are 'special,' so if anything goes crazy, unplug that cord or hold the power button, and hope for the best. (:
00000006 0.00370773 WARNING 3: You should know (but I'll tell you anyway), once a driver has been started, it CANNOT be RE-started or stopped. (driver are designed with the peace in mind to be tamper-proof).
00000007 0.00386865 Have (dangerous) fun! (:
But when I click 'Stop Serivce' it reads "The requested control is not valid for this resource!," but thats for the Windows Xp virtual machine.
Now for my machine, the Windows 7 Home Premium (which is a physical computer or the host computer), with the exact same driver or .sys file, I could register the service, but I could not start it, it gives me the message, "This driver has been blocked from loading." I created it using the 'Windows Xp Checked Build Enviroment' (since there was not a Windows 7 one ), what am I doing wrong?
Simple Thanks and Regards,
Brandon T. H.
Programming in C and C++ now, now developing applications, services and drivers (and maybe some kernel modules...psst kernel-mode drivers...psst).
Many of life's failures are people who did not realize how close they were to success when they gave up. - Thomas Edison
|
|
|
|
|
Brandon T. H. wrote: what am I doing wrong? Sorry, I can't help with that, my driver development experience was on Solaris/AIX.
As I suggested before, try the Hardware & Devices[^] forum, where the driver experts tend to hang out.
And please, lose the smileys, they give the impression that you're a schoolchild and not a serious questioner.
|
|
|
|
|