|
Hi, id like to crate Cursor from image or bitmap made in program (not from file). And is there a way how to draw on existing cursor ? Thanks.
|
|
|
|
|
Can anyone show me how to enable XP-Style selection highlight for a ListView control? Thanks in advance.
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
I assume you mean how Windows explorer lets you drag a rectangle around the files/folders you're selecting? If that's what you mean, I'm not sure this functionality is available. If it is, it would be available in UxTheme.dll (search codeproject for this). In .NET 2.0, there is a wrapper for UxTheme in the form of System.Windows.Forms.VisualStyles.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Hallelujah! It's Ken Jennings!
Judah Himango
|
|
|
|
|
I am experiencing problem regarding calling a "PostThreadMessage" function from outside the thread function. A code is attched below... Please go through it and guide me as to how to go about correcting it...
/*
The PRODUCER and OTHER threads post messages to the
CONSUMER thread. All the threads wait on the
"consumerReady" event to be set by the main thread.
*/
#include <windows.h>
#include <iostream.h>
#include <stdio.h>
typedef struct temp
{
int msid;
char *msg;
}box;
// Thread IDs. Define these globally so the threads can refer to each other.
DWORD producerID, consumerID, otherID;
void get_msg(DWORD quid,box *obj);
void post_msg(DWORD quid,box *obj);
// An event
HANDLE consumerReady;
// The producer thread.
DWORD WINAPI produce(LPVOID)
{
// Do not start producing until all threads are ready.
WaitForSingleObject(consumerReady, INFINITE);
int count = 0;
while(count < 2)
{
box *ptr;
ptr=(box *)malloc(sizeof(box));
ptr->msg = (char *)malloc(10);
strcpy(ptr->msg,"hello\0");
ptr->msid = 12;
post_msg(consumerID,ptr);
// PostThreadMessage(consumerID, WM_USER, (WPARAM)ptr, 0); // works fine if this
// line is used instead
// of above line
Sleep(1000);
printf("\nposted 12");
count++;
}
return 0;
}
// The consumer thread.
DWORD WINAPI consume(LPVOID)
{
// Do not start producing until all threads are ready.
WaitForSingleObject(consumerReady, INFINITE);
Sleep(0);
int count = 0;
while (true)
{
box *ptr;
ptr=(box *)malloc(sizeof(box));
ptr->msg = (char *)malloc(10);
get_msg(consumerID,ptr);
count++;
printf("count %d",count);
}
return 0;
}
DWORD WINAPI other(LPVOID)
{
// Do not start producing until all threads are ready.
WaitForSingleObject(consumerReady, INFINITE);
int count = 0;
// Send simple integers. Use WM_USER messages with the integer values
// in the wParam field.
while(count < 2)
{
box *ptr;
ptr=(box *)malloc(sizeof(box));
ptr->msg = (char *)malloc(10);
strcpy(ptr->msg,"other\0");
ptr->msid = 11;
post_msg(consumerID,ptr);
// PostThreadMessage(consumerID, WM_USER, (WPARAM)ptr, 0); // works fine if this
// line is used instead
// of above line
Sleep(1000);
printf("\nposted 11");
count++;
}
return 0;
}
// main() runs the simulation.
int main()
{
// Create an event which is initially unsignaled
consumerReady = CreateEvent(0, TRUE, FALSE, 0);
// Create the threads and start them immediately.
HANDLE consumerHandle = CreateThread(0, 0, consume, 0, 0, &consumerID);
HANDLE producerHandle = CreateThread(0, 0, produce, 0, 0, &producerID);
HANDLE otherHandle = CreateThread(0, 0, other, 0, 0, &otherID);
//Set the event now that all threads are ready
SetEvent(consumerReady);
//Keep the main thread alive
WaitForSingleObject(producerHandle, INFINITE);
WaitForSingleObject(consumerHandle, INFINITE);
return 0;
}
void post_msg(DWORD quid,box *obj)
{
PostThreadMessage(quid, WM_USER, (WPARAM)obj, 0);
int err = GetLastError();
printf("\n obj_post->msgid %d ",obj->msid);
printf("\n err_post = %d ",err);
}
void get_msg(DWORD quid,box *obj)
{
MSG lmsg;
GetMessage(&lmsg, 0, 0, 0);
obj = (box*)(lmsg.wParam);
int err = GetLastError();
printf("\n obj_get->msgid %d ",obj->msid);
printf("\n obj_get->msg %c ",*(obj->msg));
printf("\n err_get = %d ",err);
}
///////////////////////////////////////////////////////////////////////
The output is given below:
obj_post->msgid 12
err_post = 1444
obj_post->msgid 11
err_post = 1444
posted 12
obj_get->msgid 12
obj_get->msg h
err_get = 0 count 1
posted 11
obj_get->msgid 11
obj_get->msg o
err_get = 0 count 2
obj_post->msgid 11
err_post = 1444
obj_post->msgid 12
err_post = 1444
posted 11
posted 12
////////////////////////////////////////////////////////////
As can be seen , posting the messages results in a error id of 1444(INVALID THREAD IDENTIFIER) which is puzzling cos all the threads are already created....
Any help would be appreciated in this regard...
|
|
|
|
|
|
ok, I have a simple regular expression:
<br />
Regex to_find = new Regex(textBox2.Text, System.Text.RegularExpressions.RegexOptions.None);<br />
textBox3.Text = to_find.Matches(richTextBox1.Text, 0).Count.ToString();<br />
obviously, it just sends the count of the resulting matches to textBox3. this is good to test regular epxressions, but it doesn't provide any way I can see to format the results (besides the replace option). like for instance, I would like to atleast select the results one at a time (select, not highlight), without using the "find" thing for a richTextBox.find(...). even more though, I would prefer to actually be able to highlight the results in blue or green or something of that sort, rather than just selecting them. where do I find these options for regular expressions? sry I don't know all the big terms for classes or what not.
thanks for the help,
Stephen P.
|
|
|
|
|
|
what is the easiest way to get the current system time?
|
|
|
|
|
DateTime.Now.ToLongTimeString() or something like that.
I'm too damn lazy to look it up.
|
|
|
|
|
You beat me by two minutes!!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
|
I have a shortcut on the desktop, and I have a path to it, but if I try to use it, a new folder is created on the desktop. How do I take the path to a shortcut and get the path to the actual folder ?
Thanks
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I've found a way of doing it, but it involves a COM interface. If there's a non-COM way, I'd love to hear about it....
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
What do you mean by "but if I try to use it, a new folder is created on the desktop"? Are you trying to access a folder shortcut? Can you explain it a little more?
It seems you've solved the problem via COM but here is another solution via Com Interop to Access the Windows Scripting Object. Maybe useful for a clear solution:
http://www.knowdotnet.com/articles/createshortcutondesktop.html[^]
|
|
|
|
|
(plz i need help, to make apper the bmp image as a pixles by c#
|
|
|
|
|
Wow - you do need help.
Image.FromFile
DrawImage
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
MSDN as usual sucks on documenting this, and most threads contain only partial code. I'm trying to create a windows service that allows anyone to call its "bool HelloWorld(string sSayCheese)" method via remoting.
The consumer of this method will be an asp.net page, but for now can be anything including a console app.
I have created many Windows services, so this is not the problem. The service is running fine, but I can't get it to allow others to call its public methods remotely.
Any help would be greatly appreciated for myself and the other devs in the office.
Thanks!
|
|
|
|
|
I usually put all my objects offering remote calls in a class library project. Then I can debug them by hosting them from a console application. As soon as they are debugged, I put the remoting configuration code in the service OnStart and the system.runtime.remoting section of the config file in the service config file. Either way, the startup code is the same whether it is in the Service OnStart or in a console app main().
The hardest part of your problem is consuming the remote objects from a web app; you must put the client configuration code in the Global.asax code behind file in the Application_Start method.
There are many people here who can answer your questions if you can make them specific enough. Are you having trouble with the remoting part, or is it that you don't know about Global.asax Application_Start? Give us some info and we can help.
|
|
|
|
|
The problem is in the remoting portion of the service itself.
The service looks like:
<br />
public class MyService : System.ServiceProcess.ServiceBase<br />
{<br />
private m_sString = "hello";<br />
...<br />
protected override void OnStart(string[] args)<br />
{<br />
RemotingConfiguration.Configure("RemotingServer.Config");<br />
}<br />
...<br />
public string StringFunction()<br />
{<br />
return m_sString;<br />
}<br />
...<br />
}<br />
And uses the following RemotingServer.config:
<br />
<configuration><br />
<system.runtime.remoting><br />
<application><br />
<service><br />
<wellknown <br />
mode="SingleCall" <br />
type="MyService,Tools.MyService" <br />
objectUri="MyService.rem"<br />
/><br />
</service><br />
<channels><br />
<channel ref="http" port="8500"/><br />
</channels><br />
</application><br />
</system.runtime.remoting><br />
</configuration><br />
The client looks like this:
<br />
MyService remoteObject = (MyService) Activator.GetObject(typeof(MyService), "http://localhost:8500/RemotingClient.rem");<br />
string sRetVal = remoteObject.StringFunction();<br />
The client RemotingClient.rem file looks like:
<br />
<configuration><br />
<system.runtime.remoting><br />
<application><br />
<client><br />
<wellknown <br />
type="MyService, Tools.MyService"<br />
url="http://localhost:8500/MyService.rem"<br />
/><br />
</client><br />
</application><br />
</system.runtime.remoting><br />
</configuration><br />
The error I receive is:
<br />
An unhandled exception of type 'System.Net.WebException' occurred in mscorlib.dll<br />
<br />
Additional information: The underlying connection was closed: Unable to connect to the remote server.<br />
The client code is sitting in an console app.
The service starts and reports it is running correctly. It is compiled as a DLL.
|
|
|
|
|
I am sorry I have not replied quickly. There are several problems to consider in the approach you have. You can't remote your whole service like you are trying to do. Instead, put your code in a class (preferably in a new class library project). The class must inherit from MarshalByRefObject to be remoted. Also, the "type" attribute in your config files should be in the form type="namespace.class,assemblyname". It looks like you have it backwards.
Also, when you write the client app, you can add a reference to your remote class, but is generally looked upon as bad practice. It will work though for learning about remoting. After you become more comfortable, there are other ways of referencing your remote objects in the client such as implementing an interface in the remote code, and only referring to the interface in the client code. There are also ways to make a meta data assembly using soapsuds to extract the definitions from the remote object, then compiling an assembly using the output from soapsuds. For now, just keep that in the back of your mind to explore after you get romoting to work in the most simple case.
1. Make a new class library project (call it HelloWorld or something).
a. Add a Class called HelloWorldInfo or something.
1. Make sure it inherits from MarshalByRefObject
2. Make a console project to act as a test server (call it MyServer).
a. Add a reference in MyServer to HelloWorld.
b. Add a config file to MyServer and add the remoting config to it.
c. In Main(), call the remoting configuration, and then wait for a keypress.
3. Make a console project to act as a client to the server.
a. Add a reference to HelloWorld (this is not good practice, but will serve as a simple way during learning).
b. Add a config file and put the client remoting config in it.
c. In Main(), call the remoting configuration, then call any methods you want and output the results to the console.
4. Debug the server by starting it in Visual Studio
a. Open a command prompt and type "netstat -a"
b. look in the list output from netstat for the port you have assigned to your remote object. You should see your computer listening on that port.
5. Open your client in another copy of Visual Studio and start it for debugging.
a. You can now step through your code in debug mode, and even step into the server code. This makes debugging much easier.
6. Once the server code is fully debugged, Make a new windows service project.
a. Add a reference to HelloWorld.
b. Put the remoting configuration code in the OnStart of your service.
c. Add an installer to your service.
d. Add a setup project to install your service.
After you get comfortable with remoting, be sure to go back and learn how to reference remote classes in the remote client without deploying the server code to the client (so it by implementing interfaces, or compiling metadata-only assemblies).
|
|
|
|
|
Hi,
I had trouble about flickering effect on an MDI form. I'd built my own control, which is moveable by draging, and also overrided the paint event. It was very well in a normal form but unfortunately disappeared in MDI form. Even some of the codes provided here have the same problem. What is handle the MDI form painting event? Is it different from the normal one? And how could I fix such a problem?
Thanks in advance.
|
|
|
|
|
There's nothing different about an MDI Form being painted. There is no seperate event for painting either.
Is your control on the MDI Parent form? Did you know that there is a MDIClient control on the Parent form? Is you control in the Controls collection of the MDIParent or the MDIClient? If it's the MDIParent, your control is probably being painted over by the MDIClient area control.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is there a way to import regirtry files within C#?
this way i could update some settings myself, and then in C# just open up the registry to the necessary folder and import the files. This would save alot of messing around and i would be able to use the peice of code again.
Any ideas?
|
|
|
|
|
This is an example of a file exported from regedit:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ppt]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ppt\OpenWithProgids]
"PowerPoint.Show.8"=hex(0):
this is just for the file extension .ppt
Is there any way that i can use this?
|
|
|
|
|
I am not sure how this is done. I have been doing some searching and reading and I can't seem to get this to work. I am really bad with terminology, but if someone could point me in the right direction I would bw greatful...
Thanks,
Eric Garcia
|
|
|
|
|