|
I tried making it own drawn fixed, but it also asserts
|
|
|
|
|
my codes was run normally! if possible, please send your more codes
*.h
----------------------------------------
class AFX_EXT_CLASS CLineStyleComboBox : public CComboBox
{
protected:
virtual void MeasureItem( LPMEASUREITEMSTRUCT lpMIS);
virtual void DrawItem( LPDRAWITEMSTRUCT lpDIS);
virtual int CompareItem(LPCOMPAREITEMSTRUCT lpCIS);
//{{AFX_MSG(CLineStyleComboBox)
afx_msg int OnCreate( LPCREATESTRUCT lpCreateStruct );
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
void AddStyleItem(int Style) { AddString((LPCTSTR)Style);}
int SelectItem(int Style);
};
*.cpp
----------------------------------------
#define LSTYLE_ITEM_HEIGHT 18
BEGIN_MESSAGE_MAP(CLineStyleComboBox, CComboBox)
//{{AFX_MSG_MAP(CLineStyleComboBox)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
int CLineStyleComboBox::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
int nRet = CComboBox::OnCreate(lpCreateStruct);
if( nRet==-1 )
return nRet;
static int styles[] =
{
PS_SOLID,PS_DASH,PS_DOT,PS_DASHDOT,PS_DASHDOTDOT,PS_NULL
};
for(int i=0;i<sizeof(styles) sizeof(styles[0]);i++)
="" addstyleitem(="" styles[i]="" );
="" setcursel(0);
="" return="" nret;
}
void="" clinestylecombobox::measureitem(lpmeasureitemstruct="" lpmis)
{
="" lpmis-="">itemHeight = LSTYLE_ITEM_HEIGHT;
}
void CLineStyleComboBox::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
CDC* pDC = CDC::FromHandle(lpDIS->hDC);
COLORREF Color =
(lpDIS->itemState & ODS_SELECTED)?RGB(0xff,0,0):RGB(0,0,0);
int nPenStyle = int(lpDIS->itemData);
CPen Pen( nPenStyle,1, Color );
CPen * pOldPen = pDC->SelectObject( &Pen );
pDC->SetBkMode(TRANSPARENT);
int y = (lpDIS->rcItem.top+lpDIS->rcItem.bottom)>>1;
pDC->MoveTo( lpDIS->rcItem.left,y );
pDC->LineTo( lpDIS->rcItem.right,y );
pDC->SelectObject( pOldPen );
}
int CLineStyleComboBox::CompareItem(LPCOMPAREITEMSTRUCT lpCIS)
{
return int(lpCIS->itemData1)-int(lpCIS->itemData2);
}
int CLineStyleComboBox::SelectItem(int Style)
{
int n = GetCount();
for(int i=0;i
|
|
|
|
|
I wonder if you understand me when I explain my problem.
I am trying to make an application with Visual C++, my application must contain MFC and ADo connection.
It must me connected to database (which I made in Access).
We must be able to brows tables (2-3 different tables) of the database.
INserting, adding and deleting records of the tables.
I have done the following:
My database is a phonebook, I have made and access database connection to it, and I can brows it, add, delete and updating.
My problem is: How do I add another table in the application? I have tried everything, and made mistakes and over and over again. What I meen is that I must have 2 tables och more working paralell in the application.
How do I do this?
|
|
|
|
|
I've written an MFC DLL, say ClientAPI.dll and ClientAPI.lib. In the DLL, there's a class, say CMyClassA, it's just a class doing some getXXX and setXXX with CString's, and without any memory allocations.
However, in the application using it, i just link with ClientAPI.lib, and create an instance as
CMyClassA *pInsA;
pInsA = new CMyClassA();
delete pInsA;
In delete pInsA, I got an error :
Heap block at 003B7378 modified at 003B7400 past requested size of 80
What's worng with it ?
Thanks
|
|
|
|
|
Probably the reason of heap corruption is that you're allocating memory blocks for CStrings in .DLL and freeing them in .exe.
Did you link with MFC dynamically or statically?
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
Yeah, the CString's are in the classes in the DLL, but I just make it class variable ( should be auto variable ). I didn't allocate memory on my own.
You are right too, I declared the classes in the DLL, and use it in a EXE. In the exe routine, i did
CMyClassA *pInst;
pInst = new CMyClassA;
delete pInst;
I like MFC dynamically in debug mode.
Hiya, Everybody ^^
|
|
|
|
|
Hi!
I making a "funny" application (not serious but good practice). I want to steer a picture with the arrow keys. The problem is that when I holding arrow left to move the picture left and then press up arrow while I holding left arrow down the left arrow functionality seems to stop then... How to make the picture move left and up at the same time? because that must be the problem...
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
You could create a sub-message handler specifically for your arrow keys when you handle the WM_CHAR message.
Then what this handler would do is call GetKeyboardState, or GetKeyState in order to test the values
of all of the arrow keys. Then you can logically decide which way to move the image based on which arrow keys are set.
If you wanted to get more complicated with the way that the keys control the movement you will have to store the last known state of the keys. For instance, say that you are holding the left arrow key, then you hit the right arrow key. The simple solution in this case would be not to move the items because both keys cancel themselves out. However, if you record the state of the keys in the WM_KEYUP and WM_KEYDOWN messages, you would be able to tell that the right arrow key was clicked second, and the movement of the picture should change to the right.
|
|
|
|
|
When I use the Data Grid control and ADO in my program, It run correctly,but it can't run on the machine whithout the Vc++ IDE correctly. It troubles me for all day. Can somebody help me !
Thanks very much!!
splendoury
VCBeginer
|
|
|
|
|
You have to register ocx file of DataGrid in that machine.For this purpose you can use installshield and add that file to it.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Is it to copy the file named DBGRID32.OCX to the system directory! I do like this, but it's unuseful. Is it ADO that cause it!!
VCBeginer
|
|
|
|
|
Forlegend wrote:
DBGRID32.OCX
no,thats msdatagrid.ocx. If you don't use installshield,use regsvr32 in command menu for that file,then run your application.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Thank you very much!!
VCBeginer
|
|
|
|
|
Hi all,
how to create a main application and with a menu command open inside this main applicationa one or more dialog (but not called with a DoModal())?!
Thanks!
|
|
|
|
|
Why is DoModal() so scary to ya!?
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
If you want to avoid modal dialogs create a modeless dialog
Nish
I am the Keyboard Smasher
|
|
|
|
|
do you want to use Create() and ShowWindow() instead to show the dialog?
|
|
|
|
|
Hi,
In my program, I've used multithread (many clients) to send message to one thread(Server). However, I realized that only the first client can get access to the server from start to end, other clients are blocked. Can anyone help me to solve this problem??
The following is the code of the server:
if ( svrSocket.Accept(socket))
AfxMessageBox("Socket is created Succesfully");
while (...)
flag = socket.Receive(buff,sizeof(buff));
....
Please HELP! Thank you!!
|
|
|
|
|
while( ...)
{
if ( svrSocket.Accept(socket))
{
CSockThread sockThread = new CSockThread(sock);
// class CSockThread : CWinThread
}
}
Receive in Thread
while (...)
flag = socket.Receive(buff,sizeof(buff));
....
|
|
|
|
|
hi ,
I use an array to store all thread ID:
CWinThread* thread[10];
thread[i] = AfxBeginThread(.....)
then, in the thread function, I will use pThread = AfxGetThread(); in order to get the thread ID of that thread. (CWinThread* pThread)
In another function, i will use: (e.g.)
if (pThread == thread[i])
.....
Is it workable????
|
|
|
|
|
Try this:
if(AfxGetThread()->m_nThreadID == thread[i])
{
//Do something
}
instead of:
if(pThread == thread[i])
{
//Do something
}
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
thread[i] is not an ID, but address of CWinThread-derived objects. You can use it to identify the thread assuming that you're using AfxBeginThread for thread creation.
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
Hi,
I am working on eVC++ and I want to place a bitmap on a atatic control.
I am using the following code. It compiles but I am not able to see the bitmap on the screen.
Any pointers ??
MyBmp.LoadBitmap(IDB_BITMAP1);
myStatic.SetBitmap(MyBmp);
An expert is one who has made all the mistakes.
|
|
|
|
|
When you create your static control, add SS_BITMAP to the dwStyle parameter.
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
How to retrieve a RGB value of Bitmap directly in memory without use GetPixel of the CDC with logical coordinate of the point to be examined?
thx
|
|
|
|