Author Topic: Compliation fail using DECLARE LIBRARY  (Read 4708 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Compliation fail using DECLARE LIBRARY
« on: January 14, 2019, 01:45:39 pm »
Trying to pull things off beyond my skill set.
I know where the error is but not how to fix it.
I'm 95% sure its in the DECLARE LIBRARY but not sure how to correct it.

Code: QB64: [Select]
  1. 'Master Control Program (MCP)
  2. '2019/01/06
  3. 'Monitor for and Shut down Youtube access
  4. _DELAY .025
  5. _TITLE "MCP"
  6. _DELAY .25
  7.  
  8. TYPE LPpoint
  9.  Mx AS LONG
  10.  My AS LONG
  11.  
  12. TYPE Rectangle
  13.  left AS LONG
  14.  top AS LONG
  15.  right AS LONG
  16.  bottom AS LONG
  17.  
  18. DIM Rec AS Rectangle, Mp AS LPpoint
  19. DIM SHARED RF AS Rectangle, Dx&, Dy&
  20.  
  21. _SCREENHIDE 'makes the program invisible to the user. Escape key displays log!
  22. DECLARE LIBRARY 'function is already used by QB64 so "User32" is not required
  23.  FUNCTION GetAsyncKeyState% (BYVAL vkey AS LONG)
  24.  FUNCTION GetWindowRect% (BYVAL Hwnd AS LONG, Rect AS Rectangle)
  25.  FUNCTION GetCursorPos% (Mpoint AS LPpoint)
  26.  
  27. CONST TRUE = -1, FALSE = NOT TRUE
  28. Test& = _SCREENIMAGE 'get desktop screen
  29. temp& = _NEWIMAGE(640, 480, 32)
  30. _SOURCE Test&
  31.  
  32.  Test& = _SCREENIMAGE 'get desktop screen
  33.  _LIMIT 60
  34.  IF Find_Red(Test&) THEN
  35.  
  36.   RF.top = Shift_UP(RF.top) 'correct start search pos
  37.   RF.left = Shift_LEFT(RF.left)
  38.  
  39.   Tube_Found% = Check_Tube(Test&)
  40.  
  41.  IF Tube_Found% > 80 AND Tube_Found% < 95 THEN
  42.   IF Tube_Found% = 92 THEN Exact%% = TRUE ELSE Exact%% = FALSE
  43.  
  44.  IF GetCursorPos(Mp) THEN 'get current mouse Position to restore when finished
  45.    tempX% = Mp.Mx: tempY% = Mp.My
  46.   END IF
  47.  
  48.   _SCREENCLICK RF.left, RF.top, 2
  49.   _DELAY .05
  50.   '  _MOUSEMOVE temp_X%, temp_Y%
  51.   exitflag%% = TRUE
  52.   _DELAY .15
  53.  IF GetAsyncKeyState(&H1B) THEN
  54.   theitem$(a) = theitem$(a) + "{ESC}"
  55.   exitflag%% = TRUE 'ESC key exits loop
  56. LOOP UNTIL exitflag%%
  57.  
  58. 'SYSTEM
  59. 'SCREEN temp&
  60. '_PUTIMAGE (0, 0)-(320, 200), Test&, _DISPLAY, (0, 0)-(320, 200)
  61. 'LINE (RF.left, RF.top)-(RF.left + 10, RF.top + 10), _RGB32(255, 255, 0), B
  62. PRINT Tube_Found%, Exact%%; tempX%, tempX%
  63.  
  64. FUNCTION Find_Red%% (Handle&)
  65.  Result%% = FALSE
  66.  FOR y% = 1 TO Dy& STEP 3
  67.   FOR x% = 1 TO Dx& STEP 3
  68.    Colr~& = POINT(x%, y%)
  69.    IF _RED32(Colr~&) > 250 AND _BLUE32(Colr~&) < 16 AND _GREEN32(Colr~&) < 16 THEN
  70.     Result%% = TRUE: RF.top = y%: RF.left = x% 'store where the red was found
  71.     x% = Dx& + 1: y% = Dy& + 1 'exit loops upon a find
  72.    END IF
  73.   NEXT x%
  74.  NEXT y%
  75.  Find_Red = Result%%
  76.  
  77. FUNCTION Shift_UP (start%)
  78.  FOR adj% = RF.top TO RF.top - 3 STEP -1 'make sure we find top of YouTube Icon
  79.   Colr~& = POINT(RF.left, adj%)
  80.   IF _RED32(Colr~&) > 250 AND _BLUE32(Colr~&) < 16 AND _GREEN32(Colr~&) < 16 THEN shftY%% = shftY%% + 1
  81.  NEXT adj%
  82.  Result% = start% - shftY%%
  83.  Shift_UP = Result%
  84.  
  85. FUNCTION Shift_LEFT (start%)
  86.  FOR adj% = RF.left TO RF.left - 3 STEP -1 'make sure we shift left some, get better centering match
  87.   Colr~& = POINT(adj%, RF.top)
  88.   IF _RED32(Colr~&) > 250 AND _BLUE32(Colr~&) < 16 AND _GREEN32(Colr~&) < 16 THEN shftX%% = shftX%% + 1
  89.  NEXT adj%
  90.  Result% = start% - shftX%%
  91.  Shift_LEFT = Result%
  92.  
  93. FUNCTION Check_Tube (Handle&)
  94.  FOR y% = RF.top TO RF.top + 10 'adjust Y to top of icon
  95.   FOR x% = RF.left TO RF.left + 10
  96.    checking~& = POINT(x%, y%)
  97.    IF _RED32(checking~&) > 250 AND _BLUE32(checking~&) < 16 AND _GREEN32(checking~&) < 16 THEN hit% = hit% + 1
  98.   NEXT x%
  99.  NEXT y%
  100.  Result% = hit%
  101.  Check_Tube = Result%
  102.  
  103.  

the compile log is
Quote
In file included from qbx.cpp:2165:0:
..\\temp\\main.txt: In function 'void QBMAIN(void*)':
..\\temp\\main.txt:74:66: error: invalid conversion from 'void*' to 'LPPOINT {aka tagPOINT*}' [-fpermissive]
compilation terminated due to -Wfatal-errors.

not sure what I need to do to fix this.
Granted after becoming radioactive I only have a half-life!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Compliation fail using DECLARE LIBRARY
« Reply #1 on: January 14, 2019, 01:58:59 pm »
Change your declare library statement to...

DECLARE DYNAMIC LIBRARY "user32"

That will get it to compile.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Compliation fail using DECLARE LIBRARY
« Reply #2 on: January 14, 2019, 02:20:28 pm »
Awesome, Thanks Pete.
Granted after becoming radioactive I only have a half-life!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Compliation fail using DECLARE LIBRARY
« Reply #3 on: January 14, 2019, 02:37:38 pm »
now if I could figure out why I'm getting constant false positives after it closes the first tab.
Granted after becoming radioactive I only have a half-life!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Compliation fail using DECLARE LIBRARY
« Reply #4 on: January 14, 2019, 03:22:20 pm »
Please, add _FREEIMAGE test& to your program DO LOOP loop. Your program devoured all my memory and I had to restart computer. That's not nice at all! :-D For really  current screen screenshot add to program _SCREENICON for minimalizing your program.  MAYBE it help you.
« Last Edit: January 14, 2019, 03:27:37 pm by Petr »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Compliation fail using DECLARE LIBRARY
« Reply #5 on: January 14, 2019, 07:01:09 pm »
Ha! Good recommendation. My computer crashed shortly after running his code, too.

Lucky for me, I'm always backed up. That's probably why I so cranky!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Compliation fail using DECLARE LIBRARY
« Reply #6 on: January 15, 2019, 11:02:12 am »
yeah, had not progressed far enough to into testing to catch that, opps.  though as I was putting the image into the same handle it didn't occur to me it was making a new one each time rather than just over writing the old one.

By the way Pete that second function in the DECLARE, GetWindowRect, should allow for retrieval of the Position and Size of the active window, not sure if that would help you in your management program you were working on. I haven't made it to the point of testing that but that is what it is supposed to do. I believe we have a function for returning the active windows handle anyway.
Granted after becoming radioactive I only have a half-life!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Compliation fail using DECLARE LIBRARY
« Reply #7 on: January 15, 2019, 12:43:21 pm »
From what little I have read, it seems trickier than it should be to that function to get the coordinates of the titled window. For instance, this code gives a 1  for the windows coordinates, which I think means it is just acknowledging the call but not returning their respective values. It does return the window's handle (hwnd).

Code: QB64: [Select]
  1. fwp$ = "Find Windows Position"
  2. _TITLE fwp$
  3.  
  4. TYPE Rectangle
  5.     left AS LONG
  6.     top AS LONG
  7.     right AS LONG
  8.     bottom AS LONG
  9.  
  10. DIM Rec AS Rectangle
  11. DIM SHARED win AS Rectangle
  12.  
  13.     FUNCTION FindWindowA& (BYVAL ClassName AS LONG, WindowName$) 'handle by title
  14.     FUNCTION GetWindowRect& (BYVAL Hwnd AS LONG, Rec AS Rectangle)
  15.  
  16. hwnd = FindWindowA&(0, fwp$ + CHR$(0))
  17. win.left = GetWindowRect&(hwnd, Rec)
  18. win.bottom = GetWindowRect&(hwnd, Rec)
  19. PRINT win.left, win.bottom, hwnd
  20.  

My guess is you're not going for "Grandfather of the Year" with that code of yours. :D

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Compliation fail using DECLARE LIBRARY
« Reply #8 on: January 15, 2019, 12:45:10 pm »
Quote
I believe we have a function for returning the active windows handle anyway.
You think about _WINDOWHANDLE function?

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Compliation fail using DECLARE LIBRARY
« Reply #9 on: January 15, 2019, 01:05:17 pm »
_WINDOWHANDLE returns the exact same results as the WINDOW API function in my code posted. It's nice to have it in the keywords, though. There is a desktop windows api example in the Windows Library section of the Wiki, but that is a different function call, apparently just for the desktop coordinates. It would be nice to find an active window's coordinates, and beyond that, moving it to a different area of the screen, or resizing it.

I'll have to try and look through that whole API library list to be certain there isn't something in there, already. This isn't something I'm still actively working on presently, but the more you know, the more you grow... although smart guys don't usually end up as porn stars, but hey, no analogy (excuse the pun) is completely bullet proof.

Pete

Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Compliation fail using DECLARE LIBRARY
« Reply #10 on: January 15, 2019, 06:15:34 pm »
when ODIN doesn't like your title selection! took me a minute to find this again. :)
[maybe he thought I was being too modest by admitting my lack of skill with DECLARE LIBRARY]

I Think _WINDOWHANDLE only returns your programs window handle. and I think HASFOCUS only pertains to 'your' program as well. I thought there was a way to get the handle of the active window but I can't find it by searching the forum, possible it was back on .NET.

But GETFOREGROUNDWINDOW should return the current ACTIVE window. granted this is all for WINDOWs users.
there is also GETACTIVEWINDOW.

now If I could find a way to retrieve what is typed in the address bar that would be killer! Would super simplify my work.
Granted after becoming radioactive I only have a half-life!

Offline odin

  • Administrator
  • Newbie
  • Posts: 92
  • I am.
    • View Profile
Re: Compliation fail using DECLARE LIBRARY
« Reply #11 on: January 15, 2019, 06:18:23 pm »
Post titles should not be misleading or vague, or else the search feature becomes useless for people looking for help.

Yours was vague.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Compliation fail using DECLARE LIBRARY
« Reply #12 on: January 15, 2019, 06:39:16 pm »
Check the code I posted a few comments above to get the active window handle.

FUNCTION FindWindowA& (BYVAL ClassName AS LONG, WindowName$) 'handle by title

My Firefox management program  demonstrates how to use it: https://www.qb64.org/forum/index.php?topic=860.msg100590#msg100590

To get the ontents of the address bar, it uses...

_SCREENCLICK  on the address bar.
_SCREENPRINT CHR$(1) ' Select All
_SCREENPRINT CHR$(3) ' Copy URL
URL$ = _CLIPBOARD$

I'd use some brief delays between the statements, too.

Pete


Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Compliation fail using DECLARE LIBRARY
« Reply #13 on: January 15, 2019, 08:26:24 pm »
Yours was vague.
My titles reflect myself, oh wait, maybe I should go Vogue instead? :)

To get the ontents of the address bar, it uses...

_SCREENCLICK  on the address bar.
_SCREENPRINT CHR$(1) ' Select All
_SCREENPRINT CHR$(3) ' Copy URL
URL$ = _CLIPBOARD$


I thought about that, but how to know when to use it, as if you try that while someone is typing it will cause issues. and constantly running that would be impractical, even restoring the mouse position would cause usage issues. I would have to find a way of knowing when to run it.
I guess with IE its crazy easy to do, and Chrome isn't bad but because the way FireFox is made its nigh upon impossible. have to use DDE ,Dynamic Data something or other, and its not the easiest to implement either.
Granted after becoming radioactive I only have a half-life!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Compliation fail using DECLARE LIBRARY
« Reply #14 on: January 15, 2019, 09:30:54 pm »
Try this...

Code: QB64: [Select]
  1. WIDTH 100, 4
  2. PRINT: PRINT " Put Firefox anywhere. Click here to start and quickly click Firefox to focus it."
  3.     i = _MOUSEINPUT
  4.     lb% = _MOUSEBUTTON(1)
  5.     IF lb% THEN ' Button release
  6.         WHILE _MOUSEBUTTON(1)
  7.             i = _MOUSEINPUT
  8.         WEND
  9.         EXIT DO
  10.     END IF
  11. _DELAY 2 ' You have 2-seconds to click firefox.
  12.  
  13.     SUB SENDKEYS ALIAS keybd_event (BYVAL bVk AS LONG, BYVAL bScan AS LONG, BYVAL dwFlags AS LONG, BYVAL dwExtraInfo AS LONG)
  14.  
  15. CONST KEYEVENTF_KEYUP = &H2
  16. CONST VK_CONTROL = &H11 'Ctrl key
  17. CONST VK_L = &H4C ' "L"
  18.  
  19.  
  20. SENDKEYS VK_CONTROL, 0, 0, 0
  21. SENDKEYS VK_L, 0, 0, 0
  22. SENDKEYS VK_L, 0, KEYEVENTF_KEYUP, 0
  23. SENDKEYS VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
  24. PRINT: PRINT " URL = "; _CLIPBOARD$
  25.  

Now focus is a problem because the title for firefox is actually the title of the given tab in the browser. In my programs, I just open Bing home page and use that as the title. SO if Firefox is not in focus, this routine will do a Ctrl + L key send on whatever window is in focus. I suspect it won't affect too many programs but I have no idea what hotkeys are used for every program, game, etc. Still, this is a way to get the contents of the address bar, no matter where firefox is and the API allows Ctrl + L, which would be _SCREENCLICK CHR$(12) but that one is not supported in QB64. CHR$(12) was used to eject printer paper, back in the day, if I recall correctly.

Pete

Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/