eagle
New Member
- Joined
- Dec 8, 2023
- Messages
- 3
- Thread Author
- #1
Hi,
I'm trying to develop a simple project on a win32 api using C compiler.
I've been trying to draw multiple pages on the same window object, and whenever I press a button, it redraw the new page. But it turned out that win32 programming is much complex than I thought.
The problem is that the page isn't erased
My complete code, in the attachment.
Also I want to understand the main functionality of "WindowProcedure" and how it works.
There are different tools and I don't know how to use them correctly. And whether I should use one rather than the other. Like:
Also how I should use "WM_PAINT", and whether I should use it or not according to my project application.
For example:
Here's my "WindowProcedure" content:
As in the above code, I tried to run the page functions either in "WM_COMMAND" and "WM_PAINT", but couldn't solve this issue.
I'm trying to develop a simple project on a win32 api using C compiler.
I've been trying to draw multiple pages on the same window object, and whenever I press a button, it redraw the new page. But it turned out that win32 programming is much complex than I thought.
The problem is that the page isn't erased
My complete code, in the attachment.
Also I want to understand the main functionality of "WindowProcedure" and how it works.
There are different tools and I don't know how to use them correctly. And whether I should use one rather than the other. Like:
InvalidateRect(hWnd, NULL, TRUE);
UpdateWindow(hWnd);
Also how I should use "WM_PAINT", and whether I should use it or not according to my project application.
For example:
Here's my "WindowProcedure" content:
C:
#include <windows.h>
#include <stdint.h>
#include <stdbool.h>
#include "system_setup.h"
#include "control_page.h"
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp){
static int current_page = 0;
switch(msg){
case WM_COMMAND:
switch(wp){
case HOME_PAGE:
InvalidateRect(hWnd, NULL, TRUE);
main_menu_page(hWnd);
UpdateWindow(hWnd);
break;
case MOTORS_PAGE:
InvalidateRect(hWnd, NULL, TRUE);
motors_page(hWnd);
UpdateWindow(hWnd);
break;
case ELECTRICAL_PAGE:
InvalidateRect(hWnd, NULL, TRUE);
electrical_page(hWnd);
UpdateWindow(hWnd);
break;
case WEATHER_PAGE:
InvalidateRect(hWnd, NULL, TRUE);
weather_page(hWnd);
UpdateWindow(hWnd);
break;
case LED_CONTROL_PAGE:
InvalidateRect(hWnd, NULL, TRUE);
led_control_page(hWnd);
UpdateWindow(hWnd);
break;
case SERVO_MOTOR_PAGE:
InvalidateRect(hWnd, NULL, TRUE);
servo_motor_page(hWnd);
UpdateWindow(hWnd);
break;
case DC_MOTOR_PAGE:
InvalidateRect(hWnd, NULL, TRUE);
dc_motor_page(hWnd);
UpdateWindow(hWnd);
break;
}
break;
case WM_CREATE:
main_menu_page(hWnd);
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
// switch (current_page) {
// case HOME_PAGE:
// main_menu_page(hWnd);
// break;
// case MOTORS_PAGE:
// motors_page(hWnd);
// break;
// case ELECTRICAL_PAGE:
// electrical_page(hWnd);
// break;
// case WEATHER_PAGE:
// weather_page(hWnd);
// break;
// case LED_CONTROL_PAGE:
// led_control_page(hWnd);
// break;
// case SERVO_MOTOR_PAGE:
// servo_motor_page(hWnd);
// break;
// case DC_MOTOR_PAGE:
// dc_motor_page(hWnd);
// break;
// }
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_QUIT:
break;
default:
return DefWindowProcW(hWnd, msg, wp, lp);
}
return 0;
}
As in the above code, I tried to run the page functions either in "WM_COMMAND" and "WM_PAINT", but couldn't solve this issue.