Hi,
I'm working on developing my win32 api test application.
I've done the tool bar menus. Static and button controls.
Every thing is OK, but the problem is that when I want to print a new content, I still have some stuff from the previous content.
So my question, is how to clear the window before printing new content ?
This is my code:
#include <windows.h>
#include <stdint.h>
#define FILE_MENU_NEW 1 // File menu item to be used as window numbered functions
#define FILE_MENU_OPEN 2 // File menu item to be used as window numbered functions
#define FILE_MENU_EXIT 3 // File menu item to be used as window numbered functions
#define HOME_PAGE 4
#define PAGE1 5
#define PAGE2 6
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
void AddMenus(HWND);
void main_page(HWND hWnd);
void page1(HWND hWnd);
void page2(HWND hWnd);
HMENU hMenu;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR args, int nCmdShow){
WNDCLASSW wc = {0};
wc.hbrBackground = (HBRUSH)COLOR_WINDOW; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hInstance = hInstance; wc.lpszClassName = L"myWindowClass"; wc.lpfnWndProc = WindowProcedure;
if(!RegisterClassW(&wc)){
return -1;
}
CreateWindowW(L"myWindowClass", L"My Window", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 1920/4, 1080/8, 320, 480,
NULL, NULL, NULL, NULL );
MSG msg = {0};
while(GetMessage(&msg, NULL, (uint64_t)NULL, (uint64_t)NULL)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp){
switch(msg){
case WM_COMMAND:
switch(wp){
case FILE_MENU_NEW:
MessageBeep(MB_ICONINFORMATION);
break;
case FILE_MENU_OPEN:
MessageBeep(MB_OK);
break;
case FILE_MENU_EXIT:
break;
case HOME_PAGE:
main_page(hWnd);
break;
case PAGE1:
page1(hWnd);
break;
case PAGE2:
page2(hWnd);
break;
}
break;
case WM_CREATE:
AddMenus(hWnd);
main_page(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_QUIT:
break;
default:
return DefWindowProcW(hWnd, msg, wp, lp);
}
return 0;
}
void AddMenus(HWND hWnd){
hMenu = CreateMenu();
HMENU hFileMenu = CreateMenu();
AppendMenu(hMenu, MF_POPUP, (UINT_PTR)hFileMenu, "File");
AppendMenu(hMenu, MF_STRING, (uint64_t)NULL, "Help");
HMENU hSubMenu = CreateMenu();
AppendMenu(hSubMenu, MF_STRING, (uint64_t)NULL, "New 1");
AppendMenu(hFileMenu, MF_POPUP, (UINT_PTR)hSubMenu, "New");
AppendMenu(hFileMenu, MF_SEPARATOR, (uint64_t)NULL, 0);
AppendMenu(hFileMenu, MF_STRING, FILE_MENU_OPEN, "Open");
AppendMenu(hFileMenu, MF_SEPARATOR, (uint64_t)NULL, 0);
AppendMenu(hFileMenu, MF_STRING, FILE_MENU_EXIT, "Exit");
SetMenu(hWnd, hMenu);
}
void main_page(HWND hWnd){
CreateWindowW(L"Static", L"main page", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER
, 65, 10, 180, 20, hWnd, NULL, NULL, NULL);
CreateWindowW(L"Button", L"Page1", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER
, 65, 50, 180, 30, hWnd, (HMENU)PAGE1, NULL, NULL);
CreateWindowW(L"Button", L"Page2", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER
, 65, 90, 180, 30, hWnd, (HMENU)PAGE2, NULL, NULL);
}
void page1(HWND hWnd){
CreateWindowW(L"Static", L"Page1", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER
, 65, 10, 180, 20, hWnd, NULL, NULL, NULL);
CreateWindowW(L"Button", L"P1 - button1", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER
, 65, 50, 180, 30, hWnd, NULL, NULL, NULL);
CreateWindowW(L"Button", L"P1 - button2", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER
, 65, 90, 180, 30, hWnd, NULL, NULL, NULL);
CreateWindowW(L"Button", L"P1 - button3", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER
, 65, 130, 180, 30, hWnd, NULL, NULL, NULL);
CreateWindowW(L"Button", L"Main Page - P1", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER
, 65, 310, 180, 30, hWnd, (HMENU)HOME_PAGE, NULL, NULL);
}
void page2(HWND hWnd){
CreateWindowW(L"Static", L"Page2", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER
, 65, 10, 180, 20, hWnd, NULL, NULL, NULL);
CreateWindowW(L"Button", L"P2 - button1", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER
, 65, 50, 180, 30, hWnd, NULL, NULL, NULL);
CreateWindowW(L"Button", L"P2 - button2", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER
, 65, 90, 180, 30, hWnd, NULL, NULL, NULL);
CreateWindowW(L"Button", L"P2 - button3", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER
, 65, 130, 180, 30, hWnd, NULL, NULL, NULL);
CreateWindowW(L"Button", L"Main Page - P2", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER
, 65, 310, 180, 30, hWnd, (HMENU)HOME_PAGE, NULL, NULL);
}
What I have tried:
Nothing actually.
I tried to create a new window, but that open a new window to the current one which is not what I want.