|
The only way to make them globally visible is to create a class that has them as public static members. There is no global scope in C#. Personally, I think this looks like C code, I'd ditch the all caps syntax, and maybe even use an enum instead.
const is only good for compile time values, for run time values, they need to have class scope, and be declared in the constructor, and they need to be readonly, not const.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Where would I put the enum to make it globally visible?
|
|
|
|
|
Same again, there is no such thing as globally visible, excepting public and static on a class that you use to hold this sort of stuff. Or just outside any class, if they all have the same namespace.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Anywhere you want outside a class declaration.
|
|
|
|
|
Create a struct that has static accessors to the constants you want to define. Such as:
public struct Aprori
{
static public int Running
{
get { return _Running; }
}
private const int _Running = 5;
}
...
Then access it by
int x = Aprori.Running;
That way you have one object that contains your constants and is easily accessed. If you have differing constants you can group them in other structs for similar purpose.
|
|
|
|
|
I'm trying to write a small program (just for experience) that I can use to change my desktop wallpaper, but I can't see to get it right. I'm using the following code:
Bitmap img = new Bitmap (path);
try
{
img.Save (path, System.Drawing.Imaging.ImageFormat.Bmp);
SystemParametersInfo (0X14, 0, path, 0X1 | 0X2);
}
catch (Exception ex)
{
MessageBox.Show ("There was an error setting the wallpaper: " + ex.Message);
} path is the path to the image file which is currently in jpg format. When the img.Save line executes it throws an exception that says simply, and quite unhelpfully, "A generic error occured in GDI+". Any help on what I'm doing wrong would be appreciated.
Thanks.
- Aaron
|
|
|
|
|
monrobot13 wrote:
Bitmap img = new Bitmap (path);
monrobot13 wrote:
img.Save (path, System.Drawing.Imaging.ImageFormat.Bmp);
Why do you need to save it as a bmp ? Why are you using the same path to save it ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I was under the impression that an image had to be a bitmap to use as the wallpaper...is this not the case? I have no real reason as to why I was using the same path to save it.
- Aaron
|
|
|
|
|
A jpg is also fine. You should perhaps create a new file, and see what happens then. And check first if it's a bmp already. The Path class has static methods to help with this.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I was just testing out the code and the SystemParametersInfo function is changing the background when I pass it the path to a .bmp, but when I pass it a .jpg it just sets the background to nothing (as if "none" were selected in the display options). So I have two questions:
1. Does the SystemParametersInfo function only work with .bmp's and if so is there any other way to change the background?
2. Is there a way to change an image from one type to another? If the answer is as simple as the Image.Save function, but using a path that isn't the current open image (as I was doing before), then forget I asked the question.
Thanks much for the help.
- Aaron
|
|
|
|
|
monrobot13 wrote:
Does the SystemParametersInfo function only work with .bmp's
Looks like it. I think jpgs work via active desktop, so that could be why.
monrobot13 wrote:
If the answer is as simple as the Image.Save function, but using a path that isn't the current open image (as I was doing before), then forget I asked the question.
What question ? :P
Yes, that's how you do it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
First, thanks for taking the time to help me on this Christian.
Second, I still can't seem to save anything using the Image.Save method. Here's my entire chuck of code, maybe you could help me find what, if anything, I'm doing wrong.
if (lstFiles.SelectedIndex >= 0 && lstFiles.SelectedIndex < lstFiles.Items.Count)
{
string szImgPath = dlgDir.SelectedPath + "\\" + lstFiles.SelectedItem.ToString();
Bitmap dibBkgnd = new Bitmap (szImgPath);
try
{
string szSavePath = @"C:\Documents and Settings\Temp\Incomplete\";
dibBkgnd.Save (szSavePath, System.Drawing.Imaging.ImageFormat.Bmp);
SystemParametersInfo (0x14, 0, szSavePath, 0x1 | 0x2);
dibBkgnd.Dispose ();
}
catch (Exception ex)
{
MessageBox.Show ("There was an error setting the wallpaper: " + ex.Message);
}
} When I run this I'm still getting the same exception ("A generic error occurred in GDI+") thrown on the Save method.
The image is of the jpg format and I'm trying to save it as a bmp so I can set the wallpaper. I also tried changing the ImageFormat to a Jpeg just to see if it was a problem with saving to a different type, but I received the same exception. I also tried having no '\' after Incomplete cause I wasn't sure it was added in in the Save , but again the same exception.
Any and all help you can offer is very appreciated.
- Aaron
|
|
|
|
|
monrobot13 wrote:
First, thanks for taking the time to help me on this Christian.
No worries, it beats working :P
monrobot13 wrote:
string szSavePath = @"C:\Documents and Settings\Temp\Incomplete\"; dibBkgnd.Save (szSavePath, System.Drawing.Imaging.ImageFormat.Bmp);
Well, this can't work. You need to append a file name to the path
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
No worries, it beats working
Heh, isn't that the truth.
Hmm, well I feel quite the fool. I've no idea why I didn't think of that. That was defenitley the problem as I've got it working now.
Thanks for all the help, I probably never would have picked up on that. Also, thanks for the help on the My Documents folder problem.
It's been much appreciated.
- Aaron
|
|
|
|
|
My pleasure - there's no escaping the fact that GDI+ isn't exactly helpful with it's error messages....
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
The cause of the error is that you are trying to save the file with the same name as the file you loaded. As long as the Bitmap object exists, the source file is open.
---
b { font-weight: normal; }
|
|
|
|
|
Have an issue with accelerator keys being displayed (underlined) and handled in my menus
i add menu items with '&' before the letters i want to act as accelerators, but when i run the program these are not displayed and handled until i hit the alt key. Unlike most other programs ive seen which always display the underlined accelerator.
what this means for me is that if i mouse click to open up a menu i cant see, nor use, any of the accelerator keys.
i literally need to go (for example) alt-f to open file menu, and then can i only see the other accelerators and use them.
is there a standard (built-in) way of having the accelerators always shown? or do i need to implement this myself (if so whats the best approach)?
thanks in advance
- paul
|
|
|
|
|
See my post here[^].
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
You can pass by reference, which is the same thing to all intents and purposes ( that is, you get the same result ).
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
excellent, thanks! C# has some quirks I'm not used to in C++
-mutty
|
|
|
|
|
Mutty wrote:
C# has some quirks I'm not used to in C++
Yeah, there's a lot that looks more similar than it is. If you try to use const and find it next to useless, try readonly. Not a whole lot better, but closer....
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Well actually this brings up my next question... see my post about constant declarations. -mutty
|
|
|
|
|
hey i'm making a web browser, i got the progress bar in my status bar, i know how to make it go up by setting a value and the performstep() function but how do i get it to go up when i load webpages? it doesn't matter if its in c++ or c# well c# preferably since thats what i'm programming the browser in but if you know what it is in c++ i'll just transfer it over to c#, thx in advance.
|
|
|
|
|
if i understand what yoy need correctly
you can get the length of the file there are http header that can get the legth of the file but maynot return value in all cases this header is Content-Length
by using this value and chunks transfer at second
you can progress your progress bar
MCAD
|
|
|
|