|
Hi.
I am creating a MFC DLL using MFC as statically linked. It is basically a dialog based app, except I'm creating it as a DLL.
I am doing this in Studio 2005.
It has one dialog, with Ok,Cancel buttons and one CEdit box.
When I try to use AfxMessageBox( ),
AfxMessageBox("I am about to create/instantiate MyLilDllDlg dialog", MB_ICONWARNING, NULL);
I get compiler error as follows:
1>c:\temp\dll\mylildll\mylildll\mylildlldlg.cpp(40) : error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types
1> c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(5031): could be 'int AfxMessageBox(LPCTSTR,UINT,UINT)'
1> c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(5033): or 'int AfxMessageBox(UINT,UINT,UINT)'
1> while trying to match the argument list '(const char [52], long, int)'
Is there something I need to include or configure in my project settings to allow me to use Afx... ?
Thank you.
|
|
|
|
|
The third argument must be 0, not NULL, to make it a UINT value. The compiler error returned means that none of the two overloaded argument types (either LPCTSTR, UINT, UINT or UINT, UINT, UINT ) were found in your execution of the AfxMessageBox() function as NULL is not a legal UINT value.
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
First off, thanks! Embarrasedly I should have looked closer at what the suggestion in the compiler was saying.
I settled on the following:
AfxMessageBox(LPCTSTR("I am about to create/instantiate MyLilDllDlg dialog"), MB_ICONWARNING, 0);
It needs the casting to LPCTSTR. I got by with last arg being NULL.
Thanks for telling me what I was doing wrong. Without that, I would have not tried to find out more about it on my own.
Johnny
|
|
|
|
|
hi,
I'm just a beginner at programming(c++) and I wanted to create a program to do binomial expansions easily,
I have created the program and it works well. But because i'm a beginner at programming i'm using a win32 console for the program and i want to show powers, squares and cubes, which in the output of my program look like this:
2^3
0r
4^2
is there any way to show them as you would write them, like in superscript or something cos at the moment it looks a mess.
Hope you understand my problem.
Any answers appreciated
ps if you have any recomendations on C++ books which include how to use windows forms to create a program they would be appreciated
|
|
|
|
|
toprogramminguy wrote: is there any way to show them as you would write them, like in superscript...
Yes, but the exponent would be a whole line above the base.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
exponents of 2 and 3 have their own symbols in unicode. You will have to stick with x^4 for exponents of 4 (and 5, etc), but they're definitely there for 2 and 3. You will need to compile for unicode in order to use these characters. You can compile for Unicode by defining the symbols UNICODE and _UNICODE in your compiler definitions.
If you go into character map and search for "superscript" then you will get 5 results, four of which may be helpful to you. Those are the characters you need to use.
http://img122.imageshack.us/my.php?image=superscriptja8.jpg[^]
|
|
|
|
|
Hey.Guys!
I've been puzzled by this kind problem these days while doing with CTreeCtrl. My target is going to Dynamically insert any number of child items into an Empty Item by clicking + button. To do that,i have to force the control to display the + even though the item does not have any child items inserted.
i followed the instructions from msdn by setting cChildren of TVITEM struct to I_CHILDRENCALLBACK since the ctreectrl has the TVS_HASBUTTONS style. then handle with TVN_GETDISPINFO notification message. but that does not work anyway:
void CMutiTreeCtrl::OnTvnGetdispinfo(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTVDISPINFO pTVDispInfo = reinterpret_cast <lpnmtvdispinfo>(pNMHDR);
if((pTVDispInfo->item.mask & TVIF_CHILDREN ) == 0)
{
HTREEITEM hSelected = GetSelectedItem();
TV_INSERTSTRUCT tvinsert;
tvinsert.hParent=hSelected;
tvinsert.hInsertAfter=TVI_LAST;
tvinsert.item.mask=TVIF_TEXT;
tvinsert.item.hItem=NULL;
tvinsert.item.cchTextMax=50;
tvinsert.item.lParam=0;
tvinsert.item.pszText=_T("inserting child items only when the item is visible or expanded");
*pResult = 1;
}
else *pResult =0;
}
Is there any problem with the code?Any suggestion?Thanks
HALLELUJAH! Hallelujah! Hallelujah! Hallelujah!
|
|
|
|
|
KmLee David wrote: My target is going to Dynamically insert any number of child items into an Empty Item by clicking + button.
Rather than clicking the item itself?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
just insert child items while expanding the empty item to display these child items, maybe double click the item or click the + .any way u wish.
the most important thing is how to handle with the TVN_DISPINFO notify message to achieve my purpose
HALLELUJAH! Hallelujah! Hallelujah! Hallelujah!
|
|
|
|
|
KmLee David wrote: Is there any problem with the code?
Yes.
TVN_GETDISPINFO
"Requests that a tree-view control's parent window
provide information needed to display or sort an item."
You shouldn't be inserting items in response to this notification.
You also shouldn't be calling GetSelectedItem().
The TVN_ITEMEXPANDING notification is maybe a better place to insert
the child items.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: TVN_GETDISPINFO
"Requests that a tree-view control's parent window
provide information needed to display or sort an item."
You shouldn't be inserting items in response to this notification.
You also shouldn't be calling GetSelectedItem().
The TVN_ITEMEXPANDING notification is maybe a better place to insert
the child items.
Thanks a lot,finally i've figure out the problem. Here is my solution
void CMutiTreeCtrl::PopulateTree()
{
TV_INSERTSTRUCT itInsert = {0};
CString strText;
strText = _T("Start");
itInsert.item.pszText = const_cast<LPTSTR>((LPCTSTR)strText);
itInsert.item.state = TVIS_BOLD;
itInsert.item.mask = TVIF_CHILDREN | TVIF_HANDLE | TVIF_TEXT |
TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
itInsert.item.stateMask = TVIS_BOLD | TVIS_STATEIMAGEMASK;
itInsert.item.cChildren = I_CHILDRENCALLBACK;
itInsert.hParent = hRoot;
HTREEITEM hItem = this->InsertItem(&itInsert);
UpdateWindow();
}
void CMutiTreeCtrl::OnTvnItemexpanding(NMHDR *pNMHDR, LRESULT *pResult)
{
CWaitCursor curWait;
SetRedraw(FALSE);
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
HTREEITEM hItem = pNMTreeView->itemNew.hItem;
HTREEITEM hRemove = this->GetChildItem(hItem);
while(hRemove)
{
ctlTree.DeleteItem(hRemove);
hRemove = this->GetChildItem(hItem);
}
CString strText = _T("This is the Child Item which is dynamiclly inserted");
AddMySubItems(hItem, strText);
SetRedraw(TRUE);
Invalidate();
*pResult = 0;
}
void CMutiTreeCtrl::OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult)
{
TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
pTVDispInfo->item.cChildren = 1;
*pResult = 0;
}
HALLELUJAH! Hallelujah! Hallelujah! Hallelujah!
|
|
|
|
|
Hello,
I am writing a BlackJack type program to learn C++/.NET. I'm, trying to raise an event from Shoe Class (DealtCutCard Event) which is used by Dealer Class. Dealer sets a flag and at the apprpriate time raises a DealerShuffles Event which the Shoe Class uses.
This code won't compile, the error is in the Shoe.h:
"improper syntax for specifying event in __hook/__unhook" line 25
"improper syntax for specifying event in __hook/__unhook" line 25
"improper syntax for specifying event in __hook/__unhook" line 25
If I comment out #include "Dealer.h" and the __hook init function this will compile, but now I can only raise events from Shoe it won't recieve events from Dealer.
How can I both call and handle events from between the same two classes?
BTW - note i NEED "Shoe.h" in Dealer because there are functions in Dealer that reference Shoes.
Using .NET 2003
Also, I tried substituting #include "Dealer.h" with class Dealer; as a predeclaration but that didn't work.
Dealer.h
#pragma once
#include "Bettor.h"
#include "Hand.h"
#include "Shoe.h"
#ifndef DEALER_H
# define DEALER_H
[event_source(native)]
[event_receiver(native)]
class Dealer
{
public:
__event void DealerShuffles(void);
Dealer(Shoe*);
void InitShoeEvents(Shoe* pSource){
__hook(&Shoe::DealtCutCard, pSource, &Dealer::ReadyToDeal);};
};
#endif
Shoe.h
#pragma once
#ifndef SHOE_H
# define SHOE_H
#include "Dealer.h"
[event_receiver(native)]
[event_source(native)]
class Shoe
{
public:
void Shuffle(void);
void InitDealEvents(Dealer* pSource){
__hook(&Dealer::DealerShuffles, pSource, &Shoe::Shuffle);};
__event void DealtCutCard(void);
};
#endif
|
|
|
|
|
I'm currently coding a server and accepting incoming connections using the CAsyncSocket class under Vista.
Things are working fine but now I would like to be able to resolve the dotted IP address CAsyncSocket::GetPeerName() returns into a nice human readable name so users can easily identify connections rather than remembering strings of numbers (dotted ip's). Can someone point me to the API which will help me do that. Spent a while searching but everything talks about going the other way, that is name->dotted ip, not dotted ip->name.
Thanks!
|
|
|
|
|
jbem wrote: ...I would like to be able to resolve the dotted IP address CAsyncSocket::GetPeerName() returns into a nice human readable name...
Which of the two GetPeerName() methods are you using? Have you tried gethostbyaddr() ?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Thanks I missed the gethostbyaddr(). I used getnameinfo() since gethostbyaddr is deprecated and it worked out fine. Thanks for your help!
|
|
|
|
|
hi to all
i want to store some string datas in a CString or similar variable
and i need a int variable also
this is a global hook dll and i want to update this variables at runtime
and all applications should access to this variables which load this dll
simly : i can say this dll will be a bridge between applications
which load this dll
i have found the following sample but i could not
write a working one from it
application exits with crash always
note: the following sample copied from a C project
and my dll is a MFC/C++ dll
thank you
#pragma data_seg(".shared")
#pragma comment(linker, "/section:.shared,rws")
HHOOK g_hHook = 0;
HWND g_hwndNotify = 0;
BOOL g_FirstInstance = FALSE;
UINT g_nButtonCmdId[MAX_TITLE_BUTTONS] = { 0 };
UINT g_nButtonResId[MAX_TITLE_BUTTONS] = { 0 };
int g_nButtonCount = 0;
WCHAR g_szBlackList[MAX_BLACKLIST][64] = { 1 };
LONG g_nBlackListLen = 0;
#pragma data_seg()
|
|
|
|
|
I have code which worked under VC6 and now failing under VS2005 (additional change was moving portions to a dll from a lib, but pretty sure this not affecting things)
I have an out-of-process COM server, which constructs a CWnd in the constructor of the CComCoClass templated object. The intent is for this CWnd to receive messages posted from a thread (created in a linked dll) to track external state. (why is it a CWnd? because the primary recipient of the dll's state messages is a windows app)
The CWnd seems to construct fine, but the thread goes quiescent. I don't think that the thread has a message loop.
Question: how to I get the CWnd into a messagepump? a) Can I change the CWnd creation? b) Can I force the linkage of the Cwnd into the PreTranslate tree? c) Do I have to punt the CWnd and go to a GUI thread (which seems to be effectively duplicating much of what just creating a CWnd should do for me, and forces me to add to the dll a parallel notification list)?
Messages sent from the posting dll thread can be received at the COM object's message loop (via PostThreadMessage), so I'm confident the switch from VC6 to VS2005 is the culprit not the change from LIB to DLL, especially since PostMessage works in the primary application.
class ATL_NO_VTABLE CServer:
public CComObjectRootEx<ccomsinglethreadmodel>,
public CComCoClass<cserver,>,
public IDispatchImpl<iserver,>
{
...
class wndHook : public CWnd{
public:
wndHook(){}
afx_msg LPARAM Message(WPARAM, LPARAM);
DECLARE_MESSAGE_MAP()
}*pWnd;
}
CServer::CServer(){
...
pWnd = new wndHook();
if (!pWnd->CreateEx(0, NULL, _T("HOOK"), WS_CHILD,
CRect(0,0,0,0), CWnd::GetDesktopWindow(), 0, NULL)){
TRACE0("Failed to create hook window\n");
}
GetDLL()->AddToNotificationList(ENUM_VAL, pWnd);
}
BEGIN_MESSAGE_MAP(CServer::wndHook, CWnd)
ON_MESSAGE(WM_APP, CServer::wndHook::Message)
END_MESSAGE_MAP()
void DLL::Post(WORD mID, long val)
{
...
::PostMessage([element in list]->GetSafeHwnd(), WM_APP, mID, val);
}</ccomsinglethreadmodel>
|
|
|
|
|
|
First of all, this sounds like a Design and Architecture question so the VC++/MFC forum probably isn't the best place to get the answer you require.
Second of all, what I suggest is that you load the ActiveX controls as they are needed, as as you state it could all become a big mess, and this will significantly help performance when the control needs to be loaded.
As you have 20 of these controls then this sounds like a pretty good model, however have you taken the client's screen resolution into account? It depends on the size of the controls, but if you plan to place 10 of these on the screen in two rows then the page may not display as you want it to.
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
Thanks, PerspX, for your prompt reply and comments/suggestion. I'm moving from here. I did remove the message but i guess I can't remove the entire thread...
|
|
|
|
|
Regarding design - layout, have you considered grouping the controls and putting individual groups on Tab-ed pages (CPropertySheet/CPropertyPage)?
Regarding usage/active controls - as a suggestion, you might want a common look for all "screens" by having individual controls occupy same position per each "screen". You can assign variables to the controls, access the position of the controls (with CRect() and ClientToScreen() type functions), and then swap/enable/show controls using these reference points.
I recently used a collapse/expand class that I got from CP - it is rather slick and uses reference points on a dialog to show only upper/full dialog dimensions when needed (Michael Walz, Expanding and Collapsing dialogs)
|
|
|
|
|
Thanks very much for your detailed reply, john. I can't use tabbed pages because, you see, I'm simulating a control panel for a small factory with LED's, switches, etc, plus some custom controls so I need to offer the whole view to the user.
It's a clever idea that you've given, proposing to use the same dialog boxes but swapping controls. But, unfortunately, the layout of the main screen is such that it's not possible to have a common look for all the smaller screens. I'm stuck with having ten different dialog boxes.
My next question is, how can I be notified of mouse pointer position and state of the mouse buttons when moving on a bitmap? All I want to do is to highlight the square which the mouse is currently in, and be notified when and where the user clicks.
[SOLVED] Got my answer from another thread... Visual C++ ain't that hard folks
Thanks again,
Henry.
|
|
|
|
|
in C++ if i have the following string literal:
"Hello"
The compiler represents this as
{'H', 'e', 'l', 'l', 'o', '\0'}
If I were to expand that out to wide chars, for the special case of a string literal in code, I do not need to call MultiByteToWideChar do I? I can just insert 0s to fill in the gap, so "Hello" becomes:
{'H', '\0', 'e', '\0', 'l', '\0', 'l', '\0', 'o', '\0', '\0', '\0'}
I ask this because with Visual C++ wchar_t is always (so far as I know) a 16bit character, which works very nicely with the rest of the OS since it's Unicode support is built with 16bit code points/characters. On other systems (specifically unix based ones) wchar_t is frequently a 32 bit value which is NOT what I want when dealing with string support. This causes translation issues when you write L"Hello" on those systems, and if you simply leave it as "Hello" (ansi), then the string thinks it needs to translate from ascii to unicode, which is big performance hit. So for string literals I thought I might make a simple class that just expands the ansi string literal to a 16 bit version. Something like :
String s = SL("Hello");
Where String is a unicode UTF16 based string class, and "SL" is a StringLiteral class that just expands out the string literal.
Does this make any sense, or have I twisted my head into a moebius strip over nothing?
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
VCF Blog
|
|
|
|
|
Yeah, if the compiler has no built-in way of representing a string of 16-bit quantities, then you'd need a class to handle that conversion for you.
You could also do:
unsigned char str[] = {'H', '\0', 'e', '\0', 'l', '\0', 'l', '\0', 'o', '\0', '\0', '\0'}; but that's a whole lot of typing and the SL("hello") version is far easier to read.
|
|
|
|
|
|