|
Even if give the third parameter lpBounds, (CreateEnhanced) in HIMETRIC, it is not working.
Basically, I have a activex control with some drawings on the client area and a combobox in the middle. I need to get all these in the metafile.
When I call PlayMetafile to check the metafile contents, the combobox is always drawn at top instead in the middle.
When control recieves a WM_PAINT message, how will the control know where it should draw itself?
How do you force a control to draw itself into a given device context and also specify in which position it should be drawn?
|
|
|
|
|
Cna you please send me your code ?
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
Following is the code.....
//Activex control code
//method: CopyToMF
LONG CMyActiveXCtrl::CopyToMF(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CClientDC DC(this);
DC.CreateDC(_T("DISPLAY"),NULL,NULL,NULL);
CMetaFileDC mDC;
CRect rect;
GetClientRect(&rect);
CSize size = rect.Size();
DC.DPtoHIMETRIC(&size);
CRect rcBounds;
rcBounds.left = 0;
rcBounds.top = 0;
rcBounds.right= size.cx;
rcBounds.bottom = size.cy;
mDC.CreateEnhanced(DC,0,&rcBounds,_T("CTSGraphics\0Picture 1\0\0"));
mDC.SetAttribDC(DC.GetSafeHdc());
mDC.SetMapMode(MM_ANISOTROPIC);
//Some drawing stuff
..................................
CBrush br;
br.CreateSolidBrush(RGB(255,255,255));
mDC.FillRect(m_rect,&br);
mDC.Ellipse(m_rect);
.................................
//draw child control
//ChkCB - is the combobox (child control)
HWND hWndChildCB = ChkCB.GetSafeHwnd();
// I tried both WM_PAINT as well as WM_PRINT messages
::SendMessage(hWndChildCB, WM_PAINT, (WPARAM)mDC.m_hDC, 0L);
//::SendMessage(hWndChildCB, WM_PRINT, (WPARAM)mDC.m_hDC, PRF_CLIENT);
HENHMETAFILE hMF = mDC.CloseEnhanced();
DC.DeleteDC( );
return (long)hMF;
}
//Client code (Dialog based application)
void CDTestDlg::OnBnClickedButton2()
{
//Call activex control method
HENHMETAFILE m_EnhMF = (HENHMETAFILE) m_obj.CopyToMF();
CClientDC client(this);
CRect rcBounds,rcRect;
m_obj.GetClientRect(&rcBounds);
rcRect.top = rcBounds.top+300;
rcRect.left = rcBounds.left+15;
rcRect.right = rcBounds.right;
rcRect.bottom = rcBounds.bottom+300;
client.PlayMetaFile(m_EnhMF,rcRect);
//everything gets drawn, but the combobox position is wrong. It is drawn at the top instead
//at the middle
}
|
|
|
|
|
Hi all,
i want to know how can i get SystemTime?
i m using CTime class for get time, but it show the time of computer clock which is shown at below right side in start up.
<br />
CTime time = CTime::GetCurrentTime();<br />
int nSecond = time.GetSecond();<br />
<br />
if (tTime != nSecond)<br />
{<br />
CTime time = CTime::GetCurrentTime();<br />
int nSecond = time.GetSecond();<br />
int nMinute = time.GetMinute();<br />
int nHour = time.GetHour();<br />
int nday = time.GetDay();<br />
int nmnt = time.GetMonth();<br />
int nyear = time.GetYear();<br />
<br />
if (nHour > 12)<br />
nHour -= 12;<br />
CString szStr;<br />
szStr.Format("%.2d,%.2d,%.2d %.2d:%.2d:%.2d ", nmnt , nday , nyear , nHour , nMinute , nSecond);<br />
CEdit m_clock_edit;
m_clock_edit.SetWindowTextA(szStr);<br />
<br />
}<br />
tTime = nSecond;<br />
if i change the time and date here then in my applicatin i m also gat the changed time but i want to get the SystemTime of Machine.
i want if i change the date and time in computer clock ,then it is not effect on my application.
thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
What about GetSystemTime
This function retrieves the current system date and time. The system time is expressed in UTC.
void GetSystemTime(
LPSYSTEMTIME lpSystemTime
);
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
void GetSystemTime( LPSYSTEMTIME lpSystemTime );
how can show the value of this in editbox.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
i m using this.
<br />
GetSystemTime(&m_st);<br />
<br />
int nyear = m_st.wYear; <br />
int dwMonth = m_st.wMonth; <br />
int dwDay = m_st.wDay;<br />
int dwHour = m_st.wHour;<br />
int dwMinute = m_st.wMinute;<br />
int dwSeconds = m_st.wSecond;<br />
int dwMilliSeconds = m_st.wMilliseconds;<br />
<br />
CString szStr;<br />
<br />
szStr.Format("%.2d,%.2d,%.2d %.2d:%.2d:%.2d:%.2d ",nyear,dwMonth,dwDay,dwHour,dwMinute,dwSeconds,dwMilliSeconds);
CEdit m_clock_edit;
m_clock_edit.SetWindowTextA(szStr);<br />
<br />
but it gives a wrong value for Hour.
thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
modified on Wednesday, May 14, 2008 2:56 AM
|
|
|
|
|
SYSTEMTIME time;
GetSystemTime(&time);
char buff[100];
GetTimeFormat
(
LOCALE_SYSTEM_DEFAULT,
NULL,
&time,
"hh':'mm':'ss tt",
buff,
100
);
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
Thanks now it is Resolved.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
Most Welcome
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
I am using visual studio 2005 and i am trying to write a windows service which will basically check whether a particular exe is running or not.
I have down loaded a sample code and created a service called "Service1" and i am able to successfully install and uninstall the service in to my windows XP machine with service pack 2.
Problem:
I cant start the service from the win service list and i am getting an error message as below.
Could not start service on the local system.
ERROR 1053:The service did not respond to the start or control request in a timely fashion.
Below is my service code
#include "stdafx.h"
#include "Windows.h"
#include "Winsvc.h"
#include "time.h"
#include "tlhelp32.h"
SERVICE_STATUS m_ServiceStatus;
SERVICE_STATUS_HANDLE m_ServiceStatusHandle;
BOOL bRunning=true;
void WINAPI ServiceMain(DWORD argc, LPTSTR *argv);
void WINAPI ServiceCtrlHandler(DWORD Opcode);
BOOL InstallService();
BOOL DeleteService();
bool isExeRunning(WCHAR *zExeName, bool *pbRunning);
int main(int argc, char* argv[])
{
if(argc>1)
{
if(strcmp(argv[1],"-i")==0)
{
if(InstallService())
printf("\n\nService Installed Sucessfully\n");
else
printf("\n\nError Installing Service\n");
}
if(strcmp(argv[1],"-d")==0)
{
if(DeleteService())
printf("\n\nService UnInstalled Sucessfully\n");
else
printf("\n\nError UnInstalling Service\n");
}
else
{
printf("\n\nUnknown Switch Usage\n\nFor Install use Srv1 -i\n\nFor UnInstall use Srv1 -d\n");
}
}
else
{
SERVICE_TABLE_ENTRY DispatchTable[]={{L"PointService",ServiceMain},{NULL,NULL}};
StartServiceCtrlDispatcher(DispatchTable);
}
return 0;
}
void WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
{
m_ServiceStatus.dwServiceType = SERVICE_WIN32;
m_ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
m_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
m_ServiceStatus.dwWin32ExitCode = 0;
m_ServiceStatus.dwServiceSpecificExitCode = 0;
m_ServiceStatus.dwCheckPoint = 0;
m_ServiceStatus.dwWaitHint = 0;
m_ServiceStatusHandle = RegisterServiceCtrlHandler(L"PointService", ServiceCtrlHandler);
if (m_ServiceStatusHandle == (SERVICE_STATUS_HANDLE)0)
{
return;
}
m_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
m_ServiceStatus.dwCheckPoint = 0;
m_ServiceStatus.dwWaitHint = 0;
if (!SetServiceStatus (m_ServiceStatusHandle, &m_ServiceStatus))
{
}
bRunning=true;
while(bRunning)
{
Sleep(3000);
bool pbRunning = true;
isExeRunning(L"Point-HD.exe",&pbRunning);
if(pbRunning == true)
{
printf("Point-HD running......\n");
}
else
{
printf("Point-HD running......\n");
}
}
return;
}
void WINAPI ServiceCtrlHandler(DWORD Opcode)
{
switch(Opcode)
{
case SERVICE_CONTROL_PAUSE:
m_ServiceStatus.dwCurrentState = SERVICE_PAUSED;
break;
case SERVICE_CONTROL_CONTINUE:
m_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
break;
case SERVICE_CONTROL_STOP:
m_ServiceStatus.dwWin32ExitCode = 0;
m_ServiceStatus.dwCurrentState = SERVICE_STOPPED;
m_ServiceStatus.dwCheckPoint = 0;
m_ServiceStatus.dwWaitHint = 0;
SetServiceStatus (m_ServiceStatusHandle,&m_ServiceStatus);
bRunning=false;
break;
case SERVICE_CONTROL_INTERROGATE:
break;
}
return;
}
BOOL InstallService()
{
WCHAR strDir[1024];
SC_HANDLE schSCManager,schService;
GetCurrentDirectory(1024,strDir);
wcscat(strDir,L"\\Point-HDListener.exe");
schSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
if (schSCManager == NULL)
return false;
LPCTSTR lpszBinaryPathName=strDir;
schService = CreateServiceW(schSCManager,
L"PointService",
L"Point HD Listener Service",
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL,
lpszBinaryPathName,
NULL,
NULL,
NULL,
NULL,
NULL);
if (schService == NULL)
return false;
CloseServiceHandle(schService);
return true;
}
BOOL DeleteService()
{
SC_HANDLE schSCManager;
SC_HANDLE hService;
schSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
if (schSCManager == NULL)
return false;
hService=OpenService(schSCManager,L"PointService",SERVICE_ALL_ACCESS);
if (hService == NULL)
return false;
if(DeleteService(hService)==0)
return false;
if(CloseServiceHandle(hService)==0)
return false;
return true;
}
bool isExeRunning(WCHAR *zExeName, bool *pbRunning)
{
if (! pbRunning) return FALSE;
PROCESSENTRY32 pe32;
BOOL bSuccess = TRUE;
*pbRunning = FALSE;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (hSnapshot!=INVALID_HANDLE_VALUE)
{
pe32.dwSize = sizeof( PROCESSENTRY32 );
BOOL bRes = Process32First(hSnapshot, &pe32);
while (bRes==TRUE)
{
wprintf(L"%s\n",pe32.szExeFile);
if (0==wcscmp(zExeName, pe32.szExeFile))
{
*pbRunning = TRUE;
break;
}
bRes = Process32Next(hSnapshot, &pe32);
}
if (bRes!=TRUE && GetLastError()!=ERROR_NO_MORE_FILES)
{
bSuccess = FALSE;
}
CloseHandle(hSnapshot);
}
else
{
bSuccess = FALSE;
}
return bSuccess;
}
modified on Wednesday, May 14, 2008 8:53 AM
|
|
|
|
|
ERROR_SERVICE_REQUEST_TIMEOUT: The process for the service was started, but it did not call StartServiceCtrlDispatcher, or the thread that called StartServiceCtrlDispatcher may be blocked in a control handler function.
Soumyadipta wrote: ServiceMain(NULL,NULL);
I suspect this one, servicemain is called by SCM.
you are calling Service main in the service program main, this shows you have little knowledge about it or may be me.
[How to debug Windows services^]
|
|
|
|
|
That was a silly mistake. I have corrected the code but still i am getting the same problem.
Also i have downloaded the FirstService.zip from code project which is also giving me the same error message.
|
|
|
|
|
It would help you to get an answer if you read the "how to get help" message at the front of the forum, and use the pre tag to enclose your code, not the code tag. pre preserves the spacing and indentation to make it easier for people to read your code.
If we have to to struggle through a wall of text, we'll give up, and you won;t get assistance...
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
The problem is now solved.I have separated the installer code block from the existing code and have created a separate exe to install the service.I don't know the reason why the installer code block was creating the probel of ERROR 1053.
Below is the installer code:
<br />
<br />
<br />
<br />
<br />
<br />
#include <stdafx.h><br />
#include <windows.h><br />
#include <winsvc.h><br />
<pre><br />
void ShowErr();<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
SC_HANDLE NishService,scm;<br />
scm=OpenSCManager(0,0,SC_MANAGER_CREATE_SERVICE);<br />
if(!scm)<br />
{<br />
ShowErr();<br />
return 1;<br />
}<br />
NishService=CreateService(scm,"PointHDListener",<br />
"PointHDListener Service",<br />
SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS,SERVICE_DEMAND_START,<br />
SERVICE_ERROR_NORMAL,<br />
"D:\\Service1.exe",<br />
0,0,0,0,0);<br />
if(!NishService)<br />
{<br />
CloseServiceHandle(scm);<br />
ShowErr();<br />
return 1;<br />
}<br />
CloseServiceHandle(NishService);<br />
CloseServiceHandle(scm);<br />
return 0;<br />
}<br />
<br />
void ShowErr()<br />
{<br />
}</pre><br />
</winsvc.h></windows.h></stdafx.h>
|
|
|
|
|
thanks worked installer should be seperated from service
manoj kulkarni
Net protector antivirus
|
|
|
|
|
How can i display a window message from my service?
I am able to create and install a windows service. I am beeping a sound from my service successfully.
Now i want to display a message when some event occurs.Basically in my code i am looking for a exe and checking whether it is running or not.
I want to display a message "Exe not running or started/ Crashed due to some error" from my service when i found the exe is not running means when status=false.
|
|
|
|
|
I've an MFC application which uses SQL connection using Namedpipes. I'm getting crash in the application log as follows.
Fault address: 7331293E 01:0000193E C:\bin\DBNMPNTW.DLL
Call stack:
Address Frame
7331293E 013D68DC ConnectionTransact+1AE
I'm not getting any clue of why the crash is happening at this point. After opening for a long time, it just crashes at this point !!!!!
Appreciate if some body can shed a light on the reason, what all could be the reason.
Arun K Ramachandran
|
|
|
|
|
Do mean the Connect takes a long time before it crashes? if yes, the problem may be with authentication or with the sever not able to connect to your applications and the exception is not handled.
|
|
|
|
|
Hi,
I have an MDI application. In view, I have created a property sheet. In one of the pages of this property sheet, I have to create ~50 different kinds of modeless dialogs, owned by property page. All these dialogs are needed in memory as long as the document is open in the session. I have created them at application start up.
However, when I create two to three documents, my application gets very slow (~50 * 3 documents = ~150 dialogs in memory). The API CDialog::Create is taking time.
Could you please suggest a solution for this ?
Any help would be highly appreciated.
Regards,
Paresh.
|
|
|
|
|
Can each document share the dialogs, so you only have to create 50?
Why not create each dialog dynamically when it's needed, or are all 50 visible all the time. Sounds like a pretty intense app if that's the case. Could combine some of the dialogs?
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Hi Steve,
Thanks for your reply.
Steve Echols wrote: Can each document share the dialogs, so you only have to create 50?
A particlaur dialog has its own data. A data in a dialog in one document is different from another dialog from another document. Could you please let me know, How could I share the dialogs across two documents ?
Steve Echols wrote: Why not create each dialog dynamically when it's needed, or are all 50 visible all the time.
Then also application gets slow.
Regards,
Paresh.
|
|
|
|
|
I had the same problem when creating the parameter-dialogs for each element, when I had 20+ elements and tryed to open them the app was freezing. I got it improved by removing the CDialogs and using CFormViews, duplicating the views as I needed them. It gives more performance, more speed and more functionality (i.e. UpdateAllViews ()).
Paresh Chitte wrote: How could I share the dialogs across two documents ?
At the same time you are not going to be able of that. If you open the window for a document you should close it and reopen for another document. Or delete the contents of all elements and then fill them with the datas of the second element.
I made it adding a CMyDoc* pointer to the "parent" document as member variable in the CFormView, when I double-clicked on an element to be parametrized, then I got the document pointer in the CMyView and sent it to the CFormView of that element at the end of the opening process. Then used the OnInitialUpdate () to fill all the elements with the datas of the document.
You can check
this[^] and this[^] posts to have a look of what I made.
Hope it helps
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Hi Nelek,
Thanks for your reply. I will look into it.
Regards,
Paresh.
|
|
|
|
|
Hi All,
Please Help me reg Following problem
I wrote a simple DOS Program to access my ISA Card using far pointer
My ISA Card have resources like 2 I/O s and 1 Memory
My Card is configured to access the location from 0xD000
My program is working(accessing the device memory) in Pentium 1 and not working in Pentium 4
code for accessing ISA device memory:
unsigned int far* BaseAddr;<br />
BaseAddr = (unsigned int far *)MK_FP(0xD000,0x0000);
in P1 processor (Win98)
IO 1 - OK
IO 2 - OK
Memory - OK
in P4 processor (Win98)
IO 1 - OK
IO 2 - OK
Memory - Not mapping to device
Thanks in Advance
|
|
|
|
|