|
hello, i have a problem when i try to load a bitmap to a CToolBar object.
i have a bitmap resource, and it is true color. I want to load it to my Toolbar object. but then, the buttons only display a full-black bitmap on them. When i change this bitmap on 16 colors, the buttons display them.
can anyone how to load a 24-bit bitmap on my toolbar?
this is the code:
m_dialogToolbar.Create(this);
m_dialogToolbar.LoadBitmapW(IDB_BITMAP4);
m_dialogToolbar.SetButtons(toolBarButtons,3);
m_dialogToolbar.SetSizes(CSize(rect.Width(),rect.Height()),CSize(16,15));
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
m_dialogToolbar.ShowWindow(SW_SHOW);
-- modified at 13:59 Sunday 17th December, 2006
|
|
|
|
|
Maybe try using an image list instead of the CToolBar::LoadBitmap(), something like:
CImageList m_dialogToolbarImageList;
...
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP4);
m_dialogToolbarImageList.Create(16, 15, ILC_COLOR24|ILC_MASK, 3, 1);
m_dialogToolbarImageList.Add(&bitmap, RGB(0x00,0xFF,0x00));
...
m_dialogToolbar.Create(this);
m_dialogToolbar.GetToolBarCtrl().SetImageList(&m_dialogToolbarImageList);
m_dialogToolbar.SetSizes(CSize(23,21), CSize(16,15));
m_dialogToolbar.SetButtons(toolBarButtons,3);
-- modified at 16:57 Sunday 17th December, 2006
*EDIT* Fixed constructor code
-- modified at 17:01 Sunday 17th December, 2006
|
|
|
|
|
It still doesn't work. I mean, the method works but the buttons keep displaying the bitmaps only in 16 colors My bitmap resource is truecolor.
at least now , even if the bmp is 24 bit, it shows it, but in 16 colors
-- modified at 16:01 Sunday 17th December, 2006
|
|
|
|
|
levelboy wrote: even if the bmp is 24 bit, it shows it, but in 16 colors
Sorry I didn't realize you actually wanted to see your 24 bit bitmaps in true color
Just kidding.
I fixed the code in my previous post (the imagelist construction code).
Mark
|
|
|
|
|
yeah thanks.
it works just fine now
thanks again
|
|
|
|
|
What is a handle? I see this alot in MFC. Is it some type of pointer or reference to an object or resource (like a window or button)?
Thanks,
BP
|
|
|
|
|
BlitzPackage wrote: What is a handle? I see this alot in MFC. Is it some type of pointer or reference to an object or resource (like a window or button)?
Not exactly a pointer but it in fact an identifier of, for instance, windows and files.
E.g. when you ask to the OS to create a window, it will return to you its HANDLE. Then, each time you will need to identify that window with the OS (for example to send a message to it), you will have to pass to the OS that returned handle.
However the handle is not a pointer to the window because the OS cannot return to you a pointer to memory which is relocable; giving you a handle, instead, introduces an indirection layer (a kind of table linking handles to memory addresses), warranting that the handle value will not change on memory relocation.
hope that helps.
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.
|
|
|
|
|
|
A handle is some opaque data structure used to represent some system resource. The term “opaque” means the user should not assume anything about the representation used and the actual representation used could change from OS version to OS version. A handle could be a pointer, an index into a table or something else but it doesn’t matter to the user as all access is via APIs.
Steve
|
|
|
|
|
Hi,I suggest you to read 《Programming for Microsoft Windows》by Jeffrey Richter,In the chapter 3 of the book,Jeffrey described the handle clearly.
|
|
|
|
|
I am making a autoupdater, using a CEdit text box to show a logg during the update progress, however
only static_text and the progress bar updates as the tool runs the performed action, but only updates when the action is complete.
this code is called on each update stage, progress bar in the code bellow updates as it should, but not the SetWindowText, untill the "update button" function is complete.
void CAutoUpdaterDlg::OnBnClickedUpdate()
{
CEdit * s = static_cast<cedit *="">(GetDlgItem(IDC_STATIC_MSG));
s->SetWindowText("Please wait, update in progress.");
CButton *b = static_cast<cbutton *="">(GetDlgItem(IDC_UPDATE));
CButton *b2 = static_cast<cbutton *="">(GetDlgItem(IDCANCEL));
b2->EnableWindow(false);
b->EnableWindow(false);
sprintf(DynamicBuffer,"%s","Looking for updates...\n");OnUpdateScreen();
GetList(); // Downloads, test the list for readability
// Read the file into memory
file_LoadIntoMem("UpdateList.txt");
// Download the files read from the UpdateList
sprintf(DynamicBuffer,"%s","Downloading new content in progress...\n");
OnUpdateScreen();GetTheFiles();
// After reading it into memory, delete it.
CleanUp();
// Finaly enable the buttons again
b->EnableWindow(true);
b2->EnableWindow(true);
s->SetWindowText("");
}
void CAutoUpdaterDlg::OnUpdateScreen()
{
char LocalBuffer[10];
itter++; lineslimit++;
sprintf(LocalBuffer, "%d", itter);
CEdit * p = static_cast<cedit *="">(GetDlgItem(IDC_Window));
// static message for now
strcat(WindowBuffer, LocalBuffer);
strcat(WindowBuffer, ": ");
strcat(WindowBuffer, DynamicBuffer);
int Size = strlen(WindowBuffer);
p->SetMargins(5,5);
p->SetWindowText(Convert_A_To_DA(WindowBuffer));
CProgressCtrl * progress = static_cast<cprogressctrl *="">(GetDlgItem(IDC_PROGRESS));
progress->SetRange(0,MaxRange);Progress++;
progress->SetPos(Progress);
if (lineslimit == 11)
{
int size = strlen(WindowBuffer);
for(int i = 0; i <= size+1; i++ )
{
WindowBuffer[i] = 0x00;
}
lineslimit = 0;
}
int MemSize = sizeof(DynamicBuffer);
for(int i = 0; i<= MemSize+1; i++)
{
DynamicBuffer[i] = 0x00;
}
}
|
|
|
|
|
Try using the UpdateData(...) function for the dialog before you referesh it's window or ask it to display something. If you call UpdateData(FALSE) it should write whatever you have in the SetWindowText(...) or value variable for that control onto the screen.
|
|
|
|
|
UpdateWindow(); this function worked perfect, thanks.
|
|
|
|
|
Hi,
I am new to c++ and I will use it in my thesis on image processing.
I wrote a piece of code to read a ppm image file. in order to read the magic number (the number indicating the type of the image file whether it is ppm, bmp, jpeg or etc. this magic number is in the header section of the image) i create a char pointer magicNumber:
char *magicNumber;<br />
magicNumber = new char[2];
and pass it into the function PPMreadHeader. My intent is to fill the pointer inside the function and write the magicnumber in the console outside the function.
i have an array in the PPMreadHeader fuinction in order to read the file line by line. I have a local char pointer "word":
<br />
char line[255];<br />
char * word;
when i read the magicnumber (it is "P6" for ppm files) i assign it to the local pointer word:
word=line;
if i try to write the magic number in the function using the local pointer:
cout<<word<<endl;
there is no problem, it writes p6 to the console. however, if i first copy the word into the magicnumber pointer that i create in the main function:
*magicNumber=*word;<br />
*(magicNumber+1)=*(word+1);
and then try to print out the pointer to the consolelike below:
cout<<"magicNumber: "<<magicNumber<<endl;
then it writes:
magicNumber:P6ııııİİ
which not i want. it writes the p6 which is what i want to write to the console, but it writes more than p6. within the function when i write the local pointer "word" it just writes the P6, nothing more. Could you please help me on this.
You may advise other alternatives to write the magic number on to the console but even you do this, i still want to learn what is wrong with my coding. i spent a lot of time on this and i could not fix it.
Thank you in advance.
|
|
|
|
|
char* strings in C/C++ need to have a null character at the end. if you allocate 2 chars for a two-char string, there's no place for that null to go.
so, you should allocate 3 bytes for magicNumber, and set byte #3 to 0. then use a string copy function (like strcpy or even better, strncpy) to copy the strings from buffer to buffer; that will copy the null character along, too.
so, best of all, use a C++ string class, like std::string, to handle your strings. that will eliminate the need for buffer allocation, worrying about nulls, etc..
|
|
|
|
|
emrah.a wrote: char line[255];
char * word;
Modify it to ,
char line[255] = { 0 };
char * word = NULL ;
This should solve your problem.
|
|
|
|
|
Hi All,
I'm looking to team with someone who has written an HTML parser (or can write an HTML parser). My scanners\pasrsers are generally LALR (from my Compiler Theory days in college), which is a bit different from HTML.
The requirements are loose - I don't need a DOM. Something similar to below would work well (written in C\C++):
while( EOF != document )
{
Element = GetNextElement( document )
}
Element should look as follows:
struct _E
{
string element
vector<string> attributes
string value
} Element
I'm interested in the html 'primitives': < P > tag, < H# > tags, < TITLE >, < TABLE > (no need to break out the < TD >s and < TR >s. As I said, I am flexible. There is no need to return < HEAD > or < BODY > (hence the request for 'primitive' elements). To summarize, I want the 'leaves' of the tree (leaf nodes) - not the stuff encountered on the way down (branches). For proof of concept, attributes can be empty (they may be required later).
There is no need to convert between entity codes and characters. For example, does not need to be converted to it's corresponding white space (but it may in the future). Same with the C\C++ '\t' - character 0x09 can stay that way (for now).
Additionally, the co-author will be responsible for file rotation. Think of it as a log file for this purpose. Assume there will be at least 8 files to rotate (first in, first out). The data to be read and written will be a vector< string >:
vector< string >: ReadFile( Some sort of Time identifier )
void WriteFile( vector< string >: )
The algorithm does need to be deterministic (duh) - run on the same document, it must produce the same results each time.
So, the co-author should:
* create GetNextElement( )
* file I/O
* file rotation
* well document it - the byte scanner and tokenizer should take at least 3 pages. Aho, Sethi, and Ullman managed to produce 350 pages on this portion of a front end in Compilers - Principles, Techniques, and Tools[^].
I will:
* add the usage code of Element
* remaster screen shots in Photoshop
* coordinate the publication
I'm anal about article write ups. I toss out 5's for three sentence articles with a pretty Screen shot, but that is not what I expect of myself. Please see here[^] for my articles (so you can get a feel for what I expect).
I generally post to two sites: Code Project and Code Guru. It would be nice (but definetly not required) if the co-author had a Code Guru account.
Any takers? If more than one taker, I'll ask that you fight it out amongst yourselves, or take on an additional co-author. I' don't want to have to choose. I'm actually more concerned no one will step up to the plate, so don't be shy.
If successful, I want to move the Project to SourceForge. At that time the co-author can share in the Administrative responsibilities. The project will be called WebGrits. You'll understand later when the poetry is in motion.
BTW, my portion is complete It is another Crypto++ project based on hashing.
Jeff
|
|
|
|
|
Can any one show me how to double buff in a windows media player visualization using GDI. Just a very simple example of say drawing a circle will be fine. I just cant seem to get it to work following examples.
|
|
|
|
|
Hello,
I'm writing a MFC application and I need to run a complex C program. The C program gets data from a file and the write results in another file. The MFC program interacts with the user and display data and results graphically. I've the source code but also a dilemma. Can anybody tell me what is the best way to interact with the C code?
I think have three alternatives, 1) run the exe and work with pipe's, 2) put everything in extern C code or 3) create a simple c++ class that have all the C subroutines.
For the first alternative I think I will have problems if the program does not like my data, and that implies having to test all possible errors.
In the second, since the memory allocation is based in malloc, will I get memory leaks?.
The third alternative (I'm working on it right now) will get me all the benefits from c++ environment but is taking too long, since it implies that every subroutine is tested (and can only do that on the end), well linked (removing the parameters) and creating other class's.
I need to finish the program at the end of the month (year).
Any help appreciated.
Luis Bras
|
|
|
|
|
Luís Brás wrote: I think have three alternatives, 1) run the exe and work with pipe's, 2) put everything in extern C code or 3) create a simple c++ class that have all the C subroutines.
It sounds like the only difference between your MFC code and your C code is that the C code has
no user interface.
Any of your three methods will work.
If you need the C code to run in a separate process (exe) then you'll need to go with method 1.
Having to communicate with another process adds a level of complexity, obviously.
If it's ok to have the C code linked to your MFC app then method 2 or 3 will work. The code
could be in a DLL or compiled right into your MFC app.
If you are developing your C code from the start (it hasn't already been written) then method 3 is
probably the way to go. It shouldn't take any longer than any other method - you still have to
write the code and check for errors at runtime as needed, regardless of which method you use.
There's no problem mixing C code with C++. You do it all the time using MFC and/or the C runtime
(CRT). Calling malloc is fine. Remember to free memory when you're done with it
|
|
|
|
|
I need to send a enter key stroke how can I do that? That I need to do is send a enter key stroke to the dialog but I dont now how so please help me.
|
|
|
|
|
http://www.codeproject.com/cpp/sendkeys_cpp_Article.asp
modified 8-Mar-17 3:51am.
|
|
|
|
|
Hey all,
I'm facing a small dilemma...
I'm currently coding a dll which will be used in one of my projects.
As I go further and further with the development of my dll, it becomes clearer that a specific coded dll would serve
me better as opposed to a general coded dll, when it comes to both performence and coding issues.
By specific coded dll I mean that I write my dll to be used only with my current project.
If I'll ever want to use it in another project, I'll have to make changes.
What should I do?
Which is a better programming practice?
Not really sure where to post this question...
Maybe I'll post it in another forum as well.
Thanks in advance,
Shy.
|
|
|
|
|
shyagam wrote: By specific coded dll I mean that I write my dll to be used only with my current project.
Why a DLL then?
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers! We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP Linkify!|Fold With Us!
|
|
|
|
|
I have to inject it to every running process...
|
|
|
|
|