다음 코드를 사용하고 폼을로드하는 동안 창 핸들을 함수에 전달합니다. 문제가 해결되기를 바랍니다.
public void SetFormOnDesktop(IntPtr hwnd)
{
IntPtr hwndf = hwnd;
IntPtr hwndParent = FindWindow("ProgMan", null);
SetParent(hwndf, hwndParent);
}
-------------------
창을 최상위 창으로 설정하면 (
SetWindowPos
및 HWND_TOPMOST 플래그 를 통해 ) 데스크톱이 창을 가리지 못한다는 인상을 받았습니다. Windows + D는 모든 창을 최소화 한 다음 바탕 화면을 z 순서로 올려 최소화 할 수없는 창을 은폐합니다 (음,
어쨌든 한 지점
에서 그랬 습니다 ). WS_MINIMIZEBOX를 CreateWindowEx에 전달하지 않거나 WS_EX_TOOLWINDOW를 사용하여 창을 최소화 할 수 없게 만들 수 있습니다.훨씬 더 무거운 방법은 SetWindowsHookEx 및 KeyboardProc를 사용하여 전역 키보드를 연결하는 것입니다. 이것은 사용자 경험에 해로운 영향을 미칩니다.
저는 가서 제가 말하는 것에 대한 아주 간단한 예를 작성했습니다. 다음 코드는 최소화되지 않거나 사용자가 Windows + D를 눌렀을 때 가려지지 않는 창을 만듭니다. Windows 7에서는 데스크톱의 가젯을 여전히 그 위에 가져올 수 있습니다. 정말 설명 할 수 없습니다.
#include <windows.h>
#include <tchar.h>
#define WIN_TITLE _T("Resists Win+D Window")
#define WIN_CLASS _T("Resists Win+D Class")
LRESULT CALLBACK CustomWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
//Special behavior goes here
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
HWND CreateMainWindow(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = CustomWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = WIN_CLASS;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
if (!RegisterClassEx(&wcex))
{
exit(1);
}
HWND hWnd = CreateWindowEx(
WS_EX_TOOLWINDOW,
WIN_CLASS,
WIN_TITLE,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
500,
100,
NULL,
NULL,
hInstance,
NULL
);
if (!hWnd)
{
exit(1);
}
return hWnd;
}
/*
Main entry point
*/
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hwnd = CreateMainWindow(hInstance);
ShowWindow(hwnd, nCmdShow);
SetWindowPos(hwnd, HWND_TOPMOST, -1, -1, -1, -1, SWP_NOMOVE | SWP_NOSIZE);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
-------------------
ABN_FULLSCREENAPP 알림에서 작업 영역을 차지하는 창이 데스크톱인지 여부를 확인해야합니다. 그렇다면 ABN_FULLSCREENAPP 메시지를 무시하십시오.PS 대체 구현으로 상용
ShellAppBar
구성 요소를 고려하십시오 .-------------------
JKS
의 답변 외에도 양식을 이미 앱 바로 변환했다고 가정하는 VB.NET의 작업 코드가 있습니다. 함수
FindWindow
및
SetFormOnDesktop
.
'In your form
Public Sub New()
'Stuff
SetFormOnDesktop(Me.Handle)
'More stuff
End Sub
'In your form or somewhere else.
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Shared Function SetParent(_
ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
End Function
Public Sub SetFormOnDesktop(hwnd As IntPtr)
Dim hwndf As IntPtr = hwnd
Dim hwndParent As IntPtr = FindWindow("ProgMan", Nothing)
SetParent(hwndf, hwndParent)
End Sub
출처
https://stackoverflow.com/questions/2005978