|
Toolbars can pull the images for their buttons from either a bitmap (as you are doing now) or from an image list. If you use an image list, you can easily add icons to it dynamically and cause buttons to display them; see the Toolbars & Docking Windows section here for more information on how to use image lists in toolbars.
Shog9
------
Sitting in muddy water
isn't such a bad life,
if it ends after the first time... - Yoko Kanno, The Real Folk Blues
|
|
|
|
|
I have looked through most of the articles but I could not really find anything that will work. Unfortunately, my project is written in C, not C++ nor MFC. Many or most of the articles reference classes, which I cannot use. So I am still lost. I undestand how to get the handle to the icon, just no clue how to apply it to my toolbar. Any other ideas?
|
|
|
|
|
CarpeDiem wrote:
Many or most of the articles reference classes, which I cannot use.
Well, you'll just be writing more code yourself then; it's all the same in the end. How are you creating and initializing your toolbar now?
Shog9
------
Sitting in muddy water
isn't such a bad life,
if it ends after the first time... - Yoko Kanno, The Real Folk Blues
|
|
|
|
|
This is a little tough to describe. The main toolbar has bitmaps that are contained in the resources. When the app is launched, there is a function that someone created that loads all the bitmaps. There is another function, similar to TBADDBITMAP, with a few minor changes. The toolbar window itself is created with a CreateWindow and uses a class (which I do not have access to). The buttons are added one at a time. So, I have to call a function to add the button, even though I don't have a bitmap, so the button is blank. I am sorry for not being overly descriptive, I don't have access to all the code to see the exact details of how it is getting loaded...
|
|
|
|
|
Alright, well this needs some clarification yet, but here are your options from what i can see:
If you are using standard Win32 toolbars (CreateWindow(TOOLBARCLASSNAME, ...); , then you can easily convert your existing code to work with image lists, which makes dynamically adding icons trivial.
If you are using some other toolbar class, then all bets are off; you'll need to find out what's possible. If it turns out you need to have all the buttons in one big bitmap that's created when the toolbar is initialized, things get a bit more tricky. But it's still possible to get it working, you'll just need to figure out how many icons you want and draw them onto the bitmap prior to adding it to the toolbar.
Shog9
------
Sitting in muddy water
isn't such a bad life,
if it ends after the first time... - Yoko Kanno, The Real Folk Blues
|
|
|
|
|
From my understanding (and looking at the code), the main toolbar is created through a CreateWindow(TOOLBARCLASSNAME, ...); What happens is that each individual bitmap that is used for each button is actually contained within 1 file. There are about 39 bitmaps stored within this one file and is assigned at run time. For instance, the toolbar is created and then SendMessage(hwndTask, TOOLBARADDINGFUNCTION, 120, IDB_BUTTON_TO_ADD) is called. This is what actually assigns the bitmap to each button, the 120 is the position the bitmap is stored at. Did this help at all?
Sorry for the different username, I am using a friend's computer to reply and I just noticed he was logged in as his username.
|
|
|
|
|
I don't have any example code at hand right now (at home, eating ), but here's the process in a nutshell:
- Create the toolbar with
CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD|WS_VISIBLE|TBSTYLE_FLAT|TBSTYLE_WRAPABLE, 0, 0, 0, 0, hwndParent, (HMENU)ID_TOOLBAR, hInstance, NULL); or similar. - Use
ImageList_Create() to create an image list of the appropriate size for your bitmap. - Use
ImageList_Add() or ImageList_AddMasked() to add bitmaps to the image list. Use ImageList_AddIcon() to add icons to it. - Send the
TB_SETIMAGELIST message to the toolbar, associating the image list with it. - Send the
TB_BUTTONSTRUCTSIZE message to the toolbar, informing it of the size of the TBBUTTON structure you'll be using. - Send the
TB_ADDBUTTONS message to the toolbar, adding buttons as necessary.
This leaves out a lot of detail, i know, but give a look through MSDN for each step, and i think it'll make sense. If not, post back tomorrow & i'll see what i can do.
Shog9
------
Sitting in muddy water
isn't such a bad life,
if it ends after the first time... - Yoko Kanno, The Real Folk Blues
|
|
|
|
|
I have researched all of the items that you suggested. The biggest problem is not being able to post the code so you can see exactly what is happening. In a nutshell, it was described to me is that what happens is that the bitmap is read in and when we need to place a button's bitmap on the toolbar, we pass in the resource id of the button and the position the image is in on the bitmap. Basically, we have one bitmap file that contains about 40 images. When adding a button, we pass in the position the image is in and there is some code that I do not have access to that handles applying it. So, I tried to implement most of your suggestions. I called ExtractIcon to get the handle to the icon from the .exe file the user might choose, I created the ImageList, I called the AddIcon to add it. Here is gets a little sticky. From here, I call GetImageInfo to get the bitmap handle, then I tried to use the bitmap handle to apply the bitmap to the button. It doesn't work when I do this. What happens is that there is a function that does a CreateCompatibleDC, then does a GetObject with the handle to the bitmap, then does a SelectObject, if the SelectObject returns good, it does a BitBlt. The problem I have discovered is that the SelectObject returns 0x00000000 every time. The bitmaps placed on the toolbar the old way use LoadImage to get the bitmap handle. I use the GetImageInfo. But, in the end, it doesn't work. My biggest handicaps are I don't have access to all the code and I am forced to leave the way the other buttons are placed on the toolbars, I was told not to change that code. Am I screwed or what?????
|
|
|
|
|
CarpeDiem wrote:
I was told not to change that code. Am I screwed or what?
No, but you're deprived of a clean and easy way to do it - some poor maintenance programmer is gonna be cursing you all when the time comes to bring this code into the 21st century (i've been that poor sap...).
In any case, this is what you'll have to do: every time you add an icon, you'll need to re-create your master bitmap, making it slightly larger and then draw the icon onto it. Then you'll need to re-associate it with the toolbar.
I'm sorry i can't be more specific, but i don't know what your situation is - there are many ways this could be done. You can post some relevant code here, or email it to me privately, and i can give you some more specific tips.
Shog9
------
I hope I die naive - Paul Watson, Partners and their dreams
|
|
|
|
|
Hello,
How can I permanently set the splitter size? For example: Instead of the Left / Right view I have a split from left to right so I have a top and a bottom. I want the bottom view to always stay the same height even when the window is being resized.
I'm a newbie with splitters and am unsure how I can keep my bottom view set to a permanent height. I assume I should handle MainFrame WM_SIZE and somehow set the splitter location..
Any ideas?
Thanks,
Rob
|
|
|
|
|
try this:
CRect rect;
GetClientRect(&rect);
int x = rect.Width()/2;
Then set the width of your pane = x
Regards
|
|
|
|
|
Sorry, this isn't a solution to your problem
|
|
|
|
|
CSplitterWnd has methods for getting and setting the dimensions of static splitters: GetRowInfo , SetRowInfo , GetColumnInfo , and SetColumnInfo . In your frame WM_SIZE handler you can compute the size of the splitter and call one or more of these methods to set it. After you have the splitter(s) set the way you want, you have to call RecalcLayout() to update the splitter layout.
Software Zen: delete this;
|
|
|
|
|
Can someone please tell me how I can read a DWORD value from the registry and display it as a decimal. I registry API function that I have looked at seem only to be able to read a string value. Help with this is most appreciated.
- SAK
|
|
|
|
|
There are countless registry articles on CP, but here is a function I use:
DWORD CGlobalUtility::GetRegDWORD(HKEY hKey, CString cstrSubKey, CString cstrVar)
{
DWORD dwRetVal = 0;
DWORD dwTemp, dwSize = sizeof(DWORD);
HKEY phkResult;
if (RegOpenKeyEx(hKey, cstrSubKey, 0, KEY_QUERY_VALUE, &phkResult) == ERROR_SUCCESS)
{
RegQueryValueEx(phkResult, cstrVar, NULL, &dwTemp, (LPBYTE)&dwRetVal, &dwSize);
RegCloseKey(phkResult);
}
return dwRetVal;
};
Jason Henderson start page ; articles
henderson is coming
henderson is an opponent's worst nightmare
* googlism *
|
|
|
|
|
oops. take out that CGlobalUtility stuff.
Jason Henderson start page ; articles
henderson is coming
henderson is an opponent's worst nightmare
* googlism *
|
|
|
|
|
For your case reading the value as a string is the best thing. Then all you need is to convert it to a double using atof or _tcstod (for UNICODE).
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
What I want to do would seem simple but I cannot seem to find the answer to this anywhere. I want to save 2 integer variables and a string to a file from a dialog based application. I can find how to do the string but the integer, or other numeric variables is elusive. serialization is not what I need, what I want is every time int1, int2 and strComment are entered into edit boxes the user clicks a button and the info is saved. This is easily accomplished in vb, but I cannot seem to do it in Visual c++. I am using Visual studio 6.0
Michael Deming
mdeming@hotmail.com
|
|
|
|
|
Why not read the values of the edit boxes and then use standard ofstream .
Best regards,
Alexandru Savescu
P.S. Interested in art? Visit this!
|
|
|
|
|
Hey Mike,
Alexandru is correct as using a ofstream object would be rather simple if that is all you need to do, something such as this should work:
ofstream outputfile;
outputfile.open("myFile.dat", ios::out);
if(outputfile.is_open())
{
outputfile << m_int1;
outputfile << m_int2;
outputfile << time;
outputfile.close();
}
Hope this helps..
Nick Parker
May your glass be ever full.
May the roof over your head be always strong.
And may you be in heaven half an hour before the devil knows you’re dead. - Irish Blessing
|
|
|
|
|
Some endl s are called for here if you want to read the info later.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
You could just use Get/SetPrivateProfileInt() and Get/SetPrivateProfileString() to save the data to an .ini file.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Thanks Nick, Alexandru and Ravi
I used the fstream and it does exactly what I needed. I guess the biggest hangup was I was not aware that fstream would work under windows. None of the books I have were clear on the subject. I am curious as to how I could accomplish the same task using Get/SetPrivateProfileInt() and Get/SetPrivateProfileString() for the same task. Also Is there one for GetSetPrivateProfileDouble()?
Mike Deming
|
|
|
|
|
MikeDeming wrote:
Also Is there one for GetSetPrivateProfileDouble()?
No. Just convert it to a CString using Format() and read/write it out as a string.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
My application uses a DLL that causes some trouble:
I can call LoadLibrary successfully (the returned HMODULE is not NULL).
Trying to call FreeLibrary immediatly hangs my application...
Any ideas? I also mention that the dll I am trying to load/free uses some thread variables (__declspec (thread)). Could this be the problem?
Thanks!
Best regards,
Alexandru Savescu
P.S. Interested in art? Visit this!
|
|
|
|
|