C编程HWND

时间:2017-06-10 22:05:40

标签: c winapi hwnd

当我编译我的代码时,应该打开一个窗口,但它不会。我创建了一个类,HWND和应用程序处理程序;依然没有。

我有点新鲜,抱歉这个问题。

应用程序运行良好且没有错误,但似乎没有出现窗口。

$FileList = Get-Content 'C:\File_Names.txt' 
$SrcDir ='\\server\Temp' 
$DstDir ='\\server\Testing' 
Foreach ($File in $FileList) { 
    $SrcFile = Get-ChildItem $SrcDir -Recurse $File -EA SilentlyContinue
    $DstFile = Get-ChildItem $DstDir -Recurse $File -EA SilentlyContinue
    if (($Srcfile.count -eq 1) -and ($DstFile.count -eq 1)){
        Copy-Item $SrcFile $DstFile
    } Else {
        "More/less than one Source and/or Destination file $File"
    }
}

2 个答案:

答案 0 :(得分:1)

立即错误在这一行:

DefWindowProc(regularWnd, message, wparam, lparam);

窗口过程应该返回LRESULT并且DefWindowProc在必要时执行此操作,但是您不会将其传递。将其更改为

return DefWindowProc(regularWnd, message, wparam, lparam);

,您的窗口将按预期显示。

除此之外,并未使用errno,因此perror()无效。您必须使用GetLastError()FormatMessage()来获取有意义的错误消息,并使用WinMain()(强烈建议子系统windows),您将无法使用默认控制台显示它们....

最后,UpdateWindow()完全没必要。

答案 1 :(得分:1)

LRESULT CALLBACK myCallBack(HWND regularWnd, UINT message, WPARAM wparam, LPARAM lparam)
{
    switch (message) {
        case 0x0201:
            printf("left Click");
            MessageBox(regularWnd, "Left Click", "event handler", MB_OK);
            return 0;
        case WM_CLOSE:
            DestroyWindow(regularWnd);
            return 0;
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
    }
    return DefWindowProc(regularWnd, message, wparam, lparam);
}

将您的窗口过程更改为此

另外,使用GetLastErrorFormatMessage打印错误;不是perror,那个或C标准库调用。以下是如何使用此功能的示例

https://msdn.microsoft.com/en-us/library/windows/desktop/ms680582(v=vs.85).aspx