请问在非MFC程序中怎么调用系统控件?
我觉得应该可以的,MFC毕竟是Win32的包装么,但具体怎么实现有没有人试过,讲讲该怎么做?
[解决办法]
用com的方法实现.
[解决办法]
比如tree view control
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/treeview/treeview.asp
// CreateATreeView - creates a tree-view control.
// Returns the handle to the new control if successful,
// or NULL otherwise.
// hwndParent - handle to the control 's parent window.
// lpszFileName - name of the file to parse for tree-view items.
HWND CreateATreeView(HWND hwndParent, LPSTR lpszFileName)
{
RECT rcClient; // dimensions of client area
HWND hwndTV; // handle to tree-view control
// Ensure that the common control DLL is loaded.
InitCommonControls();
// Get the dimensions of the parent window 's client area, and create
// the tree-view control.
GetClientRect(hwndParent, &rcClient);
hwndTV = CreateWindowEx(0,
WC_TREEVIEW,
"Tree View ",
WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES,
0,
0,
rcClient.right,
rcClient.bottom,
hwndParent,
(HMENU)ID_TREEVIEW,
g_hinst,
NULL);
// Initialize the image list, and add items to the control.
// InitTreeViewImageLists and InitTreeViewItems are application-
// defined functions.
if (!InitTreeViewImageLists(hwndTV) ||
!InitTreeViewItems(hwndTV, lpszFileName))
{
DestroyWindow(hwndTV);
return FALSE;
}
return hwndTV;
}
[解决办法]
调用的是系统控件当然是可以的,这些控件又不是MFC专用的,不过在SDK下调这些控件比较烦,首先要知道类名,才能用CreateWindowEx来创建出来。有的可能还要在创建之前初始化。
[解决办法]
最好的办法是:
打开一个相似的窗口(别人已做好的程序),然后用spy++查看,最后CreateWindowEx,把从spy++中获取到的参数填入CreateWindowEx的相应字段,就做好了。
其实可能需要调用一些初始化函数,如楼上说的InitCommonControls();等。
[解决办法]
#import directive很方便,不过你要花点时间学习一下
msdn2.microsoft.com/en-us/library/8etzzkb6.aspx