|
|
The service is created only when i logged in as administrator .Its not working in When i logged in as a Local User.
Thanks
BOBY
boby
|
|
|
|
|
Are you sure you really have permission to write where you want to write ?
|
|
|
|
|
I want to run my application first at win2k startup,before the other application run.
|
|
|
|
|
|
If you start your app from a windows service, then it will be running even before any user logon. Here is the a tool[^] that helps you to do that.
If the other application is also a window service, then you have to modify it so that it depends on your service. When a service depends on another service, windows will load the other service first.
P.S. Your app may have problems starting from a service. Typically this is a resource issue (somthing required is not available because nobody has logged on to the machine yet). There are ways to get around this problem, but not always.
My articles and software tools
|
|
|
|
|
What is the easiest way to find and send info to any window containing a certain string?
such as, if i wanted to find any window that has a title containing "- Notepad" and send the current time and date to the bottom...
|
|
|
|
|
If you want to find one window:
HWND FindWindow(
LPCTSTR lpClassName, // class name
LPCTSTR lpWindowName // window name
);
If you want to search for all:
HWND GetNextWindow(
HWND hWnd, // handle to current window
UINT wCmd // direction
);
int GetWindowText(
HWND hWnd, // handle to window or control
LPTSTR lpString, // text buffer
int nMaxCount // maximum number of characters to copy
);
Mickey
|
|
|
|
|
You can search for a window handle or a CWnd object by using the FindWindow-function.
When the call returns, you have either a pointer to CWnd representing this window (MFC version) or the window's HWND (API version). Then you can use this HWND e.g. to change window title by using SetWindowText-function, or if you use the MFC-version, you can use the CWnd to mess around with the window just as if you would have created it yourself. Change status bar, toolbar, menu, layout, minimize, maximize etc etc
What exactly is it that you want to do with the current time and date ? Should the target window display this on it's status bar ? Or draw it somewhere else inside it ? Want to hijack a window's Device Context ? Explain. The 'Send the current time and date to the bottom' isn't very informative
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
well, basically i want to add the current time and date to the bottom of the page in all open notepad windows, save and close them.... to remember where i left off at, and what date/time i was reading it.... but this is just for knowledge.. im not going to make a nice program out of it... just experimenting :-/
|
|
|
|
|
Ahh ok.
Let's create a general outline of the solution to this problem.
1. Find the window
2. Enumerate the views of this window
3. With each view, access the underlying document
4. Get this document's CString, and append the current date and time to the end.
5. Force window to save all it's open documents/views.
For a specific, Notepad-only solution, the outline is a bit different, because Notepad doesn't have any real views: it has one HUGE edit control.
Now, some code pieces. With the MFC-way, of course
<br />
CWnd* pNotepadWin = new CWnd;<br />
<br />
HWND hwndNotepad = ::FindWindow( ClassName, NULL ) );<br />
<br />
if ( hwndNotepad )<br />
{<br />
pNotepadWin->Attach( hwndNotepad );<br />
}<br />
else<br />
{<br />
delete pNotepadWin;<br />
return FALSE;<br />
}<br />
<br />
Now we have the CWnd representation of the Notepad window.
<br />
CWnd* pNotepadEdit;<br />
<br />
pNotepadEdit = pNotepadWin->GetTopWindow();<br />
<br />
if ( !pNotepadEdit )<br />
{<br />
pNotepadWin->Detach();<br />
<br />
delete pNotepadWin;<br />
return FALSE;<br />
}<br />
<br />
bool bContinue = true;<br />
while ( bContinue )<br />
{<br />
CString strName;<br />
<br />
::GetClassName(pNotepadEdit->m_hWnd, (LPTSTR) strName, 20);<br />
<br />
if ( strName.CompareNoCase("Edit") == 0 )<br />
bContinue = false;<br />
<br />
pNotepadEdit = pNotepadEdit->GetNextWindow(GW_HWNDNEXT);<br />
<br />
if ( !pNotepadEdit )<br />
{<br />
bContinue = false;<br />
}<br />
}<br />
<br />
Phew. That was some coding. But now we have the CWnd of the edit control inside Notepad. After this, it's easy to use 'GetWindowText' and 'SetWindowText' to append the current date and time to the edit control's contents.
Perhaps I should turn this into an article
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
What a perfect world it could be with out errors.
Going forth in a software developement I got to an error which I could not find a resource that give an answer.
It's about templates, and I must tell you that I'm new in this stuff.
Consider 'ClassA' which requiers template list when you want to define a object of it. Like this:
ClassA<long> obj;
And Consider another class that is the same to the previous one, 'ClassB' (with template list).
Now here's the problem, how can you define an object of 'ClassA' with the template list of 'ClassB' type, it should be something like this:
ClassA<ClassB> obj;
But compiler tells me that it has an error becuase 'ClassB' requiers a list of templates. So I thought that it might be defined like this:
ClassA<ClassB<long>> obj;
Now it has an another error:
error C2146: syntax error : missing ',' before identifier 'obj'
Well how can I define an object from a class with template list of sort of a class with template list?
|
|
|
|
|
Hi
The solution is pretty simple.
In stead of
ClassA<ClassB<long>> obj;
use
ClassA<ClassB<long> > obj;
Yes, the only difference is a space. The reason for the error is that the compiler finds '>>' and believes it to be the >> operator instead of the end of the template lists. So if you put in a space, the first > will end the inner template list and the second the outer and the compiler is happy.
|
|
|
|
|
Hello everybody,
I'm reading a .jpg file, everything goes fine, readhuge reports reading the hole file but what I've got in the buffer is just 4 bytes. What is ReadHuge reading ?
code:
buffer = new char[1000000];
if (buffer == NULL)
{
cout<<"Not enough memory";
return;
}
try
{
imageFile.Open(fileTitle,CFile::modeRead,&e);
imageFile.ReadHuge(buffer,1000000);
imageFile.Close();
CString output = header + buffer;
imageFile.Open("msg01",CFile::modeCreate | CFile::modeWrite,&e);
imageFile.WriteHuge((LPCTSTR) output,output.GetLength());
imageFile.Close();
delete []buffer;
}
|
|
|
|
|
The jpg contains binary NUL characters; your output = header + buffer statement will append the buffer up to the first NUL byte (or WORD, if you're using UNICODE), so GetLength() isn't giving you a big enough number.
Steve S
|
|
|
|
|
How to restore (maximize) my application instead of running a new instance when another instance is already running?
|
|
|
|
|
You could try to define a hook to maximize your app when you do smtg ... Or you could hit ALT-TAB
|
|
|
|
|
|
Somehow, before you create your app window, you need to find if another instance is running. One way is to use a named mutex that each instance tries to aquire. Another is to use the main window text as shown below (although not the suggested method) :
HWND h = ::FindWindowW(AppName, NULL);
if( h ) {
::SetForegroundWindow( (HWND)((ulong)h|0x00000001) );
return(true);
}
The key point in the above is not finding the app window, but how to restore it once found.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Working with the Wizzard, I define the PreCreateWindow function - and it never gets the control.
Does anyone have an idea, why not?
|
|
|
|
|
I assume you use MFC here.
There, the PreCreateWindow is a virtual member function of CWnd. This having said, in order to overwrite it succesfully you need to derive a class from CWnd or one of it's derivates (view/control).
Then you would, in your main program's InitInstance, create a 'new' object of your type using:
CMyDerivedCWnd* pWindow = new CMyDerivedCWnd;
When you would create the window object by calling "pWindow->Create(...)", the PreCreateWindow WILL get called by the framework.
Perhaps you have not derived from CWnd ? Perhaps you haven't overwritten your derived class's PreCreateWindow, but you just added some PreCreateWindow -function to your code ? In that case, check your function declaration. The framework will call THE PreCreateWindow of your DERIVED CLASS, and NOTHING else
Greets,
Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thankx. I guess I misunderstood PreCreateWindow; I wanted to gain control before the window of my own main dialog will be constructed.
Btw, do you know
a) how to change font attributes IN an EXISTING CFont?
b) if I change the font size in OnSetFont, will that influence the size of the window and all controls?
because this is just what I wanted to achieve in PreCreateWindow.
|
|
|
|
|
Like I said, the PreCreateWindow allows you to fiddle with the create struct of the window. This structure contains info like the window class, window title, cursor, default brush, menu etc etc. This function is called before the Windows API call 'CreateEx' is called. This API call is responsible for actually creating the Windows window object. The framework will bind then this object (by it's handle) to the CWnd/CDialog object.
For example, in custom controls, it is common to make a check for class name in the PreCreateWindow -override. If this member is NULL, the control will register a new window class with AfxRegisterWndClass to make sure that it has a valid class (All top-level windows in MFC MUST have a valid class name). This way it doesn't bother the end user with this.
To get a complete idea of this, go check the Windows API reference on window objects. Look for things like WNDCLASS structure, RegisterWndClass function, CreateWindow and CreateWindowEx functions. These functions are called by the framework to actually create it's objects. You can, just as well, create them yourself and call the 'Attach' method of CWnd to bind your CWnd object to an existing window handle. Now, you can modify this window through the CWnd wrapper.
As for answers to your questions:
a) What you are trying to do is impossible, font-wise. After a Windows font object is created, you can't modify it. However, you _can_ modify a CFont object. It is just a wrapper for the underlying font.
To accomplish similar results, you can get the CFont-bound Windows font object's representation to a LOGFONT structure by calling the GetLogFont member method of CFont. This will fill the specified LOGFONT structure with the information about this specific font bound to this specific CFont.
Then, use the CFont's member function 'DestroyObject' to destroy the current font object, making sure that it is not selected to a device context, otherwise your program might crash/assert/throw an exception.
After you have destroyed the old object, modify the LOGFONT structure to meet your new demands. Then call 'CreateFontIndirect' of CFont and pass a pointer to the LOGFONT (use address-of) structure. This will create a new Windows font object with the specified parameters, and attach this font to the CFont object.
The general version of this routine (Get current params -> Destroy old -> Modify params -> Create new) is applicable to all GDI objects and their MFC wrappers (CPen, CBrush, CFont etc)
b) For some background info: each Windows window object (Window, dialog, control etc) has a default GDI object of each type bound to it. It has a default pen, a default brush... and a default font.
Now, the OnSetFont function of CDialog does precisely as it's description in MSDN says: it allows you to set a new default font for your dialog. This font is copied (passed) to all controls (statics, buttons etc) drawn by the dialog. So, yes, in a way. If you specify a new default font for your dialog, each control it draws will use this default font to draw it's texts. I am unsure whether the underlying framework routine will resize your controls depending on the font, but I believe that it will. The only way to make sure is to test it.
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thanks for the explanation. However, OnSetFont receives a pointer to the CFont; it can not pass back a new CFont. I was already so far, that I displayed the current font attributes (GetLogFont) and created a new CFont - but I can't tell MFC to use this CFont.
|
|
|
|
|
Most interesting.
Apparently 'OnSetFont' didn't work as straightforward as I had understood from the MFC Reference. It seems that this handler can't be used to override the passed font object, because in doing so, the program asserts in the end. Why this happens is currently still unclear to me.
However, I've already found a few alternates, but they require you to alter the font for each and every control of your dialog box seperately. Go to your main application, and force a creation of modeless dialog box. Once the box is created, get a control ID inside it (GetDlgItem), and call this returned pointer's 'SetFont' method, issuing an address of a precreated CFont.
If a modeless dialog box is not an option, then create a dynamic CFont object in your dialog's constructor by using a LOGFONT structure with values you specify. Don't forget to zero the structure before using it. Then call 'GetDlgItem' in your dialog's WM_PAINT handler and the result's 'SetFont' to give it a new font. Remember to delete the Windows font object and release the dynamic CFont object, e.g. in your dialog class's destructor.
In all cases, remember to check your app for memory leaks, they tend to become easy with these things
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|