Click here to Skip to main content
15,949,741 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionMFC ActiveX Creation? Pin
spalanivel27-Sep-07 21:23
spalanivel27-Sep-07 21:23 
AnswerRe: MFC ActiveX Creation? Pin
chandu00427-Sep-07 22:51
chandu00427-Sep-07 22:51 
Questiona problem about std::string new and delete,Help Pin
kcynic27-Sep-07 21:00
kcynic27-Sep-07 21:00 
AnswerRe: a problem about std::string new and delete,Help Pin
Cedric Moonen27-Sep-07 21:06
Cedric Moonen27-Sep-07 21:06 
GeneralRe: a problem about std::string new and delete,Help Pin
kcynic27-Sep-07 21:15
kcynic27-Sep-07 21:15 
GeneralRe: a problem about std::string new and delete,Help Pin
Cedric Moonen27-Sep-07 21:17
Cedric Moonen27-Sep-07 21:17 
GeneralRe: a problem about std::string new and delete,Help Pin
kcynic27-Sep-07 21:36
kcynic27-Sep-07 21:36 
QuestionCannot max/min untitled dialog box Pin
champ2327-Sep-07 19:46
champ2327-Sep-07 19:46 
I have done an untitled dialog box in MFC,
Clicking on this dialog button on taskbar, window does not minimize or maximize.
To handle this i have written code in OnNcActivate message.
My problem is that, when i say ShowWindow(SW_SHOWNORMAL); at that time the window
is shown but again it gets minimized. It does not get hold.
Please try the code, let me know what is the problem.

Here is the following code
BOOL CRestoreDlg::OnNcActivate(BOOL bActive)
{
BOOL b2 = FALSE;
TBBUTTON tbButton;
HWND hWndBut = NULL;
WINDOWPLACEMENT wndpl;
HANDLE hProcess = NULL;
LPVOID lpRemoteBuffer = NULL;
DWORD dwProcessId = 0, dwThreadId = 0;

memset(&wndpl, 0, sizeof(WINDOWPLACEMENT));
memset(&tbButton, 0, sizeof(TBBUTTON));

GetWindowPlacement(&wndpl);
HWND hDesktop = ::GetDesktopWindow();
HWND hTray = ::FindWindowEx(hDesktop , 0, _T("Shell_TrayWnd"), NULL);
HWND hReBar = ::FindWindowEx(hTray, 0, _T("ReBarWindow32"), NULL);
HWND hTask = ::FindWindowEx(hReBar, 0, _T("MSTaskSwWClass"), NULL);
HWND hToolbar = ::FindWindowEx(hTask, 0, _T("ToolbarWindow32") , NULL);

// obtain the count of buttons on toolbar
LRESULT count = ::SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0);

// obtain taskbar process id - by window
dwThreadId = GetWindowThreadProcessId(hToolbar, &dwProcessId);

// open taskbar process
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);
if (NULL == hProcess)
{
return FALSE;
}

// for loop to recognize our application button on task bar
for (int i= 0 ; i < count ; i++ )
{
memset(&tbButton, 0, sizeof(TBBUTTON));

lpRemoteBuffer = VirtualAllocEx(hProcess, NULL, sizeof(TBBUTTON), MEM_COMMIT, PAGE_READWRITE);
if (NULL == lpRemoteBuffer)
{
return FALSE;
}

// get button info
::SendMessage(hToolbar, TB_GETBUTTON, i, (LPARAM)lpRemoteBuffer);

b2 = ReadProcessMemory(
hProcess,
lpRemoteBuffer,
(LPVOID)&tbButton,
sizeof(TBBUTTON),
NULL);
if (FALSE == b2)
{
return FALSE;
}

// Retrieve window handle of pressed btn
BYTE localBuffer[BUFFER_SIZE];
BYTE* pLocalBuffer = localBuffer;
DWORD_PTR ipLocalBuffer = (DWORD_PTR)pLocalBuffer;

// window handle
pLocalBuffer = localBuffer;
ipLocalBuffer = (DWORD_PTR)pLocalBuffer;

// initialize remote buffer
DWORD_PTR lpRemoteData = (DWORD_PTR)tbButton.dwData;

// and read the dwData fields of a TBBUTTON from remote process
ReadProcessMemory(hProcess, (LPVOID)lpRemoteData, (LPVOID)ipLocalBuffer, sizeof(DWORD_PTR), NULL);

// obtain window handle
// copy first 4 bytes

HWND windowHandle;
memcpy(&windowHandle, (void *)ipLocalBuffer, 4);

if (windowHandle == m_hWnd)
{
if (tbButton.fsState & TBSTATE_PRESSED)
{
if (wndpl.showCmd == SW_SHOWMINIMIZED)
{
ShowWindow(SW_SHOWNORMAL);
//wndpl.showCmd = SW_SHOWNORMAL; 
//SetWindowPlacement(&wndpl);
}
else if (wndpl.showCmd == SW_SHOWNORMAL)
{
ShowWindow(SW_SHOWMINIMIZED);
//wndpl.showCmd = SW_SHOWMINIMIZED; 
//SetWindowPlacement(&wndpl);
}
}
}


VirtualFreeEx(hProcess, lpRemoteBuffer, 0, MEM_RELEASE);
}

CloseHandle(hProcess);

return TRUE;
}

AnswerRe: Cannot max/min untitled dialog box Pin
Naveen27-Sep-07 21:08
Naveen27-Sep-07 21:08 
GeneralRe: Cannot max/min untitled dialog box Pin
champ2327-Sep-07 22:29
champ2327-Sep-07 22:29 
GeneralRe: Cannot max/min untitled dialog box Pin
Naveen27-Sep-07 23:07
Naveen27-Sep-07 23:07 
GeneralRe: Cannot max/min untitled dialog box Pin
champ2328-Sep-07 1:05
champ2328-Sep-07 1:05 
GeneralRe: Cannot max/min untitled dialog box Pin
champ2328-Sep-07 1:07
champ2328-Sep-07 1:07 
QuestionOne message Box at a time Pin
neha.agarwal2727-Sep-07 19:42
neha.agarwal2727-Sep-07 19:42 
AnswerRe: One message Box at a time Pin
Nishad S27-Sep-07 19:56
Nishad S27-Sep-07 19:56 
QuestionRe: One message Box at a time Pin
David Crow28-Sep-07 2:48
David Crow28-Sep-07 2:48 
QuestionModem to PC through RS-232 Pin
krishna Vuppala27-Sep-07 19:29
krishna Vuppala27-Sep-07 19:29 
AnswerRe: Modem to PC through RS-232 Pin
Cedric Moonen27-Sep-07 20:22
Cedric Moonen27-Sep-07 20:22 
GeneralRe: Modem to PC through RS-232 Pin
krishna Vuppala27-Sep-07 21:22
krishna Vuppala27-Sep-07 21:22 
GeneralRe: Modem to PC through RS-232 Pin
Cedric Moonen27-Sep-07 21:27
Cedric Moonen27-Sep-07 21:27 
GeneralRe: Modem to PC through RS-232 Pin
David Crow28-Sep-07 2:49
David Crow28-Sep-07 2:49 
Answerwant ur help please Pin
p_27-Sep-07 20:34
p_27-Sep-07 20:34 
GeneralRe: want ur help please Pin
krishna Vuppala27-Sep-07 21:28
krishna Vuppala27-Sep-07 21:28 
AnswerRe: Modem to PC through RS-232 Pin
ghle27-Sep-07 21:09
ghle27-Sep-07 21:09 
QuestionSimple ESC Key Pin
Michael10127-Sep-07 19:15
Michael10127-Sep-07 19:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.