|
-
Sep 21st, 2001, 05:33 PM
#1
Thread Starter
Frenzied Member
Subclass Help
Can you tell why this code doesn't subclass the window?
Code:
#include <windows.h>
#define WIN32_LEAN_AND_MEAN
static HINSTANCE hInstance = NULL;
char szClassName[] = "StartButton";
HWND hwndTask;
HWND hwndStart;
WNDPROC wpOldStBtnProc;
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam);
LRESULT APIENTRY wpNewStBtnProc(HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam);
// main window procedure
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszArgument, int nCmdShow){
HWND hwnd; // main window handle
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wincl.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
if(!RegisterClassEx(&wincl)) return 0;
hwnd = CreateWindowEx(0, szClassName, "Start Button", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
HWND_DESKTOP, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
while(GetMessage(&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
// callback procedure
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam){
switch(message){
case WM_CREATE:
hwndTask = FindWindowEx(0, 0, "Shell_TrayWnd", 0);
hwndStart = FindWindowEx(hwndTask, 0, "Button", 0);
if(hwndStart != NULL){
wpOldStBtnProc = (WNDPROC) SetWindowLong(hwndStart,
GWL_WNDPROC, (LONG) wpNewStBtnProc);
}
else{
MessageBox(NULL, "Failed to Subclass!", "Error", NULL);
}
break;
case WM_COMMAND:
break;
case WM_DESTROY:
SetWindowLong(hwndStart, GWL_WNDPROC,
(LONG) wpOldStBtnProc);
DestroyWindow(hwnd);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
// Subclass procedure
// IS NOT WORKING
LRESULT APIENTRY wpNewStBtnProc(HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
MessageBox(NULL, "New procedure", "Success", NULL);
return CallWindowProc(wpOldStBtnProc, hwnd, message, wParam, lParam);
}
-
Sep 21st, 2001, 05:35 PM
#2
Monday Morning Lunatic
It needs to be in a DLL, because the protected memory space of your program is separate to the shell.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 21st, 2001, 05:40 PM
#3
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|