| | |
Repaint window help?
![]() |
•
•
Join Date: Oct 2008
Posts: 9
Reputation:
Solved Threads: 0
I'm currently working on a project that manages multiple notepad windows in a MDI client area. It runs just as I want it to, except that the notepad windows seem to freeze up and become glitchy inside of the parent window. I was told to look into using InvalidateRect, but i'm not sure how to implement it into my program. Here is my code, I would appreciate any help.
C++ Syntax (Toggle Plain Text)
#include <windows.h> #include <tchar.h> const char ClassName[] = "WndClassName"; int counter = 0; HWND notepad; HWND notepad2; HWND notepad3; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CLOSE: { DestroyWindow(hwnd); } break; case WM_CREATE: { STARTUPINFO si; PROCESS_INFORMATION pi; TCHAR tszCommandLine[500]; // Initialize the startup info struct GetStartupInfo(&si); // Call CreateProcess(), mostly defaults. Note that // the lpCommandLine argument MUST NOT be a constant string. _tcscpy(tszCommandLine, _T("notepad")); for(int a=0; a<3; a++){ CreateProcess(NULL, tszCommandLine, NULL, NULL, FALSE, NULL, NULL, NULL, &si, &pi); } while(!notepad && counter < 10) { counter+=1; DWORD dwMilliseconds = 1000; // create DWORD type variable to hold delay time in milliseconds Sleep ( dwMilliseconds ); // Sleep for that number of msecs, note bold! notepad = FindWindow("Notepad", NULL); } // Check if notepad exists if (!notepad) { MessageBox(hwnd, "Notepad not open, closing", "Error", MB_OK | MB_ICONERROR); DestroyWindow(hwnd); } // Set it as a child window SetParent(notepad, hwnd); // Resize and position it to make it visible SetWindowPos(notepad, NULL, 0, 0, 650, 700, NULL); while(!notepad2 && counter < 10) { counter+=1; DWORD dwMilliseconds = 1000; // create DWORD type variable to hold delay time in milliseconds Sleep ( dwMilliseconds ); // Sleep for that number of msecs, note bold! notepad2 = FindWindow("Notepad", NULL); } // Check if notepad exists if (!notepad2) { MessageBox(hwnd, "Notepad not open, closing", "Error", MB_OK | MB_ICONERROR); DestroyWindow(hwnd); } notepad2 = FindWindow("Notepad", NULL); // Set it as a child window SetParent(notepad2, hwnd); // Resize and position it to make it visible SetWindowPos(notepad2, NULL, 650, 100, 650, 700, NULL); while(!notepad3 && counter < 15) { counter+=1; DWORD dwMilliseconds = 1000; // create DWORD type variable to hold delay time in milliseconds Sleep ( dwMilliseconds ); // Sleep for that number of msecs, note bold! notepad3 = FindWindow("Notepad", NULL); } // Check if notepad exists if (!notepad3) { MessageBox(hwnd, "Notepad not open, closing", "Error", MB_OK | MB_ICONERROR); DestroyWindow(hwnd); } notepad3 = FindWindow("Notepad", NULL); // Set it as a child window SetParent(notepad3, hwnd); // Resize and position it to make it visible SetWindowPos(notepad3, NULL, 650, 0, 600, 100, NULL); } break; case WM_DESTROY: { PostQuitMessage(0); } break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { HWND hwnd; WNDCLASSEX wc; MSG msg; wc.cbWndExtra = 0; wc.cbClsExtra = 0; wc.cbSize = sizeof WNDCLASSEX; wc.hbrBackground = (HBRUSH) COLOR_WINDOW; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.lpszClassName = ClassName; wc.lpszMenuName = NULL; wc.style = 0; if (!RegisterClassEx(&wc)) { return 1; } hwnd = CreateWindowEx( WS_EX_APPWINDOW, ClassName, "Notepad Manager", WS_MINIMIZEBOX | WS_MAXIMIZEBOX| WS_SYSMENU | WS_CAPTION | WS_THICKFRAME, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if (!hwnd) { return 1; } ShowWindow(hwnd, nShowCmd); UpdateWindow(hwnd); while (GetMessage(&msg, NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } return static_cast<int>( msg.wParam ); }
•
•
Join Date: Mar 2008
Posts: 1,383
Reputation:
Solved Threads: 112
Now that i've had a better look at what you've got sofar, a way I think you could go about fixing this problem is by using the WM_ERASEBKGND message. By doing that all the notepad windows will be painted perfectly.
However, you are going to have to manually paint only the parts of the main window which don't have a notepad window over it (which may be harder than it sounds). I will see what I can do
However, you are going to have to manually paint only the parts of the main window which don't have a notepad window over it (which may be harder than it sounds).
#include <windows.h>
#include <tchar.h>
const char ClassName[] = "WndClassName";
int counter = 0;
HWND notepad;
HWND notepad2;
HWND notepad3;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_ERASEBKGND:
{
// Overridden
}
break;
case WM_CLOSE:
{
DestroyWindow(hwnd);
}
break;
[..rest of code...]
•
•
Join Date: Nov 2008
Posts: 3
Reputation:
Solved Threads: 0
First: you should add WS_CLIPCHILDREN and WS_CLIPSIBLINGS as window styles for main frame.
Second: to set notepad windows as child its not efficient to only set parent. You should also change notepad windows style to WS_CHILD using SetWindowLong function.
Here is the modified code. It almost works fine. Consider the WM_SIZE message. There could be a better way to handle WM_SIZE message instead of redrawing all window.
Second: to set notepad windows as child its not efficient to only set parent. You should also change notepad windows style to WS_CHILD using SetWindowLong function.
Here is the modified code. It almost works fine. Consider the WM_SIZE message. There could be a better way to handle WM_SIZE message instead of redrawing all window.
C++ Syntax (Toggle Plain Text)
const char ClassName[] = "WndClassName"; int counter = 0; HWND notepad; HWND notepad2; HWND notepad3; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CLOSE: { DestroyWindow(hwnd); } break; case WM_CREATE: { STARTUPINFO si; PROCESS_INFORMATION pi; TCHAR tszCommandLine[500]; // Initialize the startup info struct GetStartupInfo(&si); // Call CreateProcess(), mostly defaults. Note that // the lpCommandLine argument MUST NOT be a constant string. _tcscpy(tszCommandLine, _T("notepad")); for(int a=0; a<3; a++){ CreateProcess(NULL, tszCommandLine, NULL, NULL, FALSE, NULL, NULL, NULL, &si, &pi); } while(!notepad && counter < 10) { counter+=1; DWORD dwMilliseconds = 1000; // create DWORD type variable to hold delay time in milliseconds Sleep ( dwMilliseconds ); // Sleep for that number of msecs, note bold! notepad = FindWindow("Notepad", NULL); } // Check if notepad exists if (!notepad) { MessageBox(hwnd, "Notepad not open, closing", "Error", MB_OK | MB_ICONERROR); DestroyWindow(hwnd); } // Set it as a child window SetParent(notepad, hwnd); SetWindowLong(notepad, GWL_STYLE, GetWindowLong(notepad, GWL_STYLE) | WS_CHILD); // Resize and position it to make it visible SetWindowPos(notepad, NULL, 0, 0, 650, 700, NULL); while(!notepad2 && counter < 10) { counter+=1; DWORD dwMilliseconds = 1000; // create DWORD type variable to hold delay time in milliseconds Sleep ( dwMilliseconds ); // Sleep for that number of msecs, note bold! notepad2 = FindWindow("Notepad", NULL); } // Check if notepad exists if (!notepad2) { MessageBox(hwnd, "Notepad not open, closing", "Error", MB_OK | MB_ICONERROR); DestroyWindow(hwnd); } notepad2 = FindWindow("Notepad", NULL); // Set it as a child window SetParent(notepad2, hwnd); SetWindowLong(notepad2, GWL_STYLE, GetWindowLong(notepad2, GWL_STYLE) | WS_CHILD); // Resize and position it to make it visible SetWindowPos(notepad2, NULL, 650, 100, 650, 700, NULL); while(!notepad3 && counter < 15) { counter+=1; DWORD dwMilliseconds = 1000; // create DWORD type variable to hold delay time in milliseconds Sleep ( dwMilliseconds ); // Sleep for that number of msecs, note bold! notepad3 = FindWindow("Notepad", NULL); } // Check if notepad exists if (!notepad3) { MessageBox(hwnd, "Notepad not open, closing", "Error", MB_OK | MB_ICONERROR); DestroyWindow(hwnd); } notepad3 = FindWindow("Notepad", NULL); // Set it as a child window SetParent(notepad3, hwnd); SetWindowLong(notepad3, GWL_STYLE, GetWindowLong(notepad3, GWL_STYLE) | WS_CHILD); // Resize and position it to make it visible SetWindowPos(notepad3, NULL, 650, 0, 600, 100, NULL); } break; case WM_SIZE: InvalidateRect(hwnd, NULL, FALSE); break; case WM_DESTROY: { PostQuitMessage(0); } break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { HWND hwnd; WNDCLASSEX wc; MSG msg; wc.cbWndExtra = 0; wc.cbClsExtra = 0; wc.cbSize = sizeof WNDCLASSEX; wc.hbrBackground = (HBRUSH) COLOR_WINDOW; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.lpszClassName = ClassName; wc.lpszMenuName = NULL; wc.style = 0; if (!RegisterClassEx(&wc)) { return 1; } hwnd = CreateWindowEx( WS_EX_APPWINDOW, ClassName, "Notepad Manager", WS_MINIMIZEBOX | WS_MAXIMIZEBOX| WS_SYSMENU | WS_CAPTION | WS_THICKFRAME | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if (!hwnd) { return 1; } ShowWindow(hwnd, nShowCmd); UpdateWindow(hwnd); while (GetMessage(&msg, NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } return static_cast<int>( msg.wParam ); }
![]() |
Similar Threads
- Error while compiling but not in the code itself???? (Java)
- Applet Help (Java)
- JPanel and putting a Background GIF pic...NOT WORKING (Java)
- "cannot resolve symbol"problem (Java)
- how to do it?? (Java)
- Loading images (Java)
- Spelling Test using a button GUI environment..how do I create a brand new window? (Java)
- Loading images in AWT (Java)
- Refreshing a window (C++)
- W2K screen freeze and icon repaint (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: CIN>>EQUATION (how to then mult by it later)
- Next Thread: program help
| Thread Tools | Search this Thread |
ada api apic++ array backup based binary bitmap c++ c/c++ char class classes code coding compile console conversion count delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file fileread forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math matrix memory multiple news node output parameter pointer pong prime problem program programming project python random read recursion reference rpg set string strings symbian temperature template test text text-file trackbarprogress tree url variable vector video visual web win32 windows winsock wordfrequency wxwidgets






