我正在编写一个具有自定义框架窗口的应用程序。 我访问了这些网站,并使用它们都创建了自己的应用程序:
还有:
我使用TDM_GCC和C语言编写此应用。 该应用成功使用某些链接器进行了编译;但我的自定义框架窗口不可拖动且无法调整大小。 请帮助我解决我的问题。 我的代码如下:
#include <windows.h>
#include <windowsx.h>
#include <winuser.h>
#include <dwmapi.h>
#include <stdbool.h>
const char g_szClassname[] = "myWindowClass";
LRESULT HitTestNCA(HWND hWnd,WPARAM wParam,LPARAM lParam)
{
POINT ptMouse = { GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam)};
RECT rcWindow;
GetWindowRect(hWnd,&rcWindow);
RECT rcFrame = { 0 };
AdjustWindowRectEx(&rcFrame,WS_OVERLAPPedwinDOW & ~WS_CAPTION,false,WS_EX_CLIENTEDGE);
USHORT uRow = 1;
USHORT uCol = 1;
bool fOnResizeBorder = false;
if (ptMouse.y >= rcWindow.top && ptMouse.y < rcWindow.top + 50)
{
fOnResizeBorder = (ptMouse.y < (rcWindow.top - rcFrame.top));
uRow = 0;
}
else if (ptMouse.y < rcWindow.bottom && ptMouse.y >= rcWindow.bottom - 50)
{
uRow = 2;
}
if (ptMouse.x >= rcWindow.left && ptMouse.x < rcWindow.left + 50)
{
uCol = 0; // left side
}
else if (ptMouse.x < rcWindow.right && ptMouse.x >= rcWindow.right - 50)
{
uCol = 2; // right side
}
LRESULT hitTests[3][3] =
{
{ HTTOPLEFT,fOnResizeBorder ? HTTOP : HTCAPTION,HTTOPRIGHT },{ HTLEFT,HTNOWHERE,HTRIGHT },{ HTBOTTOMLEFT,HTBOTTOM,HTBOTTOMRIGHT },};
return hitTests[uRow][uCol];
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,LPARAM lParam)
{
MARGINS m = {50,50,50};
bool f = false;
LRESULT l = 0;
HRESULT hr = S_OK;
RECT rcClient;
if(msg == WM_actIVATE){
hr = DwmExtendFrameIntoClientArea(hwnd,&m);
f = true;
l = 0;
}
if(msg == WM_NCCALCSIZE){
wParam = true;
return 0;
}
if(msg == WM_CREATE){
GetWindowRect(hwnd,&rcClient);
setwindowpos(hwnd,NULL,rcClient.left,rcClient.top,800,600,SWP_FRAMECHANGED);
f = true;
l = 0;
}
if ((msg == WM_NCHITTEST) && (l == 0)){
l = HitTestNCA(hwnd,wParam,lParam);
if (l != HTNOWHERE)
f = false;
}
return DefWindowProc(hwnd,msg,lParam);
}
int WINAPI Winmain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)(NULL_PEN);
wc.lpszMenuName = NULL;
wc.lpszClassname = g_szClassname;
wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL,"Window Registration Failed!","Error!",MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,g_szClassname,"The title of my window",WS_OVERLAPPedwinDOW,CW_USEDEFAULT,hInstance,NULL);
if(hwnd == NULL)
{
MessageBox(NULL,"Window Creation Failed!",MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
// Step 3: The Message Loop
while(GetMessage(&Msg,0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
我的项目在zip文件中: