|
Is this article of any help? It uses that same control code.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
hope this is good
<br />
#include "stdafx.h"<br />
#include <windows.h><br />
#include <stdio.h><br />
#include <psapi.h><br />
#include <conio.h><br />
<br />
#pragma comment (lib,"psapi.lib")<br />
LPCTSTR GetDriverFromFilePath(LPTSTR FilePath, LPTSTR DriverName);<br />
LPCTSTR ErrorMessage(DWORD ErrorId);<br />
typedef struct _ActivateInfo<br />
{<br />
BOOLEAN bActivate;<br />
} ACTIVATE_INFO, *PACTIVATE_INFO;<br />
<br />
typedef struct _CallbackInfo<br />
{<br />
HANDLE hParentId;<br />
HANDLE hProcessId;<br />
BOOLEAN bCreate;<br />
}CALLBACK_INFO, *PCALLBACK_INFO;<br />
<br />
DWORD WINAPI Opreste(LPVOID pParam);<br />
<br />
HANDLE kmev;<br />
bool out;<br />
#define FILE_DEVICE_UNKNOWN 0x00000022<br />
#define IOCTL_UNKNOWN_BASE FILE_DEVICE_UNKNOWN<br />
#define IOCTL_PROCOBSRV_ACTIVATE_MONITORING \<br />
CTL_CODE(IOCTL_UNKNOWN_BASE, 0x0800, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)<br />
#define IOCTL_PROCOBSRV_GET_PROCINFO \<br />
CTL_CODE(IOCTL_UNKNOWN_BASE, 0x0801, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)<br />
<br />
<br />
int _cdecl main(void)<br />
{<br />
<br />
<br />
<br />
WIN32_FIND_DATA fd;<br />
<br />
SC_HANDLE hSCManager;<br />
SC_HANDLE hService;<br />
<br />
<br />
<br />
FindFirstFile("*.sys",&fd);<br />
char path[1024];<br />
GetModuleFileName(0,path,sizeof(path));<br />
MessageBox(0,ErrorMessage(GetLastError()),"GetModuleFileName",MB_ICONINFORMATION);<br />
char DriverName[1024];<br />
strcpy(DriverName,GetDriverFromFilePath(path,fd.cFileName));<br />
<br />
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);<br />
MessageBox(0,ErrorMessage(GetLastError()),"OpenSCManager",MB_ICONINFORMATION);<br />
printf("Load Driver\n");<br />
<br />
if(hSCManager!=NULL)<br />
{<br />
<br />
printf("Create Service\n");<br />
<br />
<br />
hService = CreateService(hSCManager,fd.cFileName,fd.cFileName,SERVICE_ALL_ACCESS,SERVICE_KERNEL_DRIVER,SERVICE_DEMAND_START,SERVICE_ERROR_NORMAL,DriverName,NULL,NULL,NULL,NULL,NULL);<br />
MessageBox(0,ErrorMessage(GetLastError()),"CreateService",MB_ICONINFORMATION);<br />
<br />
if (hService==NULL) hService=OpenService(hSCManager, fd.cFileName,SERVICE_ALL_ACCESS);<br />
MessageBox(0,ErrorMessage(GetLastError()),"OpenService",MB_ICONINFORMATION);<br />
printf("Start Service\n");<br />
<br />
if(StartService(hService, 0, NULL)==0)<br />
{<br />
MessageBox(0,ErrorMessage(GetLastError()),"Start Service",MB_ICONINFORMATION);<br />
DeleteService(hService);<br />
CloseServiceHandle(hService);<br />
<br />
}<br />
else<br />
{<br />
<br />
SERVICE_STATUS ss;<br />
while (1)<br />
{<br />
QueryServiceStatus(hService,&ss);<br />
if (ss.dwCurrentState!=SERVICE_RUNNING)<br />
{<br />
if (ss.dwWaitHint<1000) Sleep(1000);<br />
else <br />
if (ss.dwWaitHint>10000) Sleep(10000);<br />
else Sleep(ss.dwWaitHint);<br />
<br />
}<br />
else<br />
goto out;<br />
<br />
}<br />
<br />
<br />
<br />
}<br />
}<br />
<br />
out:<br />
<br />
MessageBox(NULL,"Service running","",MB_OK);<br />
<br />
<br />
DWORD ret;<br />
HANDLE hDrv;<br />
char pth[1024];<br />
char DrvPath[1024];<br />
<br />
GetModuleFileName(GetModuleHandle(0),pth,sizeof(pth));<br />
<br />
strcpy(DrvPath,GetDriverFromFilePath(pth,fd.cFileName));<br />
MessageBox(0,DrvPath,"",MB_OK);<br />
<br />
<br />
hDrv=CreateFile(DrvPath,<br />
GENERIC_READ | GENERIC_WRITE,<br />
FILE_SHARE_READ | FILE_SHARE_WRITE,<br />
0,<br />
OPEN_EXISTING,<br />
FILE_FLAG_OVERLAPPED,<br />
0);<br />
MessageBox(0,ErrorMessage(GetLastError()),"CreateFile",MB_ICONINFORMATION);<br />
<br />
<br />
out=false;<br />
CALLBACK_INFO call;<br />
ACTIVATE_INFO activateInfo;<br />
activateInfo.bActivate=TRUE;<br />
bool active=false;<br />
CreateThread(0,0,Opreste,0,0,0);<br />
<br />
<br />
kmev=OpenEvent(SYNCHRONIZE,FALSE,"ProcObsrvProcessEvent");<br />
MessageBox(0,ErrorMessage(GetLastError()),"OpenEvent kmev",MB_ICONINFORMATION);<br />
int st=DeviceIoControl(hDrv,<br />
IOCTL_PROCOBSRV_ACTIVATE_MONITORING,<br />
&activateInfo,<br />
sizeof(activateInfo),<br />
NULL,<br />
0,<br />
&ret,<br />
NULL<br />
);<br />
<br />
MessageBox(0,ErrorMessage(GetLastError()),"DeviceIoControl",MB_ICONINFORMATION);<br />
<br />
<br />
<br />
<br />
<br />
while(!kbhit())<br />
{<br />
call.hProcessId=NULL;<br />
if (kmev==0) MessageBox(0,"Wait Failed: kmev==0","",MB_OK);<br />
<br />
if(WaitForSingleObject(kmev,INFINITE)==WAIT_FAILED)<br />
MessageBox(0,"Wait Failed=Wait","",MB_OK);<br />
OVERLAPPED ov = { 0 };<br />
ov.hEvent=CreateEvent(0,1,0,0);<br />
<br />
int stat;<br />
stat=DeviceIoControl(hDrv,<br />
IOCTL_PROCOBSRV_GET_PROCINFO,<br />
0,<br />
0,<br />
&call,<br />
sizeof(call),<br />
&ret,<br />
0);<br />
MessageBox(0,ErrorMessage(GetLastError()),"DeviceIoControl",MB_ICONINFORMATION);<br />
<br />
<br />
<br />
<br />
<br />
if (call.hProcessId!=NULL)<br />
{<br />
DWORD need;<br />
HMODULE mods[1000];<br />
char nume[1024];<br />
<br />
EnumProcessModules(OpenProcess(PROCESS_ALL_ACCESS,FALSE,(DWORD)call.hProcessId),mods,sizeof(mods),&need);<br />
GetModuleFileName(mods[0],nume,sizeof(nume));<br />
if(call.bCreate==TRUE)<br />
MessageBox(NULL,nume,"Process Created",MB_OK);<br />
else<br />
MessageBox(NULL,nume,"Process Terminated",MB_OK);<br />
}<br />
CloseHandle(ov.hEvent);<br />
Sleep(100);<br />
}<br />
<br />
getch();<br />
printf("%s","Unloading driver");<br />
ACTIVATE_INFO ac;<br />
ac.bActivate=FALSE;<br />
DeviceIoControl(hDrv,IOCTL_PROCOBSRV_ACTIVATE_MONITORING,&ac,sizeof(ac),NULL, 0,&ret,NULL);<br />
MessageBox(0,ErrorMessage(GetLastError()),"DeviceIoControl",MB_ICONINFORMATION);<br />
ControlService(hService,SERVICE_CONTROL_STOP,0);<br />
DeleteService(hService);<br />
<br />
<br />
return 0;<br />
}<br />
<br />
DWORD WINAPI Opreste(LPVOID pParam)<br />
{<br />
bool x;<br />
x=false;<br />
while(x==false)<br />
{<br />
if(GetAsyncKeyState(VK_ESCAPE)<0)<br />
{<br />
<br />
x=true;<br />
out=true;<br />
}<br />
Sleep(1);<br />
}<br />
<br />
_exit(0);<br />
ExitThread(0);<br />
return 0;<br />
}<br />
<br />
<br />
<br />
LPCTSTR GetDriverFromFilePath(LPTSTR FilePath, LPTSTR DriverName)<br />
{<br />
char file[1024];<br />
char file1[1024];<br />
strcpy(file,_strrev(FilePath));<br />
char slesh[2]={'\\','\0'};<br />
<br />
<br />
for (int i=0; i<=strlen(file); i++)<br />
{<br />
char fl[2]={'\0','\0'};<br />
<br />
fl[0]=file[i];<br />
fl[1]='\0';<br />
if (strcmp(fl,slesh)==0) break;<br />
<br />
}<br />
<br />
strcpy(file1,_strrev(file));<br />
file1[strlen(file1)-i]='\0';<br />
strcat(file1,DriverName);<br />
<br />
return file1;<br />
}<br />
LPCTSTR ErrorMessage(DWORD ErrorId)<br />
{<br />
<br />
LPVOID lpMsgBuf;<br />
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS,<br />
NULL,<br />
ErrorId,<br />
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),<br />
(LPTSTR) &lpMsgBuf,<br />
0,<br />
NULL<br />
);<br />
<br />
return LPCTSTR(lpMsgBuf);<br />
<br />
}<br />
gabby
|
|
|
|
|
Hi all,
I am writing a http server and client in order to pass binary data(image) from client to server. And can I transmit the binary data in binary format in the http protocol as payload, without doing base64 encoding for the binary data ?
Thanks
|
|
|
|
|
Hi,
Does anyone know how to change the colour of the HotItem-colour,
my problem is that the item set hot at the moment is dark blue and is not easily noticed next to the other items that are black. I would rather set it yellow or something instead.
Thanks in advance,
Janette
|
|
|
|
|
In my project i have inserted a WebBrowser ActiveX Control.
I want to supress the FileDownload dialog...
|
|
|
|
|
How do i detect the common Windows Error Dialog message has occured, the one with the Send Error Report / Dont Send.
|
|
|
|
|
This message is shown when your program has raised an unhandled exception. So, when you have section of your code that could possibly throw an exception, you can encapsulate it into a try-catch block.
|
|
|
|
|
I want to monitor the error caused by another program not written by me. In case it causes an exception i want my program which is monitoring for such exceptions to close it.
i am kinda lazy.
|
|
|
|
|
Your program can be written to act like a debugger and catch the exceptions generated by the other program.
Otherwise, if your piece of code can get injected into the other program, such as they will load a DLL you wrote, then you can investigate this funtion: SetUnhandledExceptionFilter
|
|
|
|
|
Hi all,
I want to know if it is possible (if anyone ever tried this) to load an application into my application. This means, I have a dialog. I want to load the other application INSIDE my dialog (so no 2nd taskbar icon, no border for the window).
I am currently launching other applications and setting their size. However, when the user switches back to my application, my application get's the focus and will jump to the front. If I just show the application inside my application, it will always have to focus.
thanks!
Geert
Want to spread the newest version of your software automatically for free? Use Updater!
Visit my website: www.gvhsoftware.org
|
|
|
|
|
|
mmmm.... Too bad.
Thanks for your help though!
Geert
Want to spread the newest version of your software automatically for free? Use Updater!
Visit my website: www.gvhsoftware.org
|
|
|
|
|
does anyone know how to subclass all controls of a specific type in a window? what i mean is the window style just like corel draw 9. everything including the CFileDialog and the print dialogs has the same style - same buttons, edit boxes,etc (i dont believe they subclassed each control separately)
Live long and in prosper
johny74656@gmail.com
|
|
|
|
|
The subclassing of a window can occur per window instance or for the entire class, meaning for the entire process.
So, if you want to subclass all windows for a single dialog, you need to subclass each instance of a child control window separately. You replace the window procedure for the window's instance. -> SetWindowLong(hWnd, GWL_WNDPROC, ... );
If you want all child windows to be modified for the entire application, then you can subclass the window procedure globally by replacing the window class's window procedure with your own code. -> SetClassLongPtr(hWnd, GCLP_WNDPROC, ... );
|
|
|
|
|
hello,
can somebody tell me how to write code for graying/ungraying of menu items?I have written following code but its not working:
HWND hwnd;
EnableMenuItem(GetMenu(hwnd), ID_GRAPHDISPLAY_CHANNEL1, MF_DISABLED| MF_GRAYED );
It gives error that GetMenu() doesnt take one parameter.
why?
please guide
thanks
|
|
|
|
|
|
hello,
this is not working.What i want is that when i close my child modeless dialog box the grayed menu item should be enabled.So in OnClose handler i am writing code for enabling menu item.But its not working.I have created an object of class CMenu and using function EnableMenuItem() as follows
CMenu mymenu;
mymenu.EnableMenuItem(ID_MENU_CHANNEL1,MF_ENABLED);
this is not working
plz help
thanks
|
|
|
|
|
sayup wrote:
when i close my child modeless dialog box the grayed menu item
Which menu item ? From which menu ?
sayup wrote:
CMenu mymenu;
mymenu.EnableMenuItem(ID_MENU_CHANNEL1,MF_ENABLED);
Is this because your CMenu is a local variable that you destroy immediately after leaving the function in which you have created it ? Post more code, plz.
~RaGE();
|
|
|
|
|
You may have more luck taking over the UPDATE_COMMAND_UI function for that menu item. This is a pretty simple process, and doesn't require that the modeless child dialog know anything about the parent, or have to send some sort of signal to indicate that it's been hidden or unhidden. The UPDATE_COMMAND_UI handlers get fired whenever that menu item is about to be displayed.
I'm going to assume that you have a View menu with your various modeless sub-dialogs represented within this menu. In this case, I'm going to further assume that you have a command ID assigned for each dialog. For example, you may have IDC_VIEW_MYCHILD as the ID for the menu command to toggle show/hide some child dialog.
Using ClassWizard on the parent window/frame/etc., find the IDC_VIEW_MYCHILD command in the left hand pane. In the right hand pane, you'll then see entries for COMMAND and UPDATE_COMMAND_UI. Double-click the UPDATE_COMMAND_UI to create an Update handler for that menu item, and go edit that code.
Like I said, MFC will call the UPDATE handler for each menu item as it's getting ready to display the menu. This allows the user to customize each menu item separately via the UPDATE handler for that item.
In your case, using the codes above, you'd end up with a new function along the lines of CMyFrame::OnUpdateViewMychild . This function will receive a pointer to a CCmdUI object. CCmdUI has a lot of features, but for your purposes, you'd only need the Enable() method. If you have a pointer to the modeless dialog, then you can simply Enable or Disable the menu item based on the visibility status of the dialog, as such:
void CMyFrame::OnUpdateViewMychild(CCmdUI * pCmdUI)
{
pCmdUI->Enable(!m_pMyChild->IsWindowVisible());
}
This code will enable (ungray) the menu item if the window is not visible, or disable (gray) the menu item if the window IS visible.
By using the UPDATE_COMMAND_UI handlers, you don't have to have the modeless child do any kind of mucking about with the main application menus or anything like that. This keeps them independent, and is a lot cleaner. In addition, one simple line of code takes care of your problem.
Hope this helps (and I hope I didn't "assume" too much )
Bob Ciora
|
|
|
|
|
Hello All,
I am having a List control in my [B]Form View[/B]. I want to create it dynamically by calling "CreateEx". My problem is when I am creating it is creating in different location than where I placed in the form. The code ( VC++ 6.0 / Windows 2000) is given below
DWORD dwStyle = LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP;<br />
CRect rect;<br />
GetDlgItem (IDC_LIST1)->GetWindowRect(&rect);<br />
VERIFY(m_oTabList.CreateEx(WS_EX_CLIENTEDGE, _T("TestControl"), _T(""), dwStyle, rect, this, IDC_LIST1, NULL));
GetWindowRect returns values {104, 400, 27, 498}. The Control is placed much below the location where i created.
Then I tried to use GetClientRect instead of GetWindowRect. At this time the value returned {0, 292, 0, 467} This time it draws at the top of the client area.
How to get the control location with respect to client area?
Thanks in Advance
Ravi
|
|
|
|
|
Ravi Sankar S wrote:
How to get the control location with respect to client area?
Api [ScreenToClient ] Will help
"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
|
|
|
|
|
You have two options:
i) Use GetWindowRect (which gives you rect in terms of screen coordinates) and then convert it using ScreenToClient. Then add the offset that you want to have for your list control from the top-left of your dialog.
ii) Use GetClientRect (which will directly give you the rectangle of YOUR COMPLETE DIALOG). So you need to add some offset to the top-left point (which is (0,0) right now), and subtract some offset from the bottom-right point.
Ravi Sankar S wrote:
At this time the value returned {0, 292, 0, 467} This time it draws at the top of the client area.
So from your description, I think using the rect {10, 250, 10, 400} would perhaps suit your needs.
Regards,
Pravin.
|
|
|
|
|
COCreateInstance() call failed from MFC client when trying to call the
interface for ATL COM EXE(LOCAL SERVER)...Any solution or workaround
|
|
|
|
|
any chance to see a piece of code and/or an error message ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Look at my earlier cry for the same error ..
http://www.tech-archive.net/Archive/Data/microsoft.public.data.oledb/2004-03/0086.html
it was mainly due to usage of improper or outdated usage of some header files ...
Look at the parameters passed in cocreateinstance() function and check if all the params are present in your relevent headers
redindian
|
|
|
|
|