页:
[1]
2
| 日出东方XP | 2004-12-22 06:18 AM |
|
发个vc 学习日志,初级问题高手勿笑。
2004-11-01
右键菜单
CMenu menu;
menu.LoadMenu(IDR_MENU1);
CMenu *pPopup;
pPopup = menu.GetSubMenu(0);
CPoint pt;
GetCursorPos(&pt);
pPopup->TrackPopupMenu(TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_LEFTALIGN,
pt.x,pt.y,this); |
| 日出东方XP | 2004-12-22 06:20 AM |
|
2004-11-01
初始化List控件:
//设置列表样式
m_listMessage.ModifyStyle(0,LVS_REPORT|LVS_SINGLESEL|LVS_SHOWSELALWAYS);
m_listMessage.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP);
m_listMessage.SetTextColor(RGB(0,0,0));
//设置列表项目
m_listMessage.InsertColumn(0,"",LVCFMT_CENTER,400); |
| 日出东方XP | 2004-12-22 06:28 AM |
|
2004-11-01
初始化socket
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
} |
| 日出东方XP | 2004-12-22 08:11 AM |
|
2004-11-01
最小化到系统托盘:
[CODE]
#define WM_SYSTEMTRAY WM_USER+100 //系统托盘消息
#define ID_SYSTEMTRAY 101
//对话框类
public:
VOID Minimize();
NOTIFYICONDATA m_nid;
VOID CServerDlg::Minimize()
{
m_nid.cbSize = sizeof( NOTIFYICONDATA );
m_nid.hWnd = m_hWnd;
m_nid.uID = ID_SYSTEMTRAY;
m_nid.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
m_nid.uCallbackMessage = WM_SYSTEMTRAY;//自定义消息
m_nid.hIcon = AfxGetApp()->LoadIcon( IDI_ICON1 );
strcpy( m_nid.szTip, "xxx查询服务器");
}
LRESULT CServerDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
switch(message)
{
case WM_SYSTEMTRAY: //自定义消息
if(lParam==WM_LBUTTONDOWN)
{
// AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOW);
AfxGetApp()->m_pMainWnd->ShowWindow(SW_RESTORE);
AfxGetApp()->m_pMainWnd->SetForegroundWindow();
::Shell_NotifyIcon( NIM_DELETE,&m_nid );
}
break;
case WM_SYSCOMMAND: //系统消息
if(wParam==SC_MINIMIZE)
{
AfxGetApp()->m_pMainWnd->ShowWindow(SW_HIDE);//窗口隐藏
::Shell_NotifyIcon( NIM_ADD,&m_nid );
return 0;
}
break;
}
return CDialog::WindowProc(message, wParam, lParam);
}
void CServerDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
::Shell_NotifyIcon( NIM_DELETE,&m_nid );
}
[/CODE] |
| 日出东方XP | 2004-12-23 03:54 AM |
|
2004-11-02
Variant转化到CString
[CODE]
BOOL VariantToCString(_variant_t var,CString & strValue)
{
if(var.vt==VT_NULL)
{
strValue="";
return TRUE;
}
HRESULT hr=VariantChangeType(&var, &var, 0, VT_BSTR);
if (FAILED(hr))
{
return FALSE;
}
else
strValue=var.bstrVal;
strValue.TrimRight();
return TRUE;
}
[/CODE] |
| 日出东方XP | 2004-12-24 01:36 PM |
|
2004-11-04
编译OpenSSL:
1.下载OpenSSL0.9.7d 解压到c:\OpenSSL
2.安装 ActivePerl 5.8
3.拷贝ml.exe ml.err 2个文件到OpenSSL
4. >cd \openssl
>perl Configure VC-WIN32
5. >ms\do_masm
6. >nmake -f ms\ntdll.mak |
| 日出东方XP | 2004-12-28 03:28 AM |
|
2004-11-08
字符串分割函数
[PHP]
VOID Split(CString* string, CString* separator,CArray<CString,CString&> & outArr)
{
CString tmp;
int pos1 = 0;
int pos2 = 0;
while(TRUE)
{
pos2 = string->Find(*separator, pos1);
if(pos2>=0)
{
tmp = string->Mid(pos1,pos2-pos1);
outArr.Add(tmp);
pos1 = pos2 + 1;
}
else
{
tmp = string->Mid(pos1);
outArr.Add(tmp);
break;
}
}
}
[/PHP] |
|
2004-11-15
托动非标题栏移动窗口
[PHP]
CPoint pt = point;
ClientToScreen(&pt);
CRect rec;
CStatic *pic;
pic = (CStatic *)GetDlgItem(IDC_REC);
pic->GetWindowRect(&rec);
if(rec.PtInRect(pt))
{
SetCursor(hCursor2);
PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
}
else
{
SetCursor(hCursor1);
}
CDialog::OnLButtonDown(nFlags, point);
[/PHP] |
|
2004-11-16
隐藏任务栏图标
ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW, SWP_DRAWFRAME); |
|
2004-11-17
限制窗口移动范围,禁止移出屏幕。
[PHP]
void CReadCardDlg::OnMoving(UINT fwSide, LPRECT pRect)
{
RECT newRec;
newRec.left = pRect->left < 0 ? 0 : pRect->left;
newRec.right = pRect->left < 0 ? pRect->right - pRect->left : pRect->right;
newRec.left = pRect->right > nScrWidth ? nScrWidth - pRect->right + pRect->left : newRec.left;
newRec.right = pRect->right > nScrWidth ? nScrWidth : newRec.right;
newRec.top = pRect->top < 0 ? 0 : pRect->top;
newRec.bottom = pRect->top < 0 ? pRect->bottom - pRect->top : pRect->bottom;
newRec.top = pRect->bottom > nScrHeight ? nScrHeight - pRect->bottom + pRect->top : newRec.top;
newRec.bottom = pRect->bottom>nScrHeight ? nScrHeight : newRec.bottom;
pRect->top = newRec.top;
pRect->left = newRec.left;
pRect->bottom = newRec.bottom;
pRect->right = newRec.right;
CDialog::OnMoving(fwSide, pRect);
// TODO: Add your message handler code here
}
[/PHP] |
|
2004-11-17
获取屏幕尺寸
[PHP]
HDC hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
nScrWidth = GetDeviceCaps(hScrDC,HORZRES);
nScrHeight = GetDeviceCaps(hScrDC,VERTRES);
[/PHP] |
|
2004-12-08
设置CEditView为只读
添加CREATE消息处理函数。
加入[PHP]
CEdit &edit = this->GetEditCtrl();
::SendMessage((HWND)edit.GetSafeHwnd(),EM_SETREADONLY,TRUE, 0);
[/PHP] |
|
我不懂這個```````````
不過看來,比較厲害啊~~~~~~~~` |
| barryonline | 2005-2-6 01:43 AM |
|
| 我也看不懂.以前学C++的时候全逃课了 |
|
2004-12-22
设置单文档机构程序标题栏文字。
CWinApp::InitInstance() 中加入
[PHP]
m_pMainWnd->SetWindowText("呵呵,快来看啊!");
[/PHP] |
|
2004-12-28
读取Access数据。
[PHP]
COleVariant var;
var.ChangeType(VT_BSTR, NULL);
CString tmp;
CDaoDatabase db;
CDaoRecordset RecSet(&db);
db.Open(sPath);
RecSet.Open(AFX_DAO_USE_DEFAULT_TYPE,"SELECT * FROM user",NULL);
while(!RecSet.IsEOF())
{
RecSet.GetFieldValue("id",var);
var.ChangeType(VT_BSTR);
tmp = (LPCSTR)var.bstrVal;
m_list.InsertItem(0,tmp);
RecSet.GetFieldValue("nickname",var);
tmp = (LPCSTR)var.bstrVal;
m_list.SetItemText(0,1,tmp);
}
[/PHP] |
|
2005-02-01
ADO方式连接DBF数据库。
[PHP]
_ConnectionPtr pConn("ADODB.Connection");
_RecordsetPtr pRst("ADODB.Recordset");
pConn->Open("Driver={Microsoft dBASE Driver (*.dbf)};DBQ=C:\\; DriverID=533;"
,"","",adConnectUnspecified);
try
{
pRst->Open("USERINFO", _variant_t((IDispatch *) pConn, true),
adOpenStatic, adLockReadOnly, adCmdTable);
FieldsPtr fds=pRst->GetFields();
for(int i=0;i<fds->GetCount();i++)
{
FieldPtr fd=fds->GetItem(_variant_t(short(i)));
MessageBox((LPCTSTR)fd->GetName());
}
pRst->Close();
pConn->Close();
}
catch (_com_error &e)
{
MessageBox("Description = '%s'\n", (char*) e.Description());
}
[/PHP] |
|
2005-02-01
Creating Named Shared Memory (From MSDN: [url]http://msdn.microsoft.com/library/en-us/fileio/base/creating_named_shared_memory.asp?frame=true[/url])
Multiple processes can use memory-mapped files that are backed by the system paging file to share data.
First Process
The first process creates the file mapping object by calling the CreateFileMapping function with INVALID_HANDLE_VALUE and a name for the object. By using the PAGE_READWRITE flag, the process will have read/write permission to the memory through any file views that are created.
The process then uses the file mapping object handle returned by CreateFileMapping in the call to MapViewOfFile to create a view of the file in the process address space. The MapViewOfFile function returns a pointer to the file view.
When the process no longer needs access to the file-mapping object, it should call the CloseHandle function. When all handles are closed, the system can free the section of the paging file used by the object.
[PHP]
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#define BUF_SIZE 256
TCHAR szName[]=TEXT("MyFileMappingObject");
TCHAR szMsg[]=TEXT("Message from first process");
void main()
{
HANDLE hMapFile;
LPCTSTR pBuf;
hMapFile = CreateFileMapping(
INVALID_HANDLE_VALUE, // use paging file
NULL, // default security
PAGE_READWRITE, // read/write access
0, // max. object size
BUF_SIZE, // buffer size
szName); // name of mapping object
if (hMapFile == NULL || hMapFile == INVALID_HANDLE_VALUE)
{
printf("Could not create file mapping object (%d).\n", GetLastError());
return;
}
pBuf = (LPTSTR) MapViewOfFile(hMapFile, // handle to mapping object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
BUF_SIZE);
if (pBuf == NULL)
{
printf("Could not map view of file (%d).\n", GetLastError());
return;
}
CopyMemory((PVOID)pBuf, szMsg, strlen(szMsg));
getch();
UnmapViewOfFile(pBuf);
CloseHandle(hMapFile);
}
[/PHP]
Second Process
A second process can access the same data by calling the OpenFileMapping function with the same name as the first process. It can then use the MapViewOfFile function to obtain a pointer to the file view.
[PHP]
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#define BUF_SIZE 256
TCHAR szName[]=TEXT("MyFileMappingObject");
void main()
{
HANDLE hMapFile;
LPCTSTR pBuf;
hMapFile = OpenFileMapping(
FILE_MAP_ALL_ACCESS, // read/write access
FALSE, // do not inherit the name
szName); // name of mapping object
if (hMapFile == NULL)
{
printf("Could not open file mapping object (%d).\n", GetLastError());
return;
}
pBuf = MapViewOfFile(hMapFile, // handle to mapping object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
BUF_SIZE);
if (pBuf == NULL)
{
printf("Could not map view of file (%d).\n", GetLastError());
return;
}
MessageBox(NULL, pBuf, TEXT("Process2"), MB_OK);
UnmapViewOfFile(pBuf);
CloseHandle(hMapFile);
}
[/PHP] |
Powered by Discuz! Archiver 6.1.0
© 2001-2006 Comsenz Inc.
Processed in 0.007312 second(s), 2 queries |