|
hi,
use function as follow:
1. CString szText = xxxctrl.GetWindowText();
by szText, you will get substring you want.
2. EditCtrl.SetSel(nStart,End), it will set substring to highlight.
nstart is the begin position of selection char by bytes, and nEnd is last
|
|
|
|
|
I am trying to install a local service under the context of a trusted domain account.
I installed the service correctly and it starts fine running under the LocalSystem context, however the service fails to start under the domain account because of a logon failure.
The domain account I am using meets all of the following requirements. Please tell me if I am missing anything:
1). Account is enabled/unlocked
2). Account password I am using is valid (logged into a few machines with it)
3). Account has local admin rights on the machine I am installing the service on
Attached is the CreateService() function I am using to install the service.
Thank you
TCHAR szPath[MAX_PATH] = (L"\"C:\\Program Files\\Temp.exe\"");
TCHAR szStartName[50] = (L"Domain\\User");
TCHAR szStartNamePassword[50] = (L"**********");
schService = CreateService(
schSCManager,
SVCNAME,
SVCNAME,
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL,
szPath,
NULL,
NULL,
NULL,
szStartName,
szStartNamePassword);
|
|
|
|
|
Make sure that the Domain\User account has the LogOnAsService right granted.
|
|
|
|
|
Graham, How do I set this programatically?
Thanks
|
|
|
|
|
|
Hey everybody!
I've been looking for a while for a way to get all print jobs being sent from the computer.
I tried to hook notepad and hook StartDocW and SetJobW, but nothing caught up.
Does anyone know of a way to hook the printing jobs?
Thanks a lot!!!
|
|
|
|
|
|
I have simple program (one dialog) with a rich edit control.
My OnInitDialog() event looks as follows:
BOOL CRichEditTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
// The m_oPrinterDC stores a device context of default printer
// The lLineWidth stores width which is less significant than width of
// the rich edit control - to have right margin.
m_oRichEditCtrl.SetTargetDevice( m_oPrinterDC, lLineWidth );
::SendMessage(
m_oRichEditCtrl.GetSafeHwnd(),
EM_SETTYPOGRAPHYOPTIONS,
(WPARAM)TO_ADVANCEDTYPOGRAPHY,
(LPARAM)TO_ADVANCEDTYPOGRAPHY
);
return TRUE;
}
When I type some sentences I can see that words are wrapped very nice (as expected).
Unfortunately when I type some unusual words they are not wrapped/formatted correctly.
For example: let N be the maximum number of dots (without spaces) that can fit in one line (without wrapping) in the rich edit control.
When I type N dots I have correct right margin (as expected).
When I type N+1 dots (without spaces) I have N dots in first line and 1 dot in second line
but the N dots in first line extend beyond the end of area where they should fit.
Can anyone give me some feedback on this issue? How can I achieve correct text formatting when text is unusual?
|
|
|
|
|
I have downloaded a unit testing framework which is written in standard C++. I have the source as well as a "lib" file. Is it possible to use that "lib" file in my CPP file instead of copying that framework source to my application directory.
I have added the "lib" file path in the visual studio's directory search path, but still it is complaining that the header files are missing. This error will disappear if I copy the framework's source files to my application directory. So is there any way to use the lib file in my project?
Any help would be great
|
|
|
|
|
The lib file may have the compiled object code from the source code,
but you will need to #include the header files in any of your source
modules that use code from the library.
That doesn't mean you have to copy source into your project folder.
You can use a path in your #include directives.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes that helped a lot. I solved the problem. It happened because of my lack of knowledge on how linker works.
To solve this, I have taken "Project Properties -> Linker -> Input" and added my library name in "Additional dependencies". Header file is written like the following
#include "c:\somepath\someheader.h"
I can copy the someheader.h to my application directory, but this file is a facade header file which contains includes to several other files. So compiler is complaining about those missing ones. Is it a good practice to give fully qualified path for the includes?
Thanks Mark for helping me. Have a great week ahead.
|
|
|
|
|
Christian Flutcher wrote: Is it a good practice to give fully qualified path for the includes?
I personally don't like fully qualified pathnames because it may cause a problem
when I move a project to another computer or a different drive.
I also don't like copying third-party source to my project's folder.
I like to arrange my project folders so I can use relative paths, something like
SolutionFolder
ProjectAFolder
ProjectBFolder
ProjectCFolder
ThirdPartyLibFolder
Then if a source file in project A needs to reference a ThirdPartyLib header file:
#include "..\ThirdPartyLibFolder\someheader.h"
That way the entire solution folder tree can be freely moved around without having to change
source code.
You can also use relative paths to reference the .lib
Christian Flutcher wrote: Have a great week ahead.
Thank you! You too!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: I also don't like copying third-party source to my project's folder.
Yeah. But looks like we can't avoid copying them to the solution folder.
|
|
|
|
|
Christian Flutcher wrote: can't avoid
"Can't"?
I guess if you don't mind someone else's code mixed in with yours...
Whatever works for you
I also use some SDKs from Microsoft, which aren't installed in my solution
folder tree.
For those I add the appropriate paths to the Visual Studio project directories
settings so they are available to all projects.
My main goal is to not have absolute paths in source code - it's a pain to change them
later....not good for maintainability.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Christian Flutcher wrote: I can copy the someheader.h to my application directory, but this file is a facade header file which contains includes to several other files. So compiler is complaining about those missing ones. Is it a good practice to give fully qualified path for the includes?
You should not use hardcoded path in your source. Assume if you go to another machine and there the headers exist in another directory, either you've to edit the source or copy the headers to hardcoded path. Well, the solutions are as follows.
Solution 1
1) Include the header by just filename - #include "someheader.h"
2) Declare an environment variable - SOME_HEADER_PATH with path as C:\Somepath .
3) Restart visual studio IDE for making the new env var in effect.
4) Take Visual Studio project settings, C/C++ tab, Preprocessor settings category.
5) In "Additional include directories " add - $(SOME_HEADER_PATH) .
6) Now recompile the project.
Here you've moved the directory dependency to an external env var. And if you move to some other machine, just make sure that the env var in that machine holds the right path to your Somepath.
Solution 2
1) Include the header by just filename - #include "someheader.h"
2) Take menu, Tools > Options > Directories tab .
3) Now add C:\somepath to the include directory search list.
4) you are done.
Well, depends on your requirement choose the best. Well, I recommend the first.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Jijo,
That was brilliant answer. It helped a lot. I followed the solution 1 and it worked like a charm! Appreciate your help.
Jijo raj wrote:
http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
WOW! great blog. I like the images you added there.
|
|
|
|
|
Hello guys,
I've created a struct and defined it as a new data type. However, when I want to declare a variable of this type there are several errors:
SMap: Illegal use of this type as expression
mySMap: undeclared identifier
<br />
#include <stdio.h><br />
#include <stdlib.h><br />
<br />
#ifndef NULL<br />
#define NULL 0<br />
#endif<br />
<br />
typedef struct<br />
{<br />
int width;<br />
int height;<br />
char* data;<br />
} SMap;<br />
<br />
SMap* createMap(int width, int height);<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
int width;<br />
int height;<br />
printf("Enter width: ");<br />
scanf("%i", &width);<br />
printf("Enter height: ");<br />
scanf("%i", &height);<br />
<br />
SMap* mySMap = (SMap*)malloc(sizeof(SMap));
<br />
return 0;<br />
}<br />
<br />
SMap* createMap(int width, int height)<br />
{<br />
SMap* mymap = (SMap*) malloc(sizeof(SMap));<br />
if (mymap == NULL)<br />
{<br />
return NULL;<br />
}<br />
mymap->width = width;<br />
mymap->height = height;<br />
mymap->data = (char*) malloc(width*height);<br />
if (mymap->data = NULL)<br />
{<br />
free(mymap);<br />
return NULL;<br />
}<br />
return mymap;<br />
}<br />
</stdlib.h></stdio.h>
I know that the use of malloc() isn't necessary in C++ but I want to compile the code as C-code.
Does anyone know why this doesn't work, maybe it's a basic thing I forgot about?
Thanks and best wishes.
|
|
|
|
|
Do you get different errors if you change the extension of the from between C and CPP? Then you'll be using the different compilers.
Also, for the initial typedef, try this:
struct _SMap_
{
int width;
int height;
char* data;
} SMap;
then, in main:
main (...)
{
int n;
...
n = sizeof(struct _SMap_);
n = sizeof(SMap);
}
and see if any happiness results.
Iain.
|
|
|
|
|
I told VS to compile the project as C-code until now this was enough.
As expected the results of the sizeof()-operations were the same (12Byte).
However, this didn't change anything. I've no idea what's the problem.
|
|
|
|
|
In C all variables must be defined at the start of the scope they belong to.
Change main() to:
int main(int argc, char* argv[])
{
int width;
int height;
SMap* mySMap;
printf("Enter width: ");
scanf("%i", &width);
printf("Enter height: ");
scanf("%i", &height);
mySMap = (SMap*)malloc(sizeof(SMap));
return 0;
}
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
Thanks, this was my problem. I knew that variables must be defined at the beginning of their scope when programming micro processors, didn't know that this is also important when writing Windows programs.
Thanks a lot.
|
|
|
|
|
It is a C language rule, platform/os doesn't matter.
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
we set focus to a control by sending WM_NEXTDLGCODE to it but in the case
1- the control is a button, check box or radio box
2- the dialog is opened by clicking a menu item by mouse and not keyboard
3- the user has not pressed TAB yat.
if we set focus to a button check box or radio box by code, the focus rectangle around the control text is not displayed and if the control has BS_NOTIFY style, the border is not darkened and user can not see which control has the focus.
is there any other methode to set focus to a control by code? or am I mistaken in some way?
I program with visual studio 9
Thanks
modified on Saturday, November 15, 2008 9:05 AM
|
|
|
|
|
|
No, SetFocus is not the correct answer. According to MSDN, WM_NEXTDLGCODE does things far beyond SetFocus, such as redrawing pushbutton border, and updating button`s push state and focus state.
Thanks for your reply
Abzadeh
|
|
|
|