|
Try,
HICON hSmallIcon = (HICON) ::LoadImage ( AfxGetInstanceHandle (), MAKEINTRESOURCE(IDR_MY_SMALL_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR );
it always works for me. But, remember that unlike LoadIcon, this one does require a subsequent call to DestroyIcon when your're done with the it.
-Ben
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Thanks for the reply, but I want to load built-in Windows icons and avoid including resources in my project. (Because it's a class I plan on using in several projects.)
For example:
HICON hIcon = (HICON)LoadImage(NULL, IDI_INFORMATION, IMAGE_ICON, 16, 16, LR_SHARED);
This always loads a 32x32 image and fails if LR_SHARED is removed.
BTW, IDI_INFORMATION is the same as MAKEINTRESOURCE(OIC_INFORMATION) but you don't need to #define OEMRESOURCE and can leave out the MAKEINTRESOURCE macro.
|
|
|
|
|
BTW, I know I can load the 32x32 icon and paint it as 16x16 using DrawIconEx but that does an absolutely appalling job of scaling the image. I've seen the OS use 16x16 versions of them that look good, for example in Win2k tray icon bubbles, but I can't work out how to load them...
Maybe I need to load them directly from the DLL which contains them... Gah, nasty and not guaranteed to work in the future, but luckily the code will only be run on NT4 machines so it could be a safe bet.
(The code is to emulate Win2k tray icon bubbles when running on NT4 machines.)
|
|
|
|
|
I'd say, save yourself some greaf and just copy them into your applications resources. This will not only work, but be will garonted to work in the future.
BTW: I found this in MSDN
In LoadImage:
When loading a system icon or cursor, you must use LR_SHARED or the function will fail to load the resource.
Windows 95/98/Me: The function finds the first image with the requested resource name in the cache, regardless of the size requested.
The second part does not seem to apply to you, but it seems you must use LR_SHARED on all Windows flavors.
-Ben
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Hi all - I hope you can help
I have a multi frame app eg like an MDI but each document is in it own mainframe - however whenever I try printpreview it always uses the first main frame and not the one I am trying to print preview - can anyone help me on this?
Holy Handgrenade of Antioch instructions
|
|
|
|
|
Everything I seem to see on this site is C++ and not C. Can someone please give me a hint as how to implement a static splitter window using just window API instead of MFC.
Thank you in advance,
SAK
|
|
|
|
|
You can create splitter in C. Below I'm assuming that you want simple two-way vertical splitter, you can generalize this solution to horizontals and combined splitters.
1) Registering your main window class use your own cursor looking more or less like this: <-|->
2) create your child windows in WM_CREATE handler. Use WS_EX_CLIENTEDGE style for 3D look.
3) in WM_SIZE handler ensure that height of these windows is equal to the height of main window's client area. Set that widths are set to the value that leaves some small area between two child windows. This area is your splitter bar.
3) your main window will receive mouse-related messages only if cursor is placed in the 'splitter' - the area between child windows. In WM_LBUTTONDOWN handler capture the mouse, resize child windows in subsequent WM_MOUSEMOVEs, and release mouse in WM_LBUTTONUP.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
I have a group of about 30 checkboxes.
I would like to put them into an array so i can easily get and set the values.
What process is required to do this?
Thank You
|
|
|
|
|
Save in the array a reference of each checkbox.
good Luck
Carlos Antollini.
|
|
|
|
|
Previously I asked if there was a way to separate the colors for stdout & stderr when writing to a console. I never got a response. So in the unlikely event someone else was wondering about this, check it:
You need these headers:
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
When you fire up a console (using AllocConsole(), and when you're done call FreeConsole()), get the stdout & stderr handles by doing:
HANDLE hStdOutput;
HANDLE hStdError;
Then you can use the following routine just like fprintf. Now, if your routine is doing a ton of processing and suddenly an error pops up, your machine hangs, then reboots itself, you'll have a shot at seeing what went wrong! (especially when the reboot tends to wipe your logs)
//only goes to stdout or stderr!!!
int myfprintf(FILE *stream, const char *format, ...)
{
DWORD numwritten;
char *str;
va_list args; //variable argument list
va_start(args, format);
str = new char[strlen(format)*10 + 1]; // <- you're screwed if this isn't enough mem
//sprintf(str, "%s", format);
memset(str, '\0', sizeof(char));
vsprintf(str, format, args);
if (stream == stdout)
{
SetConsoleTextAttribute (hStdOutput, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
WriteConsole (hStdOutput, str, strlen (str), &numwritten, NULL);
}
else if (stream == stderr)
{
SetConsoleTextAttribute (hStdError, FOREGROUND_GREEN);
WriteConsole (hStdError, str, strlen (str), &numwritten, NULL);
}
delete[] str;
return (numwritten);
}
I've only tried this on NT Workstation 4 & Win98se, lemme know what you think...
--
Peace,
Amit Jain
|
|
|
|
|
This raises a subtle point. I am guilty of not responding to your original post. The reason? I'd answered the same question twice already. Sigh...
This is not to say that you should have read every post to see if there was an answer. (btw lets have a rockin party when the VC forum hits 10000), but you can see where it gets tiresome. I'm not suggesting a search is the best way either - sometimes its difficult to know what to key on (if you knew what you were looking for... )
So - my point? Well, the thought of a FAQ does arise... Is it feasable? How much work would it be to take the wealth of stuff we've got in the forums and make a FAQ? Chris? Anyone?
One thing I have noticed is that people do check the articles - once a relevant article exists, the forum querys on that topic abate.
Anyway, I'm think I'm posting a lounge article in the wrong place here.
BTW you addressed the issue better than I did (hey, they're not all gems! )
Cheers
T
|
|
|
|
|
An open moderated FAQ would probably help... Like interesting questions and good answers, modded by either the community or the mods. You're absolutely right though, I hate searching for the answer to a specific programming question, it's hard to narrow it down properly, and usually my terminology is wrong.
--
Peace,
Amit Jain
|
|
|
|
|
Hi,,
each class can serialize its own data memebers, is that right?
ex:
Class myclass1
{
int x;
}
class myclass2
{
myclass1 item;
}
I like to know if myclass2 can serialize the data member (int x) of myclass1 ??
Thanks
Ehsan Behboudi
|
|
|
|
|
You can serialize another class's data if:
a) if myclass1 has members that give access to its data
b) myclass2 is a friend of myclass1
c) if myclass1 declares its data a public (not a great solution)
-Ben
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
You should have a Serialize() function in myclass1, then myclass2.Serialize() can call item.Serialize().
|
|
|
|
|
Dear all
how to set the IP address during programming ? Generally the IP address is set in the network neighborhood and then restart the PC . I want to set the IP address in my programm and don't restart the machine. Is it possible?
Thanks a lot
|
|
|
|
|
You need to disconnect, then connect again. This is because the server need to evaluate if is valid your ip, and update your ip in the list. Is for this that is better to reboot the PC.
But you have a sample in win95 that permits to change the ip without reboot the PC, with the application winipcfg, with this app you can disconnect and connect again, get a new ip, without reboot.
Cheers!!!
Carlos Antollini.
|
|
|
|
|
Hello, the codegurus around the world.;)
Your question seems to be tough.
Window 95, (98 & ME), NT, and 2000 has the differnt approaches to bind IP address to
NIC.
Windows 2000 has some API to change IP address, and the others seems not to have one.
Check MSDN help like the below.
Platform SDK: Internet Protocol Helper
IP Helper Functions
Rebooting the comp is very important to update the registry each other.
On NT, if we add NIC, and ipconfig command, we doesn't get the right info since
the registry entry mismatches.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
hi,
In Win2000 there is ipconfig, in Win98 there is winipcfg . They can refresh the IP address without reboot .I am wondering that they act as dhcp clients and after they send out a dhcp broadcast message ,then the ip address is changed by the dhcp server .
So I think there would be one method to change the IP address without rebooting . In MSDN the SDK of IP helper is useful for config the network, but the functions seems to only work in Win2000 .And I also can't assign a IP address which I want to assign using those functions.
|
|
|
|
|
Hello, the codegurus around the world.;)
Well, I think that you are right as long as we set IP as DHCP checked in TCP/IP settings.
Because DHCP server assigns our client machine as the temporary IP address
on the view of the client and server.
However, on the other hand, we can assign the static IP address to our machine.
Actually, I use the static IP address for peer-to-peer network on my Windows 98s.
On this situation, I have to reboot my comp if I change my static IP address.
So, as long as we use DHCP support, and we know which IP address DHCP server has,
we can assign the dynamic IP address. However, if this IP address is assigned to
the other machine, the client and server will be screwed up?
We may need more to consider the code.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
Hello
I want to compare two structures to find out whether they are identical or not.
What is the easiest way to do that?
thanks
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Assuming you're using C, not C++...
If the structure doesn't contain pointers, you can use
if( memcmp( &struct1, &struct2, sizeof( mystruct_t ) ) )
{
// different
}
else
{
// identical
}
This is fast, but assumes that a byte-by-byte comparison is valid (e.g. that padding elements will always match).
If there are pointers, you may wish to check the data they point to, instead of the pointer values themselves.
If you have nested structures containing pointers, this can get quite messy.
In C++, each data type can check for identicallity itself, so there's no problem.
|
|
|
|
|
What? In C++ each data type can check itself? Not true, not even close.
There's always the issue of a logical compare versus a bitwise compare.
Take something like
CString a = "Hi";
Cstring b = "Hi";
Depending on compiler settings (like string pooling) these may or may not point to physically different strings. In that case a bitwise compare would fail.
In C++ one way would be to have classes implement operator ==
But there are many different ways to approach this problem. It just depends on what you need.
--
Bryan
|
|
|
|
|
" What? In C++ each data type can check itself? Not true, not even close."
"In C++ one way would be to have classes implement operator == "
Should have been clearer - the == operator is what I meant. Then recursed classes are not the problem they are in C.
|
|
|
|
|
Ah, ok, my point back to gregor is that even if you implement operator ==, there is no magic, you still need to decide how your class is going to test for equality. And if your class has many memeber variables, you'll need to test all of them.
--
Bryan
|
|
|
|
|