|
I am using CDatabase and I want to be able to open the database without the user having to select anything. (Users like to break stuff, I want no breaking) I can get it so I just have to select the database with this code:
dbSNDB.OpenEx("DSN=MS Access Database,", 0);
And I am wondering if there is anything I can do to make it so it open's the database automtically. I am still having to select the database from the options it pops up.
Thanks
The wisest of the wise may err. - Aeschylus
|
|
|
|
|
If there's only one database you can do this:
bd.Open(_T("Your-DSN"),FALSE, FALSE, _T("ODBC;UID=yourUserName;PWD=yourPass;Database=yourDb"));
if (bd.IsOpen())
// it's ok
else {
// error
}
If you want the user to select a database you can let him choose from a list (but not the one opened by ODBC). Then you try to open the connection with the database selected by the user with the code above. If there's any error you display an error message.
-----
We are what we repeatedly do. Excellence, then, is not an act, but a habit.
|
|
|
|
|
I've tried this both with VC6 on one machine, and imported the project to VC7 on another. It worked on neither. Try the code below. After running OnWriteOut(), right click on the file in the shell, click on "Properties", and go to the "Summary" tab. Viola! Here, I'm getting only some "default" properties, and the application name ("The Application v 1.0") doesn't show up anywhere! However, if you copy the SAME FILE over to a Win2k machine, it shows up fine. You'll notice that if you set a breakpoint in OnReadIn() after the ReadMultiple call however, all the properties (including app name) come in just fine programmtically. Am I doing something wrong here? If this is confirmed, how do I report this to MS?
P.S. This is in SP1, and I'm looking at the "Advanced" view of the Summary
---------
Code
---------
void CTestwritepropsDlg::OnWriteOut()
{
HRESULT hr = S_OK;
IStorage* pStg = NULL;
hr = ::StgCreateStorageEx(CComBSTR("C:\\out.test"),
STGM_CREATE | STGM_READWRITE | STGM_TRANSACTED,
STGFMT_DOCFILE, 0,
NULL, NULL, IID_IStorage, (void**)&pStg);
ASSERT(SUCCEEDED(hr));
IPropertySetStorage* pPropSet = NULL;
hr = pStg->QueryInterface(IID_IPropertySetStorage, (void**)&pPropSet);
ASSERT(SUCCEEDED(hr));
IPropertyStorage* pProps = NULL;
hr = pPropSet->Create(FMTID_SummaryInformation, NULL, 0,
STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
&pProps);
ASSERT(SUCCEEDED(hr));
PROPSPEC specs[] = {{PRSPEC_PROPID, PIDSI_APPNAME},
{PRSPEC_PROPID, PIDSI_COMMENTS},
{PRSPEC_PROPID, PIDSI_TITLE},
{PRSPEC_PROPID, PIDSI_AUTHOR} };
PROPVARIANT vars[4];
PROPVARIANT var;
PropVariantInit(&var);
var.vt = VT_LPSTR;
var.pszVal = "The Application v 1.0";
vars[0] = var;
var.pszVal = "Some comments";
vars[1] = var;
var.pszVal = "The Title of the Document";
vars[2] = var;
var.pszVal = "Bill Gates";
vars[3] = var;
hr = pProps->WriteMultiple(4, specs, vars, 0);
ASSERT(SUCCEEDED(hr));
hr = pProps->Commit(STGC_DEFAULT);
ASSERT(SUCCEEDED(hr));
pProps->Release();
pPropSet->Release();
hr = pStg->Commit(STGC_DEFAULT);
ASSERT(SUCCEEDED(hr));
pStg->Release();
}
void CTestwritepropsDlg::OnReadIn()
{
HRESULT hr = S_OK;
IStorage* pStg = NULL;
hr = ::StgOpenStorageEx(CComBSTR("C:\\out.test"),
STGM_READWRITE | STGM_TRANSACTED,
STGFMT_DOCFILE, 0,
NULL, NULL, IID_IStorage, (void**)&pStg);
ASSERT(SUCCEEDED(hr));
IPropertySetStorage* pPropSet = NULL;
hr = pStg->QueryInterface(IID_IPropertySetStorage, (void**)&pPropSet);
ASSERT(SUCCEEDED(hr));
IPropertyStorage* pProps = NULL;
hr = pPropSet->Open(FMTID_SummaryInformation,
STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
&pProps);
ASSERT(SUCCEEDED(hr));
PROPSPEC specs[] = {{PRSPEC_PROPID, PIDSI_APPNAME},
{PRSPEC_PROPID, PIDSI_COMMENTS},
{PRSPEC_PROPID, PIDSI_TITLE},
{PRSPEC_PROPID, PIDSI_AUTHOR} };
PROPVARIANT vars[4];
hr = pProps->ReadMultiple(4, specs, vars);
ASSERT(SUCCEEDED(hr));
pProps->Release();
pPropSet->Release();
hr = pStg->Commit(STGC_DEFAULT);
ASSERT(SUCCEEDED(hr));
pStg->Release();
}
|
|
|
|
|
hi. i am working on a MFC SDI project. i use below code for changing the cursor.
HCURSOR cur;<br />
cur=AfxGetApp()->LoadStandardCursor(IDC_IBEAM);<br />
SetCursor(cur);
but it don't work. my cursor is not Static. for example i write this code in OnLButtenDown function. even i change the cursor with a left-Click then a moment later it changes to default cursor (IDC_ARROW).
if i write the code in OnMouseMove and then i move the mouse over the main window the Cursor will flicker and will change to my cursor and then will change to Defualt cursor and even i stop moving the mouse it will became default mouse cursor
what can i do to Creat a Static Cursor in a SDI ?
|
|
|
|
|
You need to handle the WM_SETCURSOR message. Windows sends this to your window everytime the mouse is moved - that is why your cursor changes back almost straight away.
Dave
|
|
|
|
|
SetCursor is trick: u must call it from a window, and the window must have focus first (or WM_SETFOCUS message is on first).
includeh10
|
|
|
|
|
I am new to working with bitmaps and other images
Where can I find a table for colors in hex?
or can some explain to me this bit of code
<br />
my_cdc->SetBkColor(RGB(0xFF,0x00,0xFF));<br />
<br />
what is the 0xFF,0x00,0xFF?
I am trying to set a color in a bitmap image to be transparent but am having trouble understanding
Thanks
Later,
JoeSox
www.joeswammi.com
"Male Employee #1 Hey Nick, how's it going?
Nick Burns: Oh great, really great. I love teaching people remedial computers here. You guys should be wearing helmets or something?"
|
|
|
|
|
Hi..
colours of pixels are mixtures of three basic colours:
Red,Green,Blue..
The final colour is the resultant of mixing the three basic colours..
I f you want to increase the red component you can increase its value in the macro RGB(Red,Green,Blue)
each component takes a value from 0 to 255 in decimal..
00xFF (hex)= 255(dec)<br />
00X00(hex)= 0 (dec)
so the resultant colour in you example will be a mixture of red and blue only..
I wish this brief explanation can spot some light !!
|
|
|
|
|
so this:
<br />
RGB(0xFF,0x00,0xFF)<br />
is the same as:
<br />
RGB(255,0,255)<br />
why would some one use RGB(0xFF,0x00,0xFF)
instead of RGB(255,0,255)?
|
|
|
|
|
JoeSox wrote:
Where can I find a table for colors in hex?
You do not need to supply the rgb values in hex.
Using MS Paint you can get the rgb value to use in your app.
Paul
|
|
|
|
|
ah, thank you!!
Later,
JoeSox
|
|
|
|
|
|
Hi All,
I just wanted to get some opinions on the best and/or simplest way to access a MS Access DB using VC++ without MFC.
Thanks,
Paul
|
|
|
|
|
OLEDB using ATL support classes (CSession, CCommand and so on).
"You can stand all night at a redlight anywhere in town, hailing Marys left and right but none of them slow down. I've seen the best of men go past. I don't wanna be the last..."
|
|
|
|
|
Hello everyone, i have a small problem trying to guess how to add a small icon in listbox.
I am pure API programmer so i think there may be some problems with that (?)
I just set a text on index 1 in listbox, and also i would like to put beside the text a small icon
representing some action.
Please help me to solve it..
|
|
|
|
|
I'm having a problem trying to get a custom control to respond to OnPaint(). I followed Chris Maunders' Creating Custom Controls tutorial to create the control, great tutorial. Now I am trying to get it to paint the control a different color. I'm using this custom control as part of a tetris clone I am writing. The project is dialog based and this custom control is what I'd like to use for the 'game board'. To test I am using buttons on the dialog where the custom control resides. Just to make sure everything is communicating correctly I used some AfxMessageBox calls to verify. And all the right functions are being called, I just cant get it to paint. The following is in my OnPaint() for the custom control class:
thanks for any help,
paul
void CGameBoard::OnPaint() <br />
{<br />
CPaintDC dc(this);
CRect rect;<br />
<br />
GetWindowRect(rect);<br />
ScreenToClient(&rect);<br />
<br />
dc.FillSolidRect(rect,RGB(35,30,100));<br />
<br />
}
I first call a Paint() function. It calls Invalidate then calls OnPaint()
void CGameBoard::Paint()<br />
{<br />
Invalidate();<br />
OnPaint();
}
|
|
|
|
|
hi. is there any Simple Code to play a Wav file from a Resource ?
thanks
|
|
|
|
|
PlaySound(MAKEINTRESOURCE(IDS_SOUND), :confused:, SND_RESOURCE | SND_ASYNC);
You need to experiment a bit with the parameters, but SND_RESOURCE is the way to go
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
i set : #include "MMSYSTEM.H"
and i use : PlaySound("c:\\sample.wav", NULL , SND_RESOURCE | SND_ASYNC);
but this error occured :
ERROR LNK2019 : unresolved external Symbol___imp___PlaySound@12 refrenced in function : public :int__thiscall CTestView::.....
|
|
|
|
|
put winmm.lib into your linker settings or use this line in your stdafx.h file: #pragma comment(lib, winmm)
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Winmm.lib?
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
I have a irregular shaped dialog created using regions. How do i go about change this region dynamically?? I tried creating the new region and use SetWindowRgn(...) again but it returns FALSE. Any ideas?
Weiye, Chen
When pursuing your dreams, don't forget to enjoy your life...
|
|
|
|
|
i never use the function, here is a "guess".
1. try to set a new region which is smaller than previous one.
if works:
2. call SetWindowPos to make sure square window is larger than new region first, then call SetWindowRgn
hope see ur testing result soon.
includeh10
|
|
|
|
|
I'm trying to open a drive, by specifying the lpFileName argument to be of the format "\\.\<drivename>:" in CreateFile. But when i use ReadFile to read from the disk, i get an error, number 87 which means invalid parameter, anyone know what's wrong?
char test[32];
HANDLE hDrive = CreateFile("\\\\.\\H:", GENERIC_READ, FILE_SHARE_WRITE , NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD dwBytesRead;
ReadFile(hDrive, &test, 32, &dwBytesRead, NULL);
CloseHandle(hDrive);
Thanks all!
-Rune SVendsen
|
|
|
|
|
Redeemer-dk wrote:
anyone know what's wrong?
Yes, and so does the MSDN documentation:
Note that all I/O buffers must be sector aligned (aligned on addresses in memory that are integer multiples of the volume's sector size), even if the disk device is opened without the FILE_FLAG_NO_BUFFERING flag.
|
|
|
|
|