|
Hi,
I would like to change the font and size of text in static text...
I have been able to change color. here are the command lines I use to do that.
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0, 0, 255));//blue
But have not found a say to set the font or font size. Is it possible to set the font size and color for a static text control in MS CE C++ (v4.0)? If it is can anyone give me a hint of how to do this?
Thanks
-- modified at 12:27 Thursday 7th June, 2007
|
|
|
|
|
Two steps are needed. First you need a font, or in the case of MFC a CFont. Then you need to select that font into the DeviceContext you already have a pointer to, pDC, before the static gets drawn. I guess in the same place as you put SetTextColor, the WM_PAINT handler.
I Can't remember off the top of my head whether you call a function on the DC pDC->SelectObject(myFont) or if you can do it the other way around myFont.Select(pDC) but you'll figure that out in no time.
Remember to record the previously selected Font which will get returned when you do the SelectObject and re-select that one back into your DC after you've finished painting or you might screw up the next guys control by drawing it with your font
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Thanks for your quick reply. Between you response and the one from Anurag Gandhi think I have the changing to static text fonts handled.
As you suggested I have a lot of studying to do on these topics. I've been developing in the UNIX/LINUX environments for years. Now they throw a an MS CE C++ project on me and want it done yesterday!!!!
I welcome the chance to learn but it’s a challenge.
Thanks!!
|
|
|
|
|
To change the font face, size, weight and other properties, Create a new font and attach it with your Device context.
use following code:
CFont font;
font.CreateFont(20,0,0,0,200,0,0,0,0,0,0,0,0,_T("Times New Roman"));
pDC->SelectObject(&font);
//First parameter is Height and 2nd is width. when 0 is passed, it takes proportionate height or width.
Now you will be able to change the font size. I will suggest read more about fonts in VC++ from any tutorial.
Anurag Gandhi.
|
|
|
|
|
Wow thanks Anurag Gandhi. I added your suggestion to by code and it ran just great!!!
As you suggested I have a lot of studying to do on these topics. I've been developing in the UNIX/LINUX environments for years. Now they throw a an MS CE C++ project on me and want it done yesterday!!!!
I welcome the chance to learn but it’s a challenge.
Thanks!!
|
|
|
|
|
I have a bunch of button resources that I want to set to be visible depending on certain criteria.
Here is a sample of the code I have:
for(i=0; i<number of sub entities; i++)
{
//for check button
pBtn=GetDlgItem(IDC_STRIPVIEW_DEVICE_1_CHECK_BTN);
pBtn->ShowWindow(SW_SHOWNORMAL);
}
I to be able to have the number in the IDC identifier change correspond to i.
How do I get the number in the IDC to be variable. Or how can I make MFC
treat a string as a resource id?
Thanks
Adam
|
|
|
|
|
Can you make the IDs consecutive and use i as an offset from the first ID?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I don't think I would be able to do that, but I can make a CString that says, for example IDC_STRIPVIEW_DEVICE_3_CHECK_BTN when i=3, but all I need to know how to do is pass that to string to the GetDlgItem function and have it accept it as an unsigned integer resource id.
Adam
|
|
|
|
|
GetDlgItem expects an integer ID. You could map indexes to an array of strings but that just
adds an unnecessary level of indirection since you'd need to convert that string back to an int
to call GetDlgItem. So, you might as well use i to index an array of actual control IDs
(integers).
That brings me back to what I was thinking...
#define IDC_BUTTON1 1000
#define IDC_BUTTON2 1001
#define IDC_BUTTON3 1002
#define IDC_BUTTON4 1003
#define IDC_BUTTON5 1004
#define IDC_BUTTON6 1005
...
for(i=0; i<number of sub entities; i++)
{
pBtn=GetDlgItem(i + BUTTON1);
pBtn->ShowWindow(SW_SHOWNORMAL);
}
-or-
for(i=IDC_BUTTON1; i<IDC_BUTTON6; i++)
{
pBtn=GetDlgItem(i);
pBtn->ShowWindow(SW_SHOWNORMAL);
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hello,
Suppose I have a dll called MyDLL.dll which is statically linked to External.dll . Now I load MyDLL.dll from my application like this:
handle = LoadLibrary("MyDLL.dll");
Now, if MyDLL.dll and External.dll are present everything works just fine and LoadLibrary succeeds (i.e. handle != 0).
When I delete External.dll, then I get this behaviour:
a) In debug mode an error message box pops up saying that External.dll was not found.
b) In release mode I don't get this error message box. handle is simply 0. So I call GetLastError() along with FormatMessage() and get an error code of 126 (specified module not found).
Ideally, I'd like to suppress the message box in a) and get its message string so I can write a more detailed description of the problem into the log. I thought GetLastError() and FormatMessage() would take care of this, but apparently they only return some hardcoded standard messages.
So my primary question is whether there is a way to get this message string somehow?
If there is no way to get the message string, I'd like b) to always display the error message box. According to the MSDN docs ( http://msdn2.microsoft.com/en-us/library/ms680621.aspx ) I need to call something like SetErrorMode(0) ( maybe something like SetErrorMode( SetErrorMode(0) | ~SEM_FAILCRITICALERRORS) ).
This call does not seem to have any effect. The current error mode is 4 ( == SEM_NOALIGNMENTFAULTEXCEPT), but the error message box still does not pop up, it keeps failing silently (handle == 0).
Can somebody help me?
|
|
|
|
|
Nitrogenycs wrote: I thought GetLastError() and FormatMessage() would take care of this, but apparently they only return some hardcoded standard messages.
So my primary question is whether there is a way to get this message string somehow?
If FormatMessage gives you the error string, then I am confused on what other message string you desire to obtain?
|
|
|
|
|
FormatMessage just gives me the error string relating to the error code 126. This is some general message like "Could not find the specified module".
The message box that's popped up shows a more detailed description of the problem, including the name of the missing dll, in this example "External.dll". This is what I really need in order to find the cause of the problem. Sometimes a user misses specific dlls (for example I forgot to include them in the package) or did not have the necessary prerequisites installed.
|
|
|
|
|
Why not just concatenate the string your using for LoadLibrary to the end of the generic message to form your own custom message that tells them exactly which dll they are missing?
|
|
|
|
|
Because the dll being loaded is not the problem. The dll being statically linked to the dll being loaded is not present and is what causes the problem. Actually, the dll being loaded might be linked against several other dlls. And I need to know which of those is missing. Missing dlls are not the only problem, they could also be somehow malformed, so I need to get the actual error message that the windows dll loader gives.
|
|
|
|
|
I'm wondering if there is a way to use the STL map class in such a way that you pass in, say, 4 parameters, the first being a key, and the other 3 being values of any type. What I mainly want is an associative container that is not limited to key/value pair.
Thanks.
|
|
|
|
|
This is easy achieved using an object (e.g. a vector) as the template type of the map.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hmm... now why didn't I think about that...
I like it.
Thanks.
|
|
|
|
|
There is multi_map and multi_hash_map .
|
|
|
|
|
AFAIK, a multi-map is a map, but the keys do not have to be unique. I haven't checked the hash map though.
|
|
|
|
|
Multiple-key map
Maps are a kind of associative containers that stores elements formed by the combination of a key value and a mapped value, much like map containers, but allowing different elements to have the same key value.
From: http://www.cplusplus.com/reference/stl/multimap/[^]
It should let you store multiple values per key, which is what you said you wanted. I've never used it myself, but it doesn't look much harder than a normal map .
multi_hash_map is just the hash_map version of it It exists in the stdex namespace in the VC++ compiler only.
Hope it helps!
|
|
|
|
|
HEllo,
I keep getting linker error "member variable already defined" when I include one file(.h) in two .cpp files.
How should I get rid of this linker error?
I have tried using #pragma once below the file #include "PlanConsts.h"
#pragma once
but still the file is included twice.
Thanks.
Prithaa
|
|
|
|
|
You shouldn't define variables in header (.h) files: only declarations there. Note that #pragma once (as well as multiple inclusion) has nothing to do with your problem.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
prithaa wrote: I have tried using #pragma once below the file #include "PlanConsts.h"
Where did you put this pragma ? Your sentence is not very clear.
The #pragma once must be placed at the top of every header file (*.h).
|
|
|
|
|
create the PlanConsts.h file as this way
#ifndef _PLANTCONSTS_H
#define _PLANTCONSTS_H
...header file contents...
..........................
..........................
#endif
I think this would solve the problem
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing.
Oscar Wilde (1854-1900)
Regards...
Shouvik
|
|
|
|
|
Hello,
thanks for all your replies.
I created planconsts.h has you said
#ifndef _PLANTCONSTS_H
#define _PLANTCONSTS_H
...header file contents...
..........................
..........................
#endif
but still I get the linker problem that the "variable already defined"
Thanks
Prithaa
|
|
|
|