|
> So, there's no point in double buffering in OnDraw?? What I've
> done so far is to use memDC to do rendering then BitBlt to pDC,
> and also override WM_ERASEBKGRND to prevent erasure of background
I'd say this is the right way. I'm using it without any problems. Do you have any special requirements?
OnPaint without overriden OnEraseBkgnd will cause flicker - moving CPaintDC will only reduce the effect.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Hi,
while creating a DLL, When I was trying to put some dialog boxes and compile it, I got an error "Unidentified identifier IDD_DIALOG".
My question is that how can i pack resources in a DLL using MFC?
|
|
|
|
|
Partial answer to a tough question (and I'm stretching my knowledge here) but I think the app invoking the DLL needs to know about the resource template for the dialog as well as the resource defines. You will need to include a resource header that defines IDD_DIALOG, and also the .rc file that contains the dialog template.
As a simple test, I made a test DLL that exported a fn that invoked a dialog (as opposed to exporting a CDialog based class) and had no success showing it until I added the .rc file for the DLL into the apps Resource Includes (on the View menu).
I don't think this is very robust though, as resource ID conflicts are bound to occur in a large project - you might want to be careful about the 'exported' ids. I think the idea is to use at least 2 .rc files on the DLL side. One that can be included by consumer apps that has stuff they need, and one to hold DLL internal version info etc.
MFC has several .rc files that are included by standard apps depending on what resouces (e.g. font dilaog) they need. I think there is an advantage here in that you can override templates in your app to customize common dialogs etc. Not something I do everyday.
|
|
|
|
|
I have a problem regarding char*'s and character arrays....
Firstly to use strcat it seems I have to use a character array:
char ret[64] = "";
If I use a char* as the strcat argument it just doesnt like it!
But the function needs to return a char*. If I do;
return ret; (as declared above)
then I get an error (returning address of local variable).
I tried to get around this by doing:
char ret[64] = "";
char* tmp;
tmp = &ret[0];
This seemed to work fine, it passes the pointer, but when I try and cout
the value (ie cout << returnedValue; ) in my main function it just outputs
a load of garbage. I checked that the pointer is pointing to the right thing
before returning it and it is, so Im just thinking the area of memory could be
messed up in that short space of time...I have attatched the code in case im not
being clear!
Thanks
Any help appreciated
Code:
char* TicTacToe::formatForPrinting() {
char ret[32] = "";
for ( int rows = 0; rows < BOARD_SIZE; rows++ ) {
for ( int cols = 0; cols < BOARD_SIZE; cols++ ) {
if( gameBoard.position[rows][cols] == 1 ) {
strcat(ret,"X");
strcat(ret," ");
}
else if ( gameBoard.position[rows][cols] == 2 ) {
strcat(ret,"O");
strcat(ret," ");
}
else if ( gameBoard.position[rows][cols] == 0 ) {
strcat(ret,"-");
strcat(ret," ");
}
}
strcat(ret,"\n");
}
char* tmp;
tmp = &ret;
return tmp;
}
int main() {
// Create game object
TicTacToe* game = new TicTacToe;
char* b;
cout << "You are X, the board is currently:\n";
b = game->formatForPrinting();
cout << b << "\n";
return 0;
}
|
|
|
|
|
You are not allocating memory on the heap for the object. The memory you are trying to use is in the local stack defined for the block you are in for that function call. Either dynamically allocate memory for the array, or better, define your char array on the call side, and pass it in to the formatForPrinting call. BTW, why aren't you using CString - it handles all that for you?
|
|
|
|
|
I tried:
char* ret = new char[32];
i presume this is what you mean by dynamically allocating memory.... This results in a load of junk in the array elements which arent used, presuambly because its not initialised. Although it does pass the right thing back as well.
Is it the done thing to allocate the memory on the call side then? I guess thats a better way of doing things..
I might start using CStrings. I have tried to avoid them so I wont have any problems if I go to another platofrm (arent CString just VC++).... I also thought in the long run it might be better if I had the increased control, do you disagree with this?? Im begining to think its more trouble than its worth...
Thanks for your help
Ben
|
|
|
|
|
Well, if you don't like the garbage in it, you can always fix that with ZeroMemory, or memset. As to the your other concern, I think that if you want to do all of your own string type operations without help from MFC, you would be well advised to either, preferably, use the STL string class, or, cook up your own well defined string class. Not wanting to be enslaved to MFC is understandable, but you should be sure that you really need to go to the extra effort of not making it dependent on MFC. Otherwise, you are just makeing extra work for yourself for no good reason.
|
|
|
|
|
If portability is a concern, then use std::string from the STL.
But I think that's just avoiding the issue, which is you just don't understand pointers and memory management yet. (That's not a knock on you; it is a tough subject.) Eventually, if you program C/C++, you will have to use them and understand them.
--Mike--
http://home.inreach.com/mdunn/
#include "buffy_sig"
|
|
|
|
|
Hello, the codegurus around the world.;)
I guess that one mistake is
char* b;
b = game->formatForPrinting()
should be
string.h
.....
int len = strlen (game->formatForPrinting);
char *b = new char[len + 1];
strcpy (b, game->formatForPrinting);
However, I didn't check this at my code, so...
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
Hi all,
I want to know what is best way to appending text in last of editbox ?
m_Edit1.GetWindowText(pString, 50);
strcpy(pAll, pString);
m_Edit1.SetWindowText(pAll);
do you have better idea ???
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Hello, the codegurus around the world.;)
CString sBaseString, sNewString(" This is the text appended!");
m_Edit1.GetWindowText(sBaseString);
sBaseString += sNewString;
m_Edit1.SetWindowText(sBaseString);
or
UpdateData(FALSE);
sBaseString = m_strEdit1;
sBaseString += sNewString;
m_strEdit1 = sBaseString;
UpdateData(TRUE);
However, I didn't check this at my code, so...
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
Hi,
can you write it by using of LPSTR instead CString ?
Thanks ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Hello, the codegurus around the world.;)
I will give you some references.
WINUSERAPI
int
WINAPI
GetWindowTextA(
HWND hWnd,
LPSTR lpString,
int nMaxCount);
WINUSERAPI
int
WINAPI
GetWindowTextW(
HWND hWnd,
LPWSTR lpString,
int nMaxCount);
#ifdef UNICODE
#define GetWindowText GetWindowTextW
#else
#define GetWindowText GetWindowTextA
#endif // !UNICODE
<br>
typedef LPSTR LPTCH, PTCH;
typedef LPSTR PTSTR, LPTSTR;
typedef LPCSTR LPCTSTR;
typedef CHAR *LPSTR, *PSTR;
Other hint is to search "Data type" of Platform SDK: Win32 API of MSDN help.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
How can i monitor the time that the connection is taking, meaning that if i have opened a connection to the net and i want to timelimit it lets say for 5 minu. how can i do it?
thanks,
|
|
|
|
|
kick off a timer and kill the connection when it expires?
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
Hello, the codegurus around the world.;)
Lauren:
How do we kill the connection of Internet?
DUN, LAN, Cable Modem, xDSL, Wireless DSL?
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
How can i catch the event of click "Enter" Button when the focus is on the ComboBox.
When i click now the "Enter" button the "OK" button is catching the event.
|
|
|
|
|
The most straight forward way is to just modify your dialog's OnOK handler to check if your ComboBox has the focus. If it does, just drop out of the OnOK without doing the EndDialog call.
|
|
|
|
|
This is not correct because when i do that the focus is always on the Dialog window even if the focus was on the combo.
|
|
|
|
|
How are you trying to determine the focus window?
|
|
|
|
|
With the funciton GetFocus()...
|
|
|
|
|
Sorry, I forgot how wacky the combo box is. I beleive the problem is that the CComboBox itself does not have the focus, the edit portion of it does, which is a separate window from the control itself. Thats what you need to be checking the focus for. I forget now how to get a pointer to the edit portion of the combo, but I think if you check around you will find how to get it.
|
|
|
|
|
|
See if this works (it did for me)
void CMyDialog::OnOK()
{
if( GetFocus() == m_Combo.GetDlgItem( 1001 ))
{
// Do combo stuff
return;
}
}
1001 is the id of the CEdit portion of the CComboBox.
|
|
|
|
|
Hello, the codegurus around the world.;)
Which situation do you want to work?
EditBox of ComboBox has the input fouce?
Or List of ComboBox is expaned and some item is selected?
when you push Enter key?
Have a nice day!
-Masaaki Onishi-
|
|
|
|