#include <windows.h>
#include <odbcinst.h>
#include <stdio.h>
#include "resource.h"
#include "ex1.h"
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASS wc;
HWND hWnd;
MSG msg;
wc.style=0;
wc.lpfnWndProc=MainWndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL,IDI_HAND);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=GetStockObject(WHITE_BRUSH);
wc.lpszMenuName=MAKEINTRESOURCE(IDR_MENU1);
wc.lpszClassName="MyClass";
if (RegisterClass(&wc)==0){
MessageBox(NULL,"Error","Failed to register class", MB_OK);
return 0;
}
hWnd=CreateWindow(wc.lpszClassName,"My Window",WS_BORDER|WS_CAPTION|WS_OVERLAPPEDWINDOW|WS_SYSMENU|WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hWnd,SW_MAXIMIZE);
UpdateWindow(hWnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK MainWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam )
{
switch(uMsg)
{
case WM_COMMAND:
switch(LOWORD( wParam ))
{
case ID_FILE_EXIT:
if (MessageBox(hwnd,"Are you sure you want to quit","Information",MB_OKCANCEL) == IDOK)
DestroyWindow(hwnd);
break;
case ID_DATABASE_ACCESS:
/*
If you want to create the DSN depending on the user input then you
will need to follow the below procedure. To hardcode it you could just pass
"DSN=TestDB\0DBQ=D:\\Database\\Friends.mdb\0DEFAULTDIR=D:\\DATABASE\0\0" as the
third parameter
*/
char* szDesc;
int mlen;
szDesc=new char[256];
sprintf(szDesc,"DSN=%s: DESCRIPTION=TOC support source: DBQ=%s: FIL=MicrosoftAccess: DEFAULTDIR=D:\\Database:: ","TestDB","D:\\Friends.mdb");
mlen = strlen(szDesc);
for (int i=0; i<mlen; i++)
{
if (szDesc[i] == ':')
szDesc[i] = '\0';
}
if (FALSE == SQLConfigDataSource(NULL,ODBC_ADD_DSN,"Microsoft Access Driver (*.mdb)\0",(LPCSTR)szDesc))
MessageBox(hwnd,"Failed","INFORMATION",MB_OK);
else
MessageBox(hwnd,"Sucess","INFORMATION",MB_OK);
break;
}
break;
case WM_CLOSE:
if (MessageBox(hwnd,"Are you sure you want to quit","Information",MB_OKCANCEL) == IDOK)
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
create_access_dsn_dynamicaly.zip (12个子文件)
ex1.dsw 529B
ex1.cpp 2KB
Script1.rc 2KB
ex1.plg 1KB
ex1.h 208B
ex1.dsp 4KB
resource.h 597B
ex1.ncb 65KB
ex1.opt 51KB
ODBCINST.H 15KB
Debug
ex1.exe 93KB
ODBCCP32.LIB 35KB
共 12 条
- 1
资源评论
普通网友
- 粉丝: 882
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功