WM_CTLCOLORSTATIC "Access is Denied", C++ WINAPI

149 views Asked by At

Hey there,
I've created a Modeless Dialog using ResEdit to mimic exactly the function of the Window's Color Select dialog, that is present in the default Windows "Paint" application.
I'm doing this as part of my C++ WINAPI studies.
(Seen here: http://i233.photobucket.com/albums/ee74/Lightfooted/Public/colorDialog.jpg)

The issue that I'm currently stumped at is, I cannot seem to color the backgrounds of the "PictureBox" controls during "WM_CTLCOLORSTATIC" handling. I don't know why but, the moment I try to handle WM_CTLCOLORSTATIC I get the system-error message "Access is Denied".

My Code looks like this:

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);
[...]
}

There isn't even anything "incase of WM_CTLCOLORSTATIC" and I am getting the system-error "Access is Denied" in response.

I have no clue what is causing this.

1

There are 1 answers

0
marcinj On

Here is error:

 lpBuffer -1,     

change it to sizeof(lpBuffer)/sizeof(TCHAR) - 1