|
I'm following you now
I've never used strings to name a resource so I was wondering how it's done LOL.
In the resource editor, if you put the ID in quotes it will be a string name. In that case you
should be able to pass the name like you did in your sample: _T("IDB_BITMAP")
Make sure that name isn't a #define in the resource header file (resource.h) or it will be
interpreted as the integer it's defined to
To be able to swap DLLs, your new DLLs will need to name the bitmaps the same.
Sorry for all the confusion!
Mark
"I'm the Dude. So that's what you call me. You know, that or, uh, His Dudeness, or uh, Duder, or El Duderino if you're not into the whole brevity thing." The Big Lebowski
|
|
|
|
|
lol... will that work??? sounds too easy to be right.... but i guess i'll find out.
|
|
|
|
|
sstainba wrote: will that work???
I tried it first LOL - like I said, I've always just used integers!
Mark
"I'm the Dude. So that's what you call me. You know, that or, uh, His Dudeness, or uh, Duder, or El Duderino if you're not into the whole brevity thing." The Big Lebowski
|
|
|
|
|
sstainba wrote: See, I've never done this before
That's why I'm trying to confuse you more! j/k
In the resource editor, when you add a bitmap and set its ID property to something like
IDB_BITMAP1 (or when the editor defines it for you), instead of using IDB_BITMAP1 as-is, it
adds a "#define IDB_BITMAP1 101" entry to resource.h. IDB_BITMAP1 is now a macro, not a string.
So if you try to load a resource using _T("IDB_BITMAP1") as the name, the resource isn't there
because the editor "helped" you by changing IDB_BITMAP1 to an integer.
Therefore, to use string names, when you add the resource, hit F4 to bring up the properties
page for the bitmap and edit the "ID" property to a string in double quotes.
I hope that is more understandable
Mark
"I'm the Dude. So that's what you call me. You know, that or, uh, His Dudeness, or uh, Duder, or El Duderino if you're not into the whole brevity thing." The Big Lebowski
|
|
|
|
|
Ok... that took me a step in the right direction. At least now FindResource is returning a non-NULL handle. I changed the name to include the quotes and it seems to be ok... But I still can't load it onto a button.
HINSTANCE mh = ::AfxLoadLibrary(_T("icons.dll"));
HINSTANCE mb = ::AfxFindResourceHandle(_T("IDB_BITMAP36"), RT_BITMAP);
Both of these return non-NULL handles... but I can't get it to work with LoadImage or LoadBitmap or just casting the mb as an HBITMAP.
I'm trying to set a bitmap field on a button... CButton::SetBitmap(HBITMAP)
Should I maybe use LoadLibrary and FindResource (non-Afx) ? I can't see that it would make a difference... but who knows.
|
|
|
|
|
I think you only need to use FindResource()/AfxFindResourceHandle for obtaining handles to binary
or custom resource types.
For bitmaps, you should use LoadImage(); That should work....are you sure you have the BS_BITMAP
style set on the button (if it's a button resource on a dialog, use F4 to get properties and set
the Bitmap property to true)?
I just tested this and it worked (note that I used ::GetModuleHandle(0) since the bitmap resource
is in my exe file):
HBITMAP hbitmap = (HBITMAP)::LoadImage(::GetModuleHandle(0), _T("MYBITMAP"), IMAGE_BITMAP, 0, 0, 0);
m_BitmapButton.SetBitmap(hbitmap);
"I'm the Dude. So that's what you call me. You know, that or, uh, His Dudeness, or uh, Duder, or El Duderino if you're not into the whole brevity thing." The Big Lebowski
|
|
|
|
|
Yeah, the button is set correctly. I can load it just fine as long as I include the header and use the int name. I just tried what you've got up there and it's a no go. LoadImage isn't returning a valid handle. Maybe it's because it is in a dll file and not the exe?
|
|
|
|
|
sstainba wrote: LoadImage isn't returning a valid handle.
Is LoadImage() returning NULL? If so, make sure IDB_BITMAP36 isn't defined anywhere else in the
project (most likely resource.h). A "Find in Files..." search in the DLL project for
"IDB_BITMAP36" should only find it once - in the .RC file.
If the name isn't the problem, and LoadImage() is returning NULL, then maybe check the error code
something like this...
HINSTANCE mh = ::AfxLoadLibrary(_T("icons.dll"));
HBITMAP hbitmap = (HBITMAP)::LoadImage(mh, _T("IDB_BITMAP36"), IMAGE_BITMAP, 0, 0, 0);
if (hbitmap)
{
m_BitmapButton.SetBitmap(hbitmap);
}
else
{
DWORD errcode = ::GetLastError();
}
"I'm the Dude. So that's what you call me. You know, that or, uh, His Dudeness, or uh, Duder, or El Duderino if you're not into the whole brevity thing." The Big Lebowski
|
|
|
|
|
sstainba wrote: I can load it just fine as long as I include the header and use the int name
I read that and apparently ignored it If that works then it's definitely the name -
Open the resource.h file in the DLL project and remove any #define entry for IDB_BITMAP36.
Since you're using strings, it may be helpful to use more descriptive names - there's no reason to
use the naming conventions that are assigned by the Visual Studio editing environment.
"I'm the Dude. So that's what you call me. You know, that or, uh, His Dudeness, or uh, Duder, or El Duderino if you're not into the whole brevity thing." The Big Lebowski
|
|
|
|
|
YAY!!!!! It worked. You rock. Hahaha... I tried asking this questiong on CodeGuru and this one guy was acting like I was an idiot for even thinking such a thing could be done. He said that the resource name wasn't stored in the dll file (WTF?). Anyway, thanks a lot!
PS. I don't suppose you know how to get a CToolTipCtrl to work do you? I followed the MSDN but it never shows up...
|
|
|
|
|
sstainba wrote: I tried asking this questiong on CodeGuru and this one guy was acting like I was an idiot for even thinking such a thing could be done.
Yeah - I was pretty much called stupid for asking a question on the Microsoft boards the
first time I went there. Geez, if you're tired of answering "stupid" questions then don't answer!
I personally believe the only stupid question is one that isn't asked (I don't know where I heard
that....maybe read it on a Starbucks cup or something )
sstainba wrote: He said that the resource name wasn't stored in the dll file (WTF?).
I wonder how he thought resources were located
sstainba wrote: PS. I don't suppose you know how to get a CToolTipCtrl to work do you? I followed the MSDN but it never shows up...
For a dialog window, right? I'll steal an example right from the MFC sample code:
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify)
...
EnableToolTips(TRUE);
...
afx_msg BOOL OnToolTipNotify(UINT id, NMHDR * pNotifyStruct, LRESULT * result);
...
BOOL CMyDlg::OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult)
{
TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
CStringA strTipText;
UINT nID = pNMHDR->idFrom;
if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
{
nID = ::GetDlgCtrlID((HWND)nID);
}
if (nID != 0)
strTipText.Format("Control ID = %d", nID);
if (pNMHDR->code == TTN_NEEDTEXTA)
strncpy(pTTTA->szText, strTipText, sizeof(pTTTA->szText));
else
::MultiByteToWideChar( CP_ACP , 0, strTipText, -1, pTTTW->szText, sizeof(pTTTW->szText) );
*pResult = 0;
return TRUE;
}
Note that this just shows a normal tooltip with text "Control ID = xxxx". You'd probably want to
map the control ID to a meaningful string.
Cheers
Mark
"I'm the Dude. So that's what you call me. You know, that or, uh, His Dudeness, or uh, Duder, or El Duderino if you're not into the whole brevity thing." The Big Lebowski
|
|
|
|
|
I forgot to mention....
if you choose to implement tooltips like that sample code, the strings you use can be loaded
from a stringtable resource, and the stringtable can be in your resource DLL.
The TOOLTIPTEXT structs have a hinst member to specify the HINSTANCE of the DLL.
If you choose to use stringtable resources for the strings, then lpszText should be set to the
ID of the string resource and the hinst member set to the instance of the module (EXE or DLL)
that contains the resource, something like:
// get string 32777 from this EXE's resources
pTTTW->hinst = ::GetModuleHandle(0);
pTTTW->lpszText = (LPWSTR)32777;
Mark
"I'm the Dude. So that's what you call me. You know, that or, uh, His Dudeness, or uh, Duder, or El Duderino if you're not into the whole brevity thing." The Big Lebowski
|
|
|
|
|
Actually, I got it working. Used a CToolTipCtrl. haha. Thanks for the info anyway.
|
|
|
|
|
Cool!
"I'm the Dude. So that's what you call me. You know, that or, uh, His Dudeness, or uh, Duder, or El Duderino if you're not into the whole brevity thing." The Big Lebowski
|
|
|
|
|
Hi I am currently using servel pins (CTS and RTS) of my serial port for data transfer with a program I wrote in Visual C++ 2005 under Windows XP.
I would like to write a program to send data over the unused pins.
Is it possible to write to individual pins (independently) using Visual C++? How is this done because I am stumped?
|
|
|
|
|
I am a newby so forgive me if I have misunderstood your question and this answer is no help at all.
I just wrote an app that uses pins individually on the serial port. and the code looks like this.
HANDLE hCom;
DCB dcb;
//Create the handle for the comport.
hCom = CreateFileA("COM1", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
if(hCom == INVALID_HANDLE_VALUE)
{
CloseHandle(hCom);
MessageBox("There are no ports avaiable. You may neeed to configure a port");
}
// Get the state of the comport and fills the dcb structure.
GetCommState(hCom, &dcb);
//You can use the following to set pins how you like.
dcb.fRtsControl = RTS_CONTROL_DISABLE; // These are outputs can be set either high or low.
dcb.fDtrControl = DTR_CONTROL_DISABLE;
// Sets the port.
SetCommState(hCom, &dcb);
I hope this helps. If not sorry to waiste your time.
I believe you would have to use WriteFile(); to send real data.
|
|
|
|
|
Hi all, im trying to do the following:
Print a string of chars to a buffer, and print from the buffer using the sockets send() function. So far i havnt found a way.
The function in question:
<br />
bool TextSender(const char* Text)<br />
{<br />
if(send(dataSock, Text, strlen(Text), 0) == -1)<br />
return false;<br />
else<br />
return true;<br />
}<br />
I was wondering if i printed information to either dataSock or Text it would work, but it does nothing.
Does it matter if i define char Text; at the top ? Because its not doing a thing, any suggestions? Thanx in advance!
|
|
|
|
|
So if send() is failing, why are you not calling WSAGetLastError() to figure out why?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Can you give me an example DavidCrow on how to call it properly please? Thanx.
|
|
|
|
|
bool TextSender( const char* Text )
{
if (send(dataSock, Text, strlen(Text), 0) == SOCKET_ERROR)
{
DWORD dwError = WSAGetLastError();
return false;
}
else
return true;
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
in hash tables every index in the table refers to a linked list which have slots, each slot have key, data, next, how to insert the data from a text file or html file that we have as every data in each slot is a certain line in the file (text or html), & the key is the no. of that line.
|
|
|
|
|
Hi,
I come from a MainFrame Background I haven't gotten into the OO way of thinking
My application which I have created a class for, for Argument sake I'll call MyClass
could use help from 2 other classes (one to check if something is a valid Hex sting and another if it is to convert that string to a Hex number
)
my question is how would I code that
Class MyClass : public Classa : public Classb
{
if so which is the base and which is derived ?
Do I have to worry about the constructers of all 3 ??
and can myClass get at the protected members of classb and CLassa
Thank ahead of time
to all you C++ experts
Which I hope to become one day
|
|
|
|
|
In OO programming I think in terms of "is a" and "has a". "is a" means it IS a class while
"has a" refers to something that should be a member of a class.
While your method will work, it does't necessarily make sense.
To make it more clear, I'll give your classes appropriate names:
class ValidHexStringChecker;
class StringToHexConverter;
Class MyClass : public ValidHexStringChecker, public StringToHexConverter
{
};
ValidHexStringChecker and StringToHexConverter are base classes.
MyClass is a derived class, derived from both base classes.
MyClass IS A ValidHexStringChecker and it also IS A StringToHexConverter.
Unless MyClass encapsulates a string, it doesn't make sense for it to be a converter and checker.
It could HAVE ("has a") methods to do those operations but to actually BE an object that does
those doesn't make sense.
Using "is a/has a", I'd ask myself - IS Myclass a ValidHexStringChecker/StringToHexConverter?
If not, then revert to "has a", and add methods to do those operations, something like:
Class MyClass
{
public: //or protected or private
bool CheckValidHexString(...);
bool ConvertStringToHex(...);
};
ForNow wrote: Do I have to worry about the constructers of all 3 ??
If the base classes need construction with constructors that take passed parameters, then yes.
If the base classes have default constructors, and that's the only constructor needed, then no.
ForNow wrote: and can myClass get at the protected members of classb and CLassa
Yes, because you've specified public access to the base classes (see Controlling Access to
Class Members[^]).
I hope at least a little of that made sense
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
While OO is neat and useful, don't let it over-complicate things (e.g., not everything has to be a class just because C++ is being used). Unless you can actually think of your "something" as an object (which you probably could), why not just make "is a valid Hex sting" and "convert that string to a Hex" into just plain functions? The former could easily be done with strtol() .
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I was thinking - atoi - However I really realy want to learn C++
If you have any suggestions please let me know
thankx
|
|
|
|
|