|
Hi,
We are using opendesktop api in a binary and we ar getting return code
170 (The requested resource is in use. ERROR_BUSY)after executing the
binary for some times . If i restart the box and execute the binary,
the error disappears.
I have not been able to find any documentation describing under what
conditions ERROR_BUSY is returned by OpenDesktop nor how to handle
this condition. For example, should OpenDesktop be retried after a
short sleep?
If anyone can provide any information on this condition, it would be
appreciated.
Regards,
Yogish
|
|
|
|
|
Hi guys,
I've been reading some forums about catching the escape key. I have this property page and when I press the escape key, instead of closing (which should have happened by default), does not close.
There were some suggestions like overriding OnClose and OnCancel or using PreTranslateMessage which has this code:
BOOL MFCDigPropPage::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN)
{
if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE)
MessageBox("Pressed the escape or enter key!");
}
return CDialog::PreTranslateMessage(pMsg);
}
This code worked when I created a simple dialog box with just the OK and Cancel button on it. But when i tried it on my property page, it does not work anymore. Any suggestions/ideas regarding this one??? I would really really really appreciate any help on this.
Thanks!
waxie
|
|
|
|
|
you need to handle the PreTranslateMessage of the property sheet. if property sheets have a parent then handle the pretranslate of that dialog.
nave
|
|
|
|
|
waxie wrote: Any suggestions/ideas regarding this one???
You need to handle this ,message in owner property sheet. e.g.
BOOL CMySheet::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN)
{
if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE)
MessageBox(L"Pressed the escape or enter key!");
}
return CPropertySheet::PreTranslateMessage(pMsg);
}
|
|
|
|
|
What are you trying to do? If you want the dialog to not close when the user presses Enter/ESC, don't use PreTranslateMessage() which is too low-level. Just change OnOK() /OnCancel() so they don't call EndDialog() . In a property page, handle the PSN_APPLY and PSN_QUERYCANCEL notifications.
|
|
|
|
|
I am trying to develop a Annotation tool, with which i should be able to draw, mark on the windows screen.
Can any help me, in pointing to some documentation/APIs where i can get started.
Thanks in advance,
Vissu
|
|
|
|
|
Vissu89 wrote:
Can any help me, in pointing to some documentation/APIs where i can get started.
check CDC class in MSDN!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
hi ,
how to distribute last column of list control to fit into client area?
thanks
rakesh
|
|
|
|
|
Try the below code.
CRect ClientRect;<br />
GetClientRect( &ClientRect );<br />
CRect LastItemRect;<br />
int nLastitem = GetHeaderCtrl()->GetItemCount() - 1;<br />
GetHeaderCtrl()->GetItemRect( nLastitem , &LastItemRect );<br />
int nNewLength = ClientRect.right - LastItemRect.left ;<br />
SetColumnWidth( nLastitem , nNewLength );
nave
|
|
|
|
|
thank you,
can you please reproduce this probelm by using
1> press window key + e
2> go to details view of folder
now see last column here in list.
can we get last column by using getheaderctrl() fn,
now i have to re distribute this space into all column at runtime .
thanks
rakesh
|
|
|
|
|
if you want to equally distribute the column width do as follows..
CRect ClientRect;
GetClientRect( &ClientRect );
CRect LastItemRect;
int nCount = GetHeaderCtrl()->GetItemCount();
int nWidth = ClientRect.Width()/nCount;
for( int nIdx = 0;nIdx < ncount; nIdx++)
{
SetColumnWidth( nIdx , nWidth );
}
nave
|
|
|
|
|
|
The list will do this for you. Call SetColumnWidth() on the last column and use the LVSCW_AUTOSIZE_USEHEADER flag.
|
|
|
|
|
Hi all,
I want to create a new class derived from CTime.
<br />
class XTime : public CTime <br />
{<br />
public:<br />
XTime();<br />
virtual ~XTime();<br />
<br />
};<br />
then I create a new object
XTime m_Date;
and then I want to initialize my object:
m_Date = NULL;
there is an error when compiling. When I create my object from a normal CTime, everything works.
As far as I learned C++, I can derive a new class and it inherits everything from the base class. But why can't I initialize it? It seems, that the = operator is not working.
Any help?
Juergen
|
|
|
|
|
This is because CTime have a contrcvtor of type CTime(time_t time);
So in the derived class also declare a constructor which accepts a time_t object and simply pass that object to base class.
class XTime : public CTime <br />
{<br />
public:<br />
XTime();<br />
virtual ~XTime();<br />
<br />
XTime( time_t t ):CTime(t)<br />
{<br />
}<br />
<br />
<br />
};
nave
|
|
|
|
|
Ahh, that helped a lot.
Now I have to find a way to inherit the = operator.
Thanks a lot
Juergen
|
|
|
|
|
e-DJ wrote: Now I have to find a way to inherit the = operator.
here it is
class XTime : public CTime
{
public:
XTime();
virtual ~XTime();
XTime( time_t t ):CTime(t)
{
}
const XTime& operator=(time_t t)
{
CTime::operator =( t );
return *this;
}
};
nave
|
|
|
|
|
Aargh,
I use CTime in my application all the time with almost all operators and constructors. When I have to reimplement them all, where is the use in object oriented design. Since I don't want to change these. All I wantetd to change was the behavior of the .Format-Class Member.
I canceled this and will redesign my application.
Juergen
|
|
|
|
|
e-DJ wrote: It seems, that the = operator is not working.
operator = is not inherited. You should redefine it in your derived class.
|
|
|
|
|
Since now, I have not been working with operators. So how should my operator= be defined?
Juergen
|
|
|
|
|
e-DJ wrote: I want to create a new class derived from CTime.
Be careful not to get caught in the "is a" vs. "has a" trap.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi all.
I write win service and I have simple code:
<br />
void main(void)<br />
{<br />
SERVICE_TABLE_ENTRY DispatcherTable[] =<br />
{<br />
{<br />
(LPWSTR)MYServiceName,<br />
(LPSERVICE_MAIN_FUNCTION)ServiceMain<br />
},<br />
{<br />
NULL,<br />
NULL<br />
}<br />
};<br />
<br />
printf("Sample of simple service\n(C) D. Bagaturia, 2007, Email: dato_baga@mail.ru\n");<br />
<br />
<br />
if(!StartServiceCtrlDispatcher(DispatcherTable))<br />
{<br />
CloseHandle(hMutex);<br />
return;<br />
}<br />
<br />
}<br />
Problem is that: Wen 'ServiceMain' function ends control go to main() function, and wen main() ends program ends, sow I get thet my service works less than second.
I try to write:
<br />
void main(void)<br />
{<br />
HANDEL hThread;<br />
SERVICE_TABLE_ENTRY DispatcherTable[] =<br />
{<br />
{<br />
(LPWSTR)MYServiceName,<br />
(LPSERVICE_MAIN_FUNCTION)ServiceMain<br />
},<br />
{<br />
NULL,<br />
NULL<br />
}<br />
};<br />
<br />
printf("Sample of simple service\n(C) D. Bagaturia, 2007, Email: dato_baga@mail.ru\n");<br />
<br />
<br />
if(!StartServiceCtrlDispatcher(DispatcherTable))<br />
{<br />
CloseHandle(hMutex);<br />
return;<br />
}<br />
<br />
do{<br />
GetExitCodeThread(hThread,
lpExitCode);<br />
if(*lpExitCode == STILL_ACTIVE)<br />
Sleep(150);<br />
else<br />
break;<br />
<br />
}while(1);<br />
<br />
}<br />
But in this time I get runtime error.
Wen I try to start or stop my service in ServiceManager, I get error message.
I know thet I blocked the service in case two, but I need this service more then 1 second.
Sow I have:
case 1: service runs less 1 second.
case 2: service runs but, it is blocked.
I know that I made som mistake, but whot?
|
|
|
|
|
Your original main was correct. The loop should be in the ServiceMain routine. Before entering the loop, your ServiceMain routine should call RegisterServiceCtrlHandlerEx to establish a callback routine for the SCM to call when the OS needs to change the state of your service. Typically, the ControlHandler sets some kind of signal, like an event. The loop in the ServiceMain then periodically checks for that signal.
Judy
|
|
|
|
|
Thanks all for reply, it help me.
I test my service on 'windows service 1998' and I think that my service is 'Ok', but it dont run on this operation system.
I have some manager exe file for this service and I think this exe have problem to 'operation system', sow wen I start service by this manager exe I get error code that service cant start.
Can this be true?
Tahnks again for your reply.
|
|
|
|
|
I'm asuming when you say "windows service 1998" that you are refering to Windows 98. I've never even tried to use one under anything earlier the NT4. Also, the MSDN documentation for the service control functions (both those from within the service like StartServiceCtrlDispatcher and those used by the calling program such as StartService) states they are NT4 or higher also. Looks like 98 is out.
Services are not the easiest things to debug. You just can't "start" them in the debugger. I typically put an ASSERT(false) in the very beginning of my _main function to force an exception and then begin debugging from there, putting break points into my ServiceMain function.
From your earlier post, it looks like you haven't done much with services before. Here is a basic outline of what one should look like. Note that I've omitted the error checking.
SERVICE_STATUS_HANDLE glb_sshStatusHandle;
SERVICE_STATUS glb_ssStatus;
VOID WINAPI MMServiceMain (DWORD dwArgc, LPTSTR *lpszArgv);
DWORD WINAPI MMServiceControl (DWORD dwCtrlCode, DWORD dwEventType,
LPVOID lpEventData, LPVOID lpContext);
int _tmain (int argc, TCHAR* argv[], TCHAR* envp[])
{
SERVICE_TABLE_ENTRY dispatchTable[] = {
{ "MMService", (LPSERVICE_MAIN_FUNCTION) MMServiceMain},
{ NULL, NULL} };
StartServiceCtrlDispatcher (dispatchTable);
glb_ssStatus.dwCheckPoint = 0;
return 0;
}
void WINAPI MMServiceMain (DWORD dwArgc, LPTSTR *lpszArgv)
{
glb_ssStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
glb_ssStatus.dwServiceSpecificExitCode = 0;
glb_sshStatusHandle = RegisterServiceCtrlHandlerEx (
"MMService", MMServiceControl, NULL);
glb_ssStatus.dwControlsAccepted = 0;
glb_ssStatus.dwCurrentState = SERVICE_START_PENDING;
glb_ssStatus.dwWin32ExitCode = NO_ERROR;
glb_ssStatus.dwWaitHint = 5000;
glb_ssStatus.dwCheckPoint = glb_ssStatus.dwCheckPoint++;
SetServiceStatus (glb_sshStatusHandle, &glb_ssStatus);
if (!Init ()) {
glb_ssStatus.dwCurrentState = SERVICE_STOPPED;
glb_ssStatus.dwWin32ExitCode = NO_ERROR;
glb_ssStatus.dwWaitHint = 0;
glb_ssStatus.dwCheckPoint = glb_ssStatus.dwCheckPoint++;
SetServiceStatus (glb_sshStatusHandle, &glb_ssStatus);
return;
}
glb_ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
glb_ssStatus.dwCurrentState = SERVICE_RUNNING;
glb_ssStatus.dwWin32ExitCode = NO_ERROR;
glb_ssStatus.dwWaitHint = 0;
glb_ssStatus.dwCheckPoint = glb_ssStatus.dwCheckPoint++;
SetServiceStatus (glb_sshStatusHandle, &glb_ssStatus);
Run ();
glb_ssStatus.dwCurrentState = SERVICE_STOPPED;
glb_ssStatus.dwWin32ExitCode = NO_ERROR;
glb_ssStatus.dwWaitHint = 0;
glb_ssStatus.dwCheckPoint = glb_ssStatus.dwCheckPoint++;
SetServiceStatus (glb_sshStatusHandle, &glb_ssStatus);
return;
}
DWORD WINAPI MMServiceControl (DWORD dwCtrlCode, DWORD dwEventType,
LPVOID lpEventData, LPVOID lpContext)
{
if (dwCtrlCode == SERVICE_CONTROL_STOP) {
glb_ssStatus.dwCurrentState = SERVICE_STOP_PENDING;
glb_ssStatus.dwWin32ExitCode = NO_ERROR;
glb_ssStatus.dwWaitHint = 0;
glb_ssStatus.dwCheckPoint = glb_ssStatus.dwCheckPoint++;
SetServiceStatus (glb_sshStatusHandle, &glb_ssStatus);
SetEvent (hStopEvent);
return NO_ERROR;
}
else
return ERROR_CALL_NOT_IMPLEMENTED;
}
bool Init ()
{
hStopEvent = CreateEvent (NULL, TRUE, FALSE, NULL);
return true;
}
void Run ()
{
while (WaitForSingleObject (hStopEvent, 1) != WAIT_OBJECT_0)
{
}
CloseHandle (hStopEvent);
return;
}
|
|
|
|