c++ - WM_CTLCOLORSTATIC "Access is Denied",C++ WINAPI

标签 c++ winapi system-error

<分区>

你好,
我使用 ResEdit 创建了一个无模式对话框,以准确模拟 Windows 的颜色选择对话框的功能,该对话框存在于默认的 Windows“画图”应用程序中。
我这样做是作为我的 C++ WINAPI 研究的一部分。
(见此处:http://i233.photobucket.com/albums/ee74/Lightfooted/Public/colorDialog.jpg)

我目前遇到的问题是,我似乎无法在“WM_CTLCOLORSTATIC”处理期间为“PictureBox”控件的背景着色。我不知道为什么,但是,当我尝试处理 WM_CTLCOLORSTATIC 时,我收到系统错误消息“访问被拒绝”。

我的代码是这样的:

DWORD   dwLastError;
TCHAR   lpBuffer[256];

switch(msg)
{

[...]

case WM_CTLCOLORSTATIC:

if(dwLastError != 0)    // Don't want to see a "operation done successfully" error ;-)
::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,                 // It´s a system error
                 NULL,                                      // No string to be formatted needed
                 dwLastError,                               // Hey Windows: Please explain this error!
                 MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),  // Do it in the standard language
                 lpBuffer,              // Put the message here
                 lpBuffer -1,                     // Number of bytes to store the message
                 NULL);
[...]
}

甚至没有任何“包含 WM_CTLCOLORSTATIC”的内容,我收到系统错误“访问被拒绝”作为响应。

我不知道是什么原因造成的。

最佳答案

这里是错误:

 lpBuffer -1,     

将其更改为 sizeof(lpBuffer)/sizeof(TCHAR) - 1

关于c++ - WM_CTLCOLORSTATIC "Access is Denied",C++ WINAPI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20907764/

相关文章:

c++ - CMFCButton.SetToolTip() 崩溃

c++ - 什么是 Windows 工具包以及它们如何工作?

c++ - 在与父进程相同的监视器上运行进程

c++ - SSL_shutdown() 返回 -1 且 errno 为 0

c++ - 如何在自定义 TensorFlow C++ 操作中调用 sgemm

c++ - 带有 qList 引用的构造函数,它是如何工作的?

file - POSIX O_DIRECT 与 Windows FILE_FLAG_WRITE_THROUGH & FILE_FLAG_NO_BUFFERING

c++ - Boost::file_system:检查错误代码

java - 程序 'java.ori' 收到 X Window 系统错误

c++ - 如何从 Armadillo 矩阵中替换 NaN?