2个回答
展开全部
跟普通函数声明差不多啊.只要在命名空间里声明就行了.
几乎跟普通函数一样的.放在头文件里.然后其他类就可以用了.
那我就写一下,没有编译,只写下怎么用...:
//XX1.cpp,命名空间内的函数实现
namespace WinApp
{
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
return DefWindowProc(hWnd, message, wParam, lParam);
}
ATOM RegisterClass(HINSTANCE hinst,LPCTSTR szWindowClass)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hinst;...
...
return RegisterClassEx(&wcex);
}
HWND InitInstance(HINSTANCE hinst,LPCTSTR szWindowClass,LPCTSTR szTitle)
{
return CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, 800, 600, NULL, NULL, hinst, NULL);
}
}//namespace WinApp
//XX1.h命名空间内的函数声明
namespace WinApp
{
ATOM RegisterClass(HINSTANCE hinst,LPCTSTR szWindowClass);
HWND InitInstance(HINSTANCE hinst,LPCTSTR szWindowClass,LPCTSTR szTitle);
}
//XX2.cpp
#include "XX1.h"
namespace WinApp
{
class start //同一个命名空间
{
static void start(HINSTANCE hInstance)
{
m_instance = hInstance;
RegisterClass(hInstance,"win"); //调用命名空间内的函数
HWND hwnd = InitInstance(hInstance,"win","hello world");
}
...
}//class start
}//namespace WinApp
这是我随便写的啊.主要你给你看怎么用的.
几乎跟普通函数一样的.放在头文件里.然后其他类就可以用了.
那我就写一下,没有编译,只写下怎么用...:
//XX1.cpp,命名空间内的函数实现
namespace WinApp
{
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
return DefWindowProc(hWnd, message, wParam, lParam);
}
ATOM RegisterClass(HINSTANCE hinst,LPCTSTR szWindowClass)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hinst;...
...
return RegisterClassEx(&wcex);
}
HWND InitInstance(HINSTANCE hinst,LPCTSTR szWindowClass,LPCTSTR szTitle)
{
return CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, 800, 600, NULL, NULL, hinst, NULL);
}
}//namespace WinApp
//XX1.h命名空间内的函数声明
namespace WinApp
{
ATOM RegisterClass(HINSTANCE hinst,LPCTSTR szWindowClass);
HWND InitInstance(HINSTANCE hinst,LPCTSTR szWindowClass,LPCTSTR szTitle);
}
//XX2.cpp
#include "XX1.h"
namespace WinApp
{
class start //同一个命名空间
{
static void start(HINSTANCE hInstance)
{
m_instance = hInstance;
RegisterClass(hInstance,"win"); //调用命名空间内的函数
HWND hwnd = InitInstance(hInstance,"win","hello world");
}
...
}//class start
}//namespace WinApp
这是我随便写的啊.主要你给你看怎么用的.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询