|
I am writing a dilaogue based application where a memory bitmap is created and the OnPaint method does a BitBlt to the dialogue.
I can get it to work by doing an initial BitBlt at the end of the OnCreateBmp() method but I would rather trigger OnPaint() so there is no duplicate code. Several attempts at invalidating the client area haven't worked.
Any suggestions?
Elaine
OnCreateBmp()
{
...
pDC = this->GetDC();
m_MemBmp.CreateCompatibleBitmap(pDC,
m_ClientRect.Width(),
m_ClientRect.Width());
m_MemDC.SetTextColor(0xff00);
m_MemDC.TextOutA(33, 33, "Hello world");
}
bmp1Dlg::OnPaint()
{
...
pDC->BitBlt(m_ClientRect.left, m_ClientRect.top,
m_ClientRect.Width(),m_ClientRect.Height() ,&m_MemDC,0,0,SRCCOPY);
CDialog::OnPaint();
...
}
The tigress is here
|
|
|
|
|
call invalidaterect at then end of the OnCreateBmp
-prakash
|
|
|
|
|
That was my first attempt as the last line in OnCreateBitmap:
InvalidateRect(m_ClientRect, TRUE); but it makes no difference.
The tigress is here
|
|
|
|
|
try InvalidateRect(NULL, TRUE);
-prakash
|
|
|
|
|
From where does OnCreateBmp get called? Maybe it's called before GetClientRect can actually get the size of the client rectangle?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
OnCreateBmp is a button event and m_ClientRect is set up within OnCreateBmp.
As I said if I put a copy of the BitBlt at the end of OnCreateBmp everything is fine, I am simply trying to get the OnPaint to happen and avoid duplicating code.
The tigress is here
|
|
|
|
|
Are you pumping your message queue? For the invalidate to work, the message queue must be pumped which will result in the delivery of the WM_PAINT message.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
This would explain what is happening, could you explain in a little more detail please?
Elaine
The tigress is here
|
|
|
|
|
I guess InvalidateRect posts the wm_paint message and the message is pumped by the mfc framework.
-prakash
|
|
|
|
|
Just curious, but what is being drawn in OnPaint()?
The problem is I see you creating a compaltible bitmap, but I do not see you selecting that bitmap into m_MemDC (before drawing to m_MemDC). If that is the case, then you are not drawing on the compatible bitmap. You would be drawing on the default bitmap which is monochrome, supporting black and white only.
INTP
Every thing is relative...
|
|
|
|
|
hello everyone,
i have a simple inheritence question for anybody knows...
let's take an example. I have the following class definition :
class CVCalcParserException {
protected:
int m_iExceptionNumber;
std::string m_strExceptionMsg;
int m_iErrorPos;
public:
CVCalcParserException(int iExceptionNumber,
const std::string& strExceptionMsg,
int iErrorPos);
virtual ~CVCalcParserException();
int GetExceptionNumber();
std::string GetMessage();
int GetErrorPos();
};
In the current state of my class, people could be able to create an instance of it, but I'd like to forbbid this as CVCalcParserException .is supposed to provide some services to the derived classes.
How could i set this class abstract ? the getter functions are not to be overloaded so i cannot put them as pure virtual functions (using =0).
any idea ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Declare the constructor as protected.
class CVCalcParserException {
...
protected:
CVCalcParserException(int iExceptionNumber,
const std::string& strExceptionMsg,
int iErrorPos);
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
S. Senthil Kumar wrote: Declare the constructor as protected
hum, yeah, i thought to this, but wasn't sure...
thank you
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
tell me one more thing, i explicitely define only one constructor with parameters, so, the compiler implicitely defines a default constructor without parameters.
should i also explicitely define this constructor protected ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote: i explicitely define only one constructor with parameters, so, the compiler implicitely defines a default constructor without parameters.
It doesn't. Explicitly defining a constructor suppresses generation of the compiler generated one, so no, you don't need to define the parameterless constructor.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
|
How about making the constructor protected.
If you do that it will be accessed only in derived class.
Note: I never tried to do so. Why do you try and let me know too.
Regards
|
|
|
|
|
Let me confess that I am fresher in network programming can any one help me???
I made very simple server using IOCP but my server is unable to receive all the message. Here is code for my server
#include "stdafx.h"
//#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include "winsock2.h"
#include "fstream"
#include "conio.h"
#include "stdio.h"
#pragma comment(lib,"ws2_32.lib")
/*--- MACRO Defination --*/
#define SERVER_PORT htons(8888)
#define DATA_BUFSIZE 4096
#define OP_READ 0
#define OP_WRITE 1
#define OP_ACCEPT 2
/* OverlapPlus Data Used to store Ovelap info and other information need to user*/
typedef struct _OVERLAPPEDPLUS
{
OVERLAPPED Overlapped;
SOCKET sServer,sClient;
int nOperationCode;
WSABUF wbuf;
DWORD dwBytes,dwFlags;
SOCKADDR_STORAGE ClientAddr;
int nClientNumber;
}OVERLAPPEDPLUS, * LP_OVERLAP_PLUS;
void Initialize();
DWORD WINAPI ServerWorkerThread(LPVOID lpParam);
FILE *stream;
void appendLog(TCHAR* strMessage)
{
stream = _wfopen( _T("c:\\iServer.log"), _T("a") );
fputws(_T("\n"),stream);
fputws(strMessage,stream);
fclose( stream );
}
int main()
{
WSADATA wsd;
SYSTEM_INFO SystemInfo;
SOCKADDR_IN InternetAddr;
SOCKET sListen;
HANDLE hIocp;
int nClientInc = 1;
/* Initialize Winsock2 */
Initialize();
/*--- Create an I/O completion port ---*/
hIocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, (ULONG_PTR)0, 0);
if(NULL == hIocp)
{
printf("Error in initialization of Completion Port! Press any to exit...");
return -1;
}
/* Determine how many processors are on the system, For thead optimization */
GetSystemInfo(&SystemInfo);
/*--- Create worker threads based on the number of processors available on the system ---*/
for(int nProcessor = 0; nProcessor < (int) SystemInfo.dwNumberOfProcessors; nProcessor++)
{
HANDLE ThreadHandle;
ThreadHandle = CreateThread(NULL, 0,ServerWorkerThread, hIocp,0, NULL);
//CloseHandle(ThreadHandle); // Why We close thread Handle ?????
}
/*--- Create a listening socket --- */
sListen = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0,WSA_FLAG_OVERLAPPED);
/*--- Fill TCP Header Info for bind a socket ---*/
InternetAddr.sin_family = AF_INET;
InternetAddr.sin_addr.s_addr = htonl(INADDR_ANY);
InternetAddr.sin_port = SERVER_PORT;
/*-- Bind the socket with port --*/
bind(sListen, (PSOCKADDR) &InternetAddr, sizeof(InternetAddr));
/*--- Prepare socket for listening mode and Start the Server ---*/
listen(sListen, 5);
printf("Server Started in listen mode ....");
while(TRUE)
{
int ret;
char strBuffer[DATA_BUFSIZE];
ULONG_PTR *PerHandleKey;
OVERLAPPED *Overlap;
OVERLAPPEDPLUS *OverlapPlus,*olpClientOverlappedPlusData;
DWORD dwBytesXfered;
SOCKET sClient;
SOCKADDR_IN saRemote;
int nRemoteLen;
/*-- Accept connections and assign to the completion port--*/
nRemoteLen = sizeof(saRemote);
sClient = WSAAccept(sListen, (SOCKADDR *)&saRemote,&nRemoteLen,0 , 0);
printf("New Client! Socket number %d connected\n", sClient);
/* Allocate memory to olpClientOverlappedPlusData */
olpClientOverlappedPlusData = (LP_OVERLAP_PLUS)GlobalAlloc(GPTR, sizeof(OVERLAPPEDPLUS));
if(NULL == olpClientOverlappedPlusData)
{
printf("Error in initialization Memory! Press any to exit...");
return -1;
}
/*-- Fill OverlapPlusData -- */
olpClientOverlappedPlusData->sClient = sClient;
olpClientOverlappedPlusData->nClientNumber = nClientInc++;
olpClientOverlappedPlusData->nOperationCode = OP_READ;
olpClientOverlappedPlusData->wbuf.buf = strBuffer;
olpClientOverlappedPlusData->wbuf.len = DATA_BUFSIZE;
memcpy(&olpClientOverlappedPlusData->ClientAddr, &saRemote, nRemoteLen);
// Associate the accepted socket with the completion port
if(NULL == CreateIoCompletionPort((HANDLE)sClient, hIocp,(ULONG_PTR)0,0) )
{
printf("Error in initialization of Completion Port for server! Press any to exit...");
return -1;
}
/*-- Make Ready to Recive Data From given Port -- */
ret = WSARecv(sClient,&olpClientOverlappedPlusData->wbuf,1,&olpClientOverlappedPlusData->dwBytes,&olpClientOverlappedPlusData->dwFlags,&olpClientOverlappedPlusData->Overlapped, NULL);
}
return 0;
}
DWORD WINAPI ServerWorkerThread(LPVOID CompletionPortID)
{
/*-- Notify Starting of server -- */
printf("\nHello Server Started, I am in worker thread! \n");
HANDLE hIocp = (HANDLE) CompletionPortID;
ULONG_PTR *PerHandleKey;
OVERLAPPED *Overlap;
OVERLAPPEDPLUS *OverlapPlus,*newolp;
DWORD dwBytesXfered;
int ret;
char *strData ;
while (1)
{
ret = GetQueuedCompletionStatus(hIocp,&dwBytesXfered,(PULONG_PTR)&PerHandleKey,&Overlap,INFINITE);
if (ret == 0){
continue;
}
OverlapPlus = CONTAINING_RECORD(Overlap, OVERLAPPEDPLUS, Overlapped);
/*--- Process Data According to Operation Code ---*/
switch (OverlapPlus->nOperationCode )
{
case OP_READ:
// Process the data read Repost the read if necessary, reusing the same receive buffer as before
memset(&OverlapPlus->Overlapped, 0, sizeof(OVERLAPPED));
ret = WSARecv(OverlapPlus->sClient,&OverlapPlus->wbuf,1,&OverlapPlus->dwBytes,&OverlapPlus->dwFlags,&OverlapPlus->Overlapped, NULL);
appendLog((TCHAR*) &OverlapPlus->wbuf.buf[0]);
ZeroMemory(&(OverlapPlus->Overlapped),sizeof(OVERLAPPED));// Why we reset memory ???
printf("\n\n****Inforamtion*****\n\nClient Socket:%d \n Bytes:%d \n Buff :%s \n Client No: %d\n FLAG :%d ",(int)OverlapPlus->sClient,OverlapPlus->dwBytes,OverlapPlus->wbuf.buf,OverlapPlus->nClientNumber,OverlapPlus->dwFlags);
if (ret == SOCKET_ERROR)
{
ret = WSAGetLastError();
if ( ret != WSA_IO_PENDING)
{
// What should i do in case of Error???
//printf("Error occur at WSARecv() : %d", ret);
//ExitThread(0);
break;
}
}
break;
case OP_WRITE:
// Process the data sent, etc.
break;//…
}
}
}
void Initialize()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 1, 1 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 )
{
printf("\n couldn't find a useable winsock.dll");
exit(1);
}
}
Madhu S. Kapoor
Madhu S. Kapoor
|
|
|
|
|
Hi! I would be most grateful for assistance. I wish to read data from a file into a CByteArray and return the array. So most simplistically, I have tried variants on:
_____
void MyClass::GetData(CString Pathname, int filesize)
{
// get pathname
// get size of file
BYTE* myarray;
myarray=ReadData(Pathname,filesize);
}
//
/////
//
BYTE* MyClass::ReadData(CString Pathname,int filesize)
{
CByteArray array;
array.SetSize(filesize,-1);
FILE* ifile=fopen(Pathname,"rb");
array.SetSize(size);
BYTE *Array = array.GetData();
ZeroMemory(Array,size);
fread(Array,sizeof(BYTE),size,ifile);
//
return Array;
}
//
_______________
I am evidently doing something totally stupid, so would be indebted to anyone who can gently point out what it is and perhaps provide the requisite correction.
Thanks in advance!
Brian
|
|
|
|
|
Do not return the pointer to the variable:
BYTE *Array = array.GetData();
Instead, return an object of some type, or allocate the memory on the heap; i.e, make it static like:
static CByteArray array;
I would rather use simple stuff:
CString strData;<br />
...<br />
return CString;
I myself have never used CByteArray, infact, I don't recall hearing about it.
this is this.
|
|
|
|
|
khan++ wrote: Instead, return an object of some type, or allocate the memory on the heap; i.e, make it static like:
static CByteArray array;
Never do that. What happens if more than one thread calls the function? Disaster
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
You are violating one of the cardinal rules of C and C++ :- Never return a pointer to a local variable. In ReadData , you are calling GetData on a local variable and then returning a pointer to it. array will be destroyed as soon as the function ends, which means you'll be left with a pointer to nowhere.
This will solve that problem.
CByteArray MyClass::ReadData(CString Pathname,int filesize)
{
CByteArray array;
array.SetSize(filesize,-1);
FILE* ifile=fopen(Pathname,"rb");
array.SetSize(size);
BYTE *Array = array.GetData();
ZeroMemory(Array,size);
fread(Array,sizeof(BYTE),size,ifile);
return array;
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi Senthil! Thank you for your response. Violating fundmental principles is, unhappily, a main skill of mine. But when I try the routine as you suggest, I get two compiler errors:
error C2558: class 'CByteArray' : no copy constructor available or copy constructor is declared 'explicit'
is invoked by
return array; // return instance of CByteArray,
while
error C2582: 'operator =' function is unavailable in 'CByteArray'
is invoked by
CByteArray byteArray;
byteArray=GetRawData(Pathname);
Thanks for your patience!
Brian
|
|
|
|
|
hello.
i want to import 3D file in VC++.and then to controll the animation or movement of object by giving values to the object through vc++ program.
thanks.
|
|
|
|
|
well... to keep it simple, u need to use DirectX SDK or OpenGL SDK. If I were in ur place, I wud've used OpenGL-GLUT. google for "GLUT" to know more...
"Do first things first, and second things not at all."
— Peter Drucker.
|
|
|
|
|