|
I have the following situation:
DataDialog::Start()
{
...
m_pDataSet = new CDataSet(m_pDB);
try
{
m_pDataSet->Open()
}
...
}
DataDialog::OnReceiveData()
{
...
if (m_pDataSet->IsOpen())
{
m_pDataSet->AddNew();
...
m_pDataSet->Update();
}
...
}
DataDialog::Stop()
{
...
if (m_pDataSet->IsOpen())
{
try
{
m_pDataSet->Close();
}
...
}
delete m_pDataSet;
...
}
where m_pDataSet is a pointer to an object derived from CDaoRecordSet and m_pDB is a pointer to a CDaoDatabase. My problem is that I get an unhandled exception when I close the data set (the data is stored fine). I tried opening and closing the data set in the OnReceiveData function and that does not crash, but it cannot keep up with the incoming data.
Any suggestions?
Thanks.
|
|
|
|
|
Does anyone know how to get the memory address of a bitmap resource, using it's ID ?
I would appreciate any help !
|
|
|
|
|
FindResource, LoadResource, and LockResource gives you a pointer to read-only data.
|
|
|
|
|
Hi
I have a problem with my application.
i made my application in VC++ 6.0 .
when i tried running that on the user's machine i found out that he is having a different screen resolution.
I developed the application in 600X800 .
but the user's machien is running on 480X600.
How do i do now.
i need my dialog box and all the controls to be visible in this new resolution also.
i cannot statically change the position of all my controls now.
Is there any way .. where i can do it for the dialog box and it gets adjusted for all the controls also?
i used MFC.
Thanks.
|
|
|
|
|
To get the size of the screen:
n_screen_width = GetSystemMetrics(SM_CXSCREEN);
n_screen_height= GetSystemMetrics(SM_CYSCREEN);
Then you can resize a control/window by using these functions:
SetWindowPos( const CWnd* pWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags );
OR
void MoveWindow( int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE );
void MoveWindow( LPCRECT lpRect, BOOL bRepaint = TRUE );
|
|
|
|
|
Hi Thank u.
i have a command button in the right most corner.
i placed it there while certaing the dialog box.
but while running when i changed the screen resolution, that command button was not visible.
where exactly am i supposed to place the
SetWindowPos or MoveWindow functions?
Is it enough if i write for the dialog box onintit or Precreatewindow.
do i have to write the same code for all teh controls inside the dialog box too ???
i am new to VC++.
and this is urjent.
could u pl. provide me some more help on this.
Thank u.
|
|
|
|
|
I think that when you change the screen resolution while your program is running that you receive a WM_PAINT/WM_SIZE message from Windows.
Then you could write an WM_PAINT/WM_SIZE handler that paints the window according to the systemmetrics values.
You can probably just move the command button then to a position where it can be seen on the screen. You can use either of the functions to accomplish this.
Rundown:
-> Receive WM_PAINT/WM_SIZE
-> In WM_PAINT/WM_SIZE handler:
-> check the screenmetrics
-> call SetWindowPos / MoveWindow to place window correctly on screen
-> resize and/or move all controls on the screen
>>do i have to write the same code for all teh controls >>inside the dialog box too ???
as explained above, let the parent window handle this (dialog box)
|
|
|
|
|
Hi,
You may try using a class that simplifies resizing a dialog and all its content. There are a lot of them on CodeProject!
I wrote one, too. If you wish, look at:
CResizableDialog - A CDialog derived class to implement resizable dialogs with MFC.
I think it's quite simple to use. But there are also many other good choices. Look in the Dialog section.
Hope this helps,
Paolo.
|
|
|
|
|
One of the things you either love or hate about VS6 and VC6 is the the "member" list that appears after you've typed "->" or "." after a class or structure name.
When I add members to classes of mine, they are accordingly listed after I type the class name. However I have a header file will lots of structure definitions in a directory different to the main app / source code. If I modify one of these structures, the changes don't seem to be listed when I next type the structure name.
Any ideas why, or what I'm doing wrong please?
Thanks
|
|
|
|
|
This is a common problem, intellisense isn't really reliable in VC++ (and of course much more complicated than in e.g.VB). The advises range from waiting for full moon, step out of your cubicle and howl all night long, to: close the project, delete all temporary files (.opt, aps, .ncb, .clw, although .ncb is the likeliest), reopen the project, and open clazz wizard dialog, to rebuild the clw information. Well, I've found out both methods have their advantages... Good luck!
Peter
|
|
|
|
|
Deleting the .NCB file usually fixes it for me. The other files have nothing to do with IntelliSense. .APS = resource browser data, .OPT = debugging settings, .CLW = ClassWizard data.
|
|
|
|
|
I have an application that contains 5 buttons, when each button is pressed a pop-up menu appears with 3 choices (each menu for each button is identical but performs different tasks). Is there any way to distinguish which menu is being accessed by using any of the CMenu functions or do I have to have message handlers for each menu item based on which button was pressed.
|
|
|
|
|
I think you can use following solutions.
1. Store the number (ID,...) last pressed button
and identify menu using this information.
2. Look MSDN for Menu Messages, especially:
WM_INITMENUPOPUP,
WM_MENUCOMMAND,
WM_MENUSELECT,
WM_UNINITMENUPOPUP
They return menu handle as one of the parameters,
look also for CWnd::OnInitMenuPopup handler.
There is nothing about CMenu functions,
but may be it will help you anyway.
Igor Chouvalov
|
|
|
|
|
How can i create a virtual serial port? An excisting programm uses a serial port to retrieve data. I wont to
use a file instead of the com port. Can anyone help me?
Greetings,
Herbert Slaghekke
|
|
|
|
|
I suppose you do not control (the source) of the existing application. So you have to figure out how it talks to the COM port.
If it uses its own COM driver, you will have to emulate this driver, which can be more difficult (depending on whether you are used to writing drivers) than rewriting the existing application.
If it uses the Win32 CreateFile API call to open the COM port, you can start by either trying to specify an non-existing COM port in the program, let's say port 3. Of course if this port does not exist, the program will not be able to open it. But then again, you could create this "file" yourself and mimic the Win32 COM API mechanism. (if that works, it will be the simpliest solution).
For more information, look at the CreateFile Win32 function with regard to the COM port communications.
If the program uses Hardware flow control, it might be very difficult.
I use the following code in my programs to open a COM port. I could easily 'fool' this code that there is a virtual COM port on the other side. So it depends on the existing program's implementation.
Best regards,
GBO
---
BOOL CSerial::Open()
{
COMMTIMEOUTS timeouts;
DWORD dwSerialStatus;
char szPort[16];
char strTemp[10];
DCB dcb; // Abre el puerto serie
::ZeroMemory(szPort, 16);
::ZeroMemory(strTemp, 10);
strcpy(szPort, "COM");
_ltoa( PortNum, strTemp, 10 );
strupr( strTemp );
strcat(szPort, strTemp);
hCom = CreateFile(szPort, GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, 0, NULL);
if (hCom == NULL || hCom == INVALID_HANDLE_VALUE)
{
// try \\.\COMxx
::ZeroMemory(szPort, 16);
strcpy(szPort, "\\\\.\\COM");
strcat(szPort, strTemp);
hCom = CreateFile(szPort, GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, 0, NULL);
}
if (hCom != NULL && hCom != INVALID_HANDLE_VALUE)
{
if (GetCommState(hCom, &dcb))
{
// Llena la estructura del DCB
dcb.BaudRate = BaudRate;
dcb.ByteSize = DataBits;
switch (Parity)
{
case 'N' :
dcb.Parity = NOPARITY;
break;
case 'E' :
dcb.Parity = EVENPARITY;
break;
case 'O' :
dcb.Parity = ODDPARITY;
break;
}
dcb.StopBits = ONESTOPBIT;
if (SetCommState (hCom, &dcb))
{
if (GetCommModemStatus (hCom, &dwSerialStatus))
{
// Setea los timeouts de la puerta serie
timeouts.ReadIntervalTimeout = 100;
timeouts.ReadTotalTimeoutMultiplier = 1;
timeouts.ReadTotalTimeoutConstant = 100;
timeouts.WriteTotalTimeoutMultiplier = 1;
timeouts.WriteTotalTimeoutConstant = 100;
if (SetCommTimeouts (hCom, &timeouts))
{
if (PurgeComm(hCom, PURGE_TXCLEAR | PURGE_RXCLEAR |
PURGE_TXABORT | PURGE_RXABORT))
{
if (SetupComm (hCom, RxBufSiz, TxBufSiz))
{
if (EscapeCommFunction(hCom, SETDTR))
{
// All OK
}
else
{
DWORD dwError = ::GetLastError();
_ASSERT(NULL);
}
return TRUE;
}
}
}
}
}
}
}
DWORD dwError = ::GetLastError();
_ASSERT(NULL);
return FALSE;
}
|
|
|
|
|
Is it possible to add a bitmap to a menu without C++ class-based coding?
|
|
|
|
|
Look MSDN for SetMenuItemBitmaps function.
Igor.
|
|
|
|
|
I need to create MS Access file at runtime. I tried using CFile which is not the correct way coz it doesnt make a db file.
I'll appreciate the help.
Thanks
|
|
|
|
|
You can use:
CDaoDatabase db;
CString strDBFileName = "d:\\aaa.db";
db.Create(strDBFileName, dbLangGeneral, dbVersion30)
|
|
|
|
|
I want to change the look of minimize, maximize and close buttons in the upper right corner of dialog or window. Also I am interested in code using skins. Does enyone know some good links and info I could find on the net? Thanks in advance.
|
|
|
|
|
I don't know anything about this, but there is a recent post on code project concerning skins.
http://www.codeproject.com/dialog/skinsyse.asp
|
|
|
|
|
Does anyone know how to convert metafile to bitmap?
|
|
|
|
|
Larry,
I can't tell you from experience, but as I understand it you simply "play" the metafile into a DC and then use standard techniques to save the DC to a .bmp file.
|
|
|
|
|
Create a DIB section and a memory DC, select the DIB section into the memory DC, play the metafile into memory DC, now you got a bitmap in the DIB section.
http://www.amazon.com/exec/obidos/ASIN/0130869856
|
|
|
|
|
thanks for you both.
I am not good in graphic design. I have some code here.
I am trying to save Meta to BMP. But I only get black area.
please help.
larry
if ( OpenClipboard() )
{
HENHMETAFILE handle = (HENHMETAFILE)GetClipboardData(CF_ENHMETAFILE);
CClientDC dc(this);
CRect client(0,0,500,500);
CBitmap * bmf = new CBitmap();
CDC mdc;
mdc.CreateCompatibleDC(&dc);
bmf->CreateCompatibleBitmap(&dc,client.Width(),client.Height());
PlayEnhMetaFile(dc, handle, &client);
dc.SelectObject(bmf);
SetClipboardData(CF_BITMAP,bmf->m_hObject);
CloseClipboard();
}
|
|
|
|
|